Categorical#

class hybrid_aif.Categorical[source]#

Bases: ExponentialFamily

A categorical distribution over num_levels outcomes, batched over leading axes.

Stored as logits; the event shape is (): a sample or a log_prob argument is an integer level index. probs and log_probs give the normalised table, from_probs() builds one from probabilities, mean() is the probability vector, and natural() pins the last level’s logit to zero (the gauge choice).

logits: Array#

Unnormalized log-probabilities, (..., num_levels): the natural parameters up to an additive gauge constant per batch entry. The trailing axis is the level axis.

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

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

log_prob(x)[source]#

Log density/mass at x; broadcasts over batch axes.

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

Draw samples with shape sample_shape + batch_shape + event_shape.

mean()[source]#

Moment view: the probability vector (one-hot expectation).

entropy()[source]#

Differential/discrete entropy as an Interval (zero-width when exact).

kl_to(other)[source]#

KL(self ‖ other) for other of the same family, as an Interval.

natural()[source]#

Logits with the last state pinned to zero (gauge choice).

classmethod from_natural(logits)[source]#

Inverse of natural(), up to gauge and float error.

__init__(logits)#