Skip to content

Add icdf functions for distributions #6612

Open
@michaelraczycki

Description

@michaelraczycki

Description

We are looking for help to implement inverse cumulative distribution (ICDF) functions for our distributions!

How to help?

This PR should give a template on how to implement and test new icdf functions for distributions: #6528

ICDF functions allow users to get the value associated with a specific cumulative probability.

So far we've added 2 examples for continuous distribution

  • Uniform:
    def icdf(value, lower, upper):
    res = lower + (upper - lower) * value
    res = check_icdf_value(res, value)
    return check_icdf_parameters(res, lower < upper)
  • Normal:
    def icdf(value, mu, sigma):
    res = mu + sigma * -np.sqrt(2.0) * pt.erfcinv(2 * value)
    res = check_icdf_value(res, value)
    return check_icdf_parameters(
    res,
    sigma > 0,
    msg="sigma > 0",
    )

And an example for a discrete distribution:

  • Geometric:
    def icdf(value, p):
    res = pt.ceil(pt.log1p(-value) / pt.log1p(-p)).astype("int64")
    res = check_icdf_value(res, value)
    return check_icdf_parameters(
    res,
    0 <= p,
    p <= 1,
    msg="0 <= p <= 1",
    )

Multiple sources describing the icdf function for any specific distribution can be found, you're free to choose which one is working for you. To start with I recommend checking:

New tests have to be added in test_continuous.py for continuous distributions, and test_discrete.py for discrete ones. You can use existing tests as a template:

check_icdf(
pm.Normal,
{"mu": R, "sigma": Rplus},
lambda q, mu, sigma: st.norm.ppf(q, mu, sigma),
)

Don't hesitate to ask any questions. You can grab as many distributions to implement moments as you want. Just make sure to write in this issue so that we can keep track of it.

Profit with your new open source KARMA!

The following distributions don't have an icdf method implemented:

Note that not all of the icdf equations will have closed solution, so it's recommended to first start with the ones that can be found in closed form, as they will be easier to implement and will contribute to the task further with providing other contributors with templates to understand the topic better. The list above is not final, and I'll try to update it to contain all distributions available for taking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions