pymc-devs / pymc-experimental

https://pymc-experimental.readthedocs.io
Other
77 stars 49 forks source link

Adding a generalised normal distribution #278

Open jbrinchmann opened 9 months ago

jbrinchmann commented 9 months ago

This pull request implements a generalized Gaussian distribution (https://en.wikipedia.org/wiki/Generalized_normal_distribution) - this is useful for situations where the distribution is close to Gaussian but with some kurtosis.

The distribution implemented is the symmetric version, but in keeping with the naming of the normal distribution I have not included this in the naming.

I have tried to follow the instructions for adding new distributions but for some reason when I do e.g.

In [1]: from pymc_experimental.distributions import GeneralizedNormal

In [2]: GeneralizedNormal.logcdf(1.5, mu=0.0, beta=1.3, alpha=0.5)
Out[2]: Log.0

which is an odd outcome since all intermediate steps are correct and the code works when embedded outside of pymc-experimental. As a consequence the tests do not appear to work.

ricardoV94 commented 9 months ago

which is an odd outcome since all intermediate

This is normal! PyMC uses PyTensor which return symbolic expressions until actually evaluated.

You can call .eval() on the output to get the numerical value. More details in https://pytensor.readthedocs.io/en/latest/tutorial/adding.html

jbrinchmann commented 9 months ago

Thanks for the feedback - in trying to get things working I had introduce two minor bugs in logp and logcdf. These are now fixed and double-checked to agree with scipy.stats.gennorm and a moment test has been added.