Skip to content

Commit 358b590

Browse files
committed
implement as gamma and add to docstring
1 parent fbcf634 commit 358b590

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

pymc/distributions/continuous.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
from pytensor.tensor.random.op import RandomVariable
5656
from pytensor.tensor.variable import TensorConstant
5757

58-
from pymc.distributions.distribution import CustomDist
5958
from pymc.logprob.abstract import _logprob_helper
6059
from pymc.logprob.basic import icdf
6160

@@ -2378,12 +2377,17 @@ class ChiSquared:
23782377
r"""
23792378
:math:`\chi^2` log-likelihood.
23802379
2380+
This is the distribution from the sum of the squares of :math:`\nu` independent standard normal random variables or a special
2381+
case of the gamma distribution.
2382+
23812383
The pdf of this distribution is
23822384
23832385
.. math::
23842386
23852387
f(x \mid \nu) = \frac{x^{(\nu-2)/2}e^{-x/2}}{2^{\nu/2}\Gamma(\nu/2)}
23862388
2389+
Read more about the :math:`\chi^2` distribution at https://en.wikipedia.org/wiki/Chi-squared_distribution
2390+
23872391
.. plot::
23882392
:context: close-figs
23892393
@@ -2414,26 +2418,12 @@ class ChiSquared:
24142418
Degrees of freedom (nu > 0).
24152419
"""
24162420

2417-
def chisquared_dist(nu, size):
2418-
return Gamma.dist(alpha=nu / 2, beta=1 / 2, size=size)
2419-
24202421
def __new__(cls, name, nu, **kwargs):
2421-
return CustomDist(
2422-
name,
2423-
nu,
2424-
dist=cls.chisquared_dist,
2425-
class_name="ChiSquared",
2426-
**kwargs,
2427-
)
2422+
return Gamma(name, alpha=nu / 2, beta=1 / 2, **kwargs)
24282423

24292424
@classmethod
24302425
def dist(cls, nu, **kwargs):
2431-
return CustomDist.dist(
2432-
nu,
2433-
dist=cls.chisquared_dist,
2434-
class_name="ChiSquared",
2435-
**kwargs,
2436-
)
2426+
return Gamma.dist(alpha=nu / 2, beta=1 / 2, **kwargs)
24372427

24382428

24392429
# TODO: Remove this once logp for multiplication is working!

0 commit comments

Comments
 (0)