Skip to content

Commit be26d95

Browse files
MetbcyQazalbash
andauthored
doc(gh-2187): enhance documentation for Chi2, DiscreteUniform, and Categorical distributions (#2199)
* doc(gh-2187): enhance documentation for Chi2, DiscreteUniform, and Categorical distributions * doc(gh-2187): address review feedback (tilde + a/b notation) * fix: use latex symbol --------- Co-authored-by: Meesum Qazalbash <meesumqazalbash@gmail.com>
1 parent b0988a7 commit be26d95

2 files changed

Lines changed: 295 additions & 0 deletions

File tree

numpyro/distributions/continuous.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,37 @@ def entropy(self) -> ArrayLike:
890890

891891

892892
class Chi2(Gamma):
893+
r"""A chi-square continuous random variable, parameterized by the degrees of
894+
freedom :math:`k`.
895+
896+
The Probability Density Function (PDF) of the chi-square distribution with
897+
:math:`k` degrees of freedom is defined as:
898+
899+
.. math::
900+
f(x; k) = \frac{x^{k/2 - 1} e^{-x/2}}{2^{k/2}\,\Gamma(k/2)},
901+
\quad x > 0
902+
903+
Where, :math:`k` represents the degrees of freedom (:attr:`df`),
904+
:math:`\Gamma(\cdot)` is the gamma function, and :math:`x` is the observed value.
905+
The support domain is :math:`x \in (0, \infty)`.
906+
907+
The chi-square distribution is a special case of the Gamma distribution:
908+
909+
.. math::
910+
\chi^2(k) \equiv \mathrm{Gamma}(k/2,\; 1/2)
911+
912+
so this class inherits sampling, log-probability, mean, variance, and entropy
913+
implementations from :class:`Gamma`.
914+
"""
915+
893916
arg_constraints = {"df": constraints.positive}
894917
reparametrized_params = ["df"]
895918

896919
def __init__(self, df: ArrayLike, *, validate_args: Optional[bool] = None) -> None:
920+
r"""
921+
:param df: Degrees of freedom parameter :math:`k > 0` (:attr:`df`).
922+
:param validate_args: If True, enforce domain constraints during initialization.
923+
"""
897924
self.df = df
898925
super(Chi2, self).__init__(0.5 * df, 0.5, validate_args=validate_args)
899926

0 commit comments

Comments
 (0)