TruncatedGaussian#

class hybrid_aif.TruncatedGaussian[source]#

Bases: Distribution

A diagonal Gaussian N(loc, diag(scale²)) restricted to [low, high] (see module).

Every leaf is (..., dim); low < high elementwise.

__init__(loc, scale, low, high)[source]#
loc: Array#

The location of the untruncated Gaussian, (..., dim).

scale: Array#

The standard deviation of the untruncated Gaussian, (..., dim).

low: Array#

The lower bound, (..., dim).

high: Array#

The upper bound, (..., dim).

property batch_shape: tuple[int, ...]#

Leading (batch) axes: leaf shape minus the family’s fixed trailing structure.

log_normalisers()[source]#

log Z per dimension, (..., dim).

mean()[source]#

The mean; a narrow box’s is mid + half·h·M₁/M₀ about its midpoint. Clamped into the box as a guard.

variance()[source]#

Per-dimension variance, (..., dim) (the covariance is diagonal); a narrow box’s is half²·(M₂/M₀ − h²(M₁/M₀)²), w²/12 in the uniform limit. Clamped into (0, w²/4] as a guard.

property cov: Array#

The diagonal covariance as a matrix, (..., dim, dim).

log_prob(x)[source]#

Log density at x, summed over dimensions; −inf outside the box.

sample(key, sample_shape=())[source]#

Reparameterised draws through the inverse CDF: u ~ U(0, 1) per dimension and x = loc + scale·Φ⁻¹(Φ(α) + u·Z), with Φ(α) + u·Z formed in log space and a box in the upper tail drawn from its reflection. Draws are clipped into the box against rounding. A box narrower than _TILT_HALF_WIDTH standard deviations, where the inverse CDF runs out of float32 resolution and t²/2 is below it, is drawn from its exponential tilt about the lower bound.

entropy()[source]#

The differential entropy, summed over dimensions; a box beyond _TAIL standard deviations takes the tail form (_tail_moments()).

expected_square(centre)[source]#

E[(x − centre)²] per dimension, from the closed mean and variance.

kl_to(other)[source]#

KL(self ‖ other) for two members on the same box, in closed form: −H[self] − E_self[log other], the cross term read off the closed first two moments.

Members on different boxes raise (eagerly, or under a trace by equinox.error_if): outside a shared box the KL is infinite or undefined.