Skip to content

Commit

Permalink
Update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
zoj613 committed Mar 28, 2021
1 parent ac6f6aa commit 3a9a4ce
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)

0 comments on commit 3a9a4ce

Please sign in to comment.