glearn.priors.InverseGamma#

class glearn.priors.InverseGamma(shape=1.0, scale=1.0)#

Inverse Gamma distribution.

Note

For the methods of this class, see the base class glearn.priors.Prior.

Parameters:
shapefloat or array_like[float], default=1.0

The shape parameter \(\alpha\) of Gamma distribution. If an array \(\boldsymbol{\alpha} = (\alpha_1, \dots, \alpha_p)\) is given, the prior is assumed to be \(p\) independent Gamma distributions each with shape \(\alpha_i\).

ratefloat or array_like[float], default=1.0

The rate \(\beta\) of Gamma distribution. If an array \(\boldsymbol{\beta} = (\beta_1, \dots, \beta_p)\) is given, the prior is assumed to be \(p\) independent Gamma distributions each with rate \(\beta_i\).

Notes

Single Hyperparameter:

The inverse Gamma distribution with shape parameter \(\alpha > 0\) and rate parameter \(\beta > 0\) is defined by the probability density function

\[p(\theta \vert \alpha, \beta) = \frac{\beta^{\alpha}}{\Gamma{\alpha}} \theta^{-(\alpha+1)} e^{-\frac{\beta}{\theta}},\]

where \(\Gamma\) is the Gamma function.

Multiple Hyperparameters:

If an array of the hyperparameters are given, namely \(\boldsymbol{\theta} = (\theta_1, \dots, \theta_p)\), then the prior is the product of independent priors

\[p(\boldsymbol{\theta}) = p(\theta_1) \dots p(\theta_p).\]

In this case, if the input arguments shape and rate are given as the arrays \(\boldsymbol{\alpha} = (\alpha_1, \dots, \alpha_p)\) and \(\boldsymbol{\beta} = (\beta_1, \dots, \beta_p)\), each prior \(p(\theta_i)\) is defined as the inverse Gamma distribution with shape parameter \(\alpha_i\) and rate parameter \(\beta_i\). In contrary, if shape and rate are given as the scalars \(\alpha\) and \(\beta\), then all priors \(p(\theta_i)\) are defined as the inverse Gamma distribution with shape parameter \(\alpha\) and rate parameter \(\beta\).

Examples

Create Prior Objects:

Create the inverse Gamma distribution with the shape parameter \(\alpha=4\) and rate parameter \(\beta=2\).

>>> from glearn import priors
>>> prior = priors.InverseGamma(4, 2)

>>> # Evaluate PDF function at multiple locations
>>> t = [0, 0.5, 1]
>>> prior.pdf(t)
array([       nan, 1.56293452, 0.36089409])

>>> # Evaluate the Jacobian of the PDF
>>> prior.pdf_jacobian(t)
array([        nan, -3.12586904, -1.08268227])

>>> # Evaluate the Hessian of the PDF
>>> prior.pdf_hessian(t)
array([[         nan,   0.        ,   0.        ],
       [  0.        , -12.50347615,   0.        ],
       [  0.        ,   0.        ,   3.60894089]])

>>> # Evaluate the log-PDF
>>> prior.log_pdf(t)
-17.15935597045384

>>> # Evaluate the Jacobian of the log-PDF
>>> prior.log_pdf_jacobian(t)
array([ -6.90775528, -10.05664278, -11.05240845])

>>> # Evaluate the Hessian of the log-PDF
>>> prior.log_pdf_hessian(t)
array([[-10.60379622,   0.        ,   0.        ],
       [  0.        ,  -3.35321479,   0.        ],
       [  0.        ,   0.        ,  -1.06037962]])

>>> # Plot the distribution and its first and second derivative
>>> prior.plot()
../_images/prior_inverse_gamma.png

Where to Use the Prior object:

Define a covariance model (see glearn.Covariance) where its scale parameter is a prior function.

>>> # Generate a set of sample points
>>> from glearn.sample_data import generate_points
>>> points = generate_points(num_points=50)

>>> # Create covariance object of the points with the above kernel
>>> from glearn import covariance
>>> cov = glearn.Covariance(points, kernel=kernel, scale=prior)
Attributes:
shapefloat or array_like[float], default=0

Shape parameter \(\alpha\) of the distribution

ratefloat or array_like[float], default=0

Rate parameter \(\beta\) of the distribution

Methods

suggest_hyperparam([positive])

Find an initial guess for the hyperparameters based on the peaks of the prior distribution.

pdf(x)

Probability density function of the prior distribution.

pdf_jacobian(x)

Jacobian of the probability density function of the prior distribution.

pdf_hessian(x)

Hessian of the probability density function of the prior distribution.