pymc-devs / pymc-experimental

https://pymc-experimental.readthedocs.io
Other
72 stars 46 forks source link

Implement Generalized Pareto distribution #294

Open xieyj17 opened 6 months ago

xieyj17 commented 6 months ago

Generalized Pareto distribution is a commonly used distribution for modelling the tail of another distribution. It has wide applications in risk management, finance, ans quality assuarance. See wiki page.

I added a new distribution to the pymc-experimental branch.

xieyj17 commented 6 months ago

When I am rebasing, I accidently added the recent PR by @zaxtax .

ricardoV94 commented 6 months ago

You should add an entry in the docs API: https://github.com/pymc-devs/pymc-experimental/blob/main/docs/api_reference.rst

xieyj17 commented 6 months ago

@ricardoV94 Thanks for you comments! I have addressed your suggested changes. Thank you!

rxd199682 commented 4 months ago

I think the logp for Generalized Pareto distribution should be def logp(value, mu, sigma, xi): """ Calculate log-probability of Generalized Pareto distribution at specified value.

    Parameters
    ----------
    value: numeric
        Value(s) for which log-probability is calculated. If the log probabilities for multiple
        values are desired the values must be provided in a numpy array or Pytensor tensor

    Returns
    -------
    TensorVariable
    """

    scaled = (value - mu) / sigma

    logp_expression = pt.switch(
        pt.isclose(xi, 0),
        -1 * scaled,
        -1 * pt.log(sigma) - ((xi + 1) / xi) * pt.log1p(xi * scaled),
    )
    logp = pt.switch(pt.gt(1 + xi * scaled, 0), logp_expression, -np.inf)
    return check_parameters(logp, sigma > 0, pt.and_(xi > -1, xi < 1), msg="sigma > 0 or -1 < xi < 1")