From 3a9a4ceb8525464240f1bc52eb1be2ec8e226fec Mon Sep 17 00:00:00 2001 From: zoj <44142765+zoj613@users.noreply.github.com> Date: Sun, 28 Mar 2021 16:15:07 +0200 Subject: [PATCH] Update docstrings --- pymc3/distributions/continuous.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 2f3d6cc0cc1..decb19218da 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -4300,6 +4300,7 @@ def __call__(self, h=1, z=0, size=None, **kwargs): def rng_fn(cls, rng, h, z, size=None): """ Generate a random sample from the distribution with the given parameters + Parameters ---------- h : scalar or sequence, optional @@ -4325,18 +4326,25 @@ def rng_fn(cls, rng, h, z, size=None): class PolyaGamma(PositiveContinuous): r""" The Polya-Gamma distribution. + The distribution is parametrized by ``h`` (shape parameter) and ``z`` (exponential tilting parameter). The pdf of this distribution is + .. math:: + f(x \mid h, z) = cosh^h(\frac{z}{2})e^{-\frac{1}{2}xz^2}f(x \mid h, 0), where :math:`f(x \mid h, 0)` is the pdf of a :math:`PG(h, 0)` variable. Notice that the pdf of this distribution is expressed as an alternating-sign sum of inverse-Gaussian densities. + .. math:: + X = \Sigma_{k=1}^{\infty}\frac{Ga(h, 1)}{d_k}, where :math:`d_k = 2(k - 0.5)^2\pi^2 + z^2/2`, :math:`Ga(h, 1)` is a gamma random variable with shape parameter ``h`` and scale parameter ``1``. + .. plot:: + import matplotlib.pyplot as plt import numpy as np from polyagamma import polyagamma_pdf @@ -4351,25 +4359,30 @@ class PolyaGamma(PositiveContinuous): plt.ylabel('f(x)', fontsize=12) plt.legend(loc=1) plt.show() + ======== ============================= Support :math:`x \in (0, \infty)` Mean :math:`dfrac{h}{4} if :math:`z=0`, :math:`\dfrac{tanh(z/2)h}{2z}` otherwise. Variance :math:`0.041666688h` if :math:`z=0`, :math:`\dfrac{h(sinh(z) - z)(1 - tanh^2(z/2))}{4z^3}` otherwise. ======== ============================= + Parameters ---------- h: float, optional The shape parameter of the distribution (h > 0). z: float, optional The exponential tilting parameter of the distribution. + Examples -------- .. code-block:: python + rng = np.random.default_rng() with pm.Model(): x = pm.PolyaGamma('x', h=1, z=5.5) with pm.Model(): x = pm.PolyaGamma('x', h=25, z=-2.3, rng=rng, size=(100, 5)) + References ---------- .. [1] Polson, Nicholas G., James G. Scott, and Jesse Windle. @@ -4401,28 +4414,32 @@ def dist(cls, h=1.0, z=0.0, rng=None, size=None, **kwargs): def logp(value, h, z): """ Calculate log-probability of Normal 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. + Returns ------- TensorVariable """ - return bound(polyagamma_logpdf(value, h, z), h > 0) + return bound(polyagamma_logpdf(value, h, z), h > 0, value > 0) def logcdf(value, h, z): """ Compute the log of the cumulative distribution function for Normal distribution at the specified value. + Parameters ---------- value: numeric or np.ndarray or `TensorVariable` Value(s) for which log CDF is calculated. If the log CDF for multiple values are desired the values must be provided in a numpy array. + Returns ------- TensorVariable """ - return bound(polyagamma_logcdf(value, h, z), h > 0) + return bound(polyagamma_logcdf(value, h, z), h > 0, value > 0)