class

InverseGamma

extendsDistribution
InverseGamma(concentration: Tensor | float, rate: Tensor | float, validate_args: bool | None = None)
source

Inverse-Gamma distribution on (0,)(0, \infty).

Distribution of the reciprocal of a Gamma random variable: if YGamma(α,β)Y \sim \mathrm{Gamma}(\alpha, \beta) then X=1/YInverseGamma(α,β)X = 1/Y \sim \mathrm{InverseGamma}(\alpha, \beta). Widely used as the conjugate prior for the variance parameter of a Normal distribution with known mean, and as a prior on positive scale parameters more generally.

Parameters

concentrationTensor or float
Shape parameter α>0\alpha > 0.
rateTensor or float
Rate (inverse-scale) parameter β>0\beta > 0.
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density on x>0x > 0:

p(x;α,β)=βαΓ(α)xα1exp ⁣(βx)p(x; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-\alpha - 1} \exp\!\left(-\frac{\beta}{x}\right)

Moments (when defined):

E[X]=βα1    (α>1),Var[X]=β2(α1)2(α2)    (α>2)\mathbb{E}[X] = \frac{\beta}{\alpha - 1}\;\;(\alpha > 1), \qquad \mathrm{Var}[X] = \frac{\beta^2}{(\alpha - 1)^2 (\alpha - 2)} \;\;(\alpha > 2)

Mode: β/(α+1)\beta / (\alpha + 1).

Conjugacy: with a Normal(μ,σ2)\mathrm{Normal}(\mu, \sigma^2) likelihood and known mean μ\mu, the posterior over σ2\sigma^2 is again Inverse-Gamma with updated parameters α=α+n/2\alpha' = \alpha + n/2, β=β+12i(xiμ)2\beta' = \beta + \tfrac{1}{2}\sum_i (x_i - \mu)^2.

Because Lucid's lucid.distributions.Gamma sampler is rejection-based, has_rsample is False here and sample returns detached samples obtained by reciprocating a Gamma draw.

Examples

>>> import lucid
>>> from lucid.distributions import InverseGamma
>>> d = InverseGamma(concentration=3.0, rate=2.0)
>>> d.mean  # β / (α - 1) = 1.0
Tensor(1.0)
>>> d.sample((4,))
Tensor([...])

Methods (6)

dunder

__init__

None
__init__(concentration: Tensor | float, rate: Tensor | float, validate_args: bool | None = None)
source

Initialise an Inverse-Gamma distribution.

Parameters

concentrationTensor | float
Shape parameter α>0\alpha > 0.
rateTensor | float
Rate (inverse-scale) parameter β>0\beta > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.
prop

mean

Tensor
mean: Tensor
source

Defined for concentration > 1: β / (α − 1).

prop

variance

Tensor
variance: Tensor
source

Defined for concentration > 2: β² / ((α − 1)² (α − 2)).

fn

sample

Tensor
sample(sample_shape: tuple[int, ...] = ())
source

Sample by taking the reciprocal of a Gamma sample.

fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-probability density of the Inverse-Gamma distribution.

Parameters

valueTensor
Point(s) x>0x > 0 at which to evaluate the density.

Returns

Tensor

Log-density αlogβlogΓ(α)(α+1)logxβ/x\alpha\log\beta - \log\Gamma(\alpha) - (\alpha+1)\log x - \beta/x.

fn

entropy

Tensor
entropy()
source

α + log β + log Γ(α) − (1 + α) · ψ(α).