Skip to content
class

InverseGamma

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

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

Distribution of the reciprocal of a Gamma random variable: if Y∼Gamma(α,β)Y \sim \mathrm{Gamma}(\alpha, \beta) then X=1/Y∼InverseGamma(α,β)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, β′=β+12∑i(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.)
>>> d.sample((4,)).shape
(4,)

Used by 2

Constructors

1
dunder

__init__

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

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.

Properties

3
prop

mean

→Tensor
mean: Tensor

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

prop

mode

→Tensor
mode: Tensor

Mode of the inverse-Gamma distribution: β/(α+1)\beta / (\alpha + 1).

prop

variance

→Tensor
variance: Tensor

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

Instance methods

6
fn

cdf

→Tensor
cdf(value: Tensor)

Cumulative distribution function of the inverse-Gamma distribution.

F(x;α,β)=Q(α,β/x),x>0F(x; \alpha, \beta) = Q(\alpha, \beta / x), \quad x > 0

the regularized upper incomplete gamma (lucid.special.gammaincc) — 1/X1/X is Gamma(alpha, beta), and X≤xX \leq x is 1/X≥1/x1/X \geq 1/x. Evaluated as QQ itself, not as 1−P1 - P, so the small left tail keeps its relative precision.

Returns probabilities in [0,1][0, 1]; 0 at and below 0.

Raises

NotImplementedError
From backward, when concentration requires a gradient, as in the reference framework.

Examples

>>> InverseGamma(concentration=1.0, rate=1.0).cdf(lucid.tensor(1.0))  # 1/e
tensor(0.3679)
fn

entropy

→Tensor
entropy()

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

fn

expand

→Self
expand(batch_shape: Sequence[int], _instance: Self | None = None)

Return a new InverseGamma with batch dimensions expanded to batch_shape.

fn

log_prob

→Tensor
log_prob(value: Tensor)

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)log⁡x−β/x\alpha\log\beta - \log\Gamma(\alpha) - (\alpha+1)\log x - \beta/x.

fn

rsample

→Tensor
rsample(sample_shape: tuple[int, ...] = ())

Draw reparameterised samples by taking the reciprocal of a Gamma sample.

fn

sample

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

Sample by taking the reciprocal of a Gamma sample.