ConditionalCategorical#

class hybrid_aif.ConditionalCategorical[source]#

Bases: _TabularConditional

Tabular CPD P(child | parents): one simplex per parent configuration.

log_table holds unnormalized log-probabilities with structure block (num_levels, *parent_shape); methods normalize over the child axis, so the stored table carries a per-config additive gauge, as Categorical.logits does.

log_table: Array#

Unnormalized log-probabilities, (..., num_levels, *parent_shape), child axis first.

parent_ndims: int#

The number of parent axes (a count, not their sizes).

property log_probs: Array#

Normalized log P(child | parents), same layout as log_table.

classmethod from_parent_leading(log_table, parent_ndims)[source]#

Build from the parent-leading layout (*parent_shape, num_levels).

Moves the child axis to the front of the structure block; batch axes stay leading and only the trailing parent_ndims + 1 axes are re-laid-out. For W of shape (num_actions=3, num_modes=2) with W[u, j] = log P(mode j | action u), from_parent_leading(W, 1) equals ConditionalCategorical(log_table=W.T, parent_ndims=1).

expected_log(parent_beliefs)[source]#

E_q(parents)[log P(child | parents)] — the FPI contraction; (…, num_levels).

average(parent_beliefs)[source]#

Bayesian model average Σ_parents P(child|parents) q(parents) as a Categorical.

condition_on(parent_indices)[source]#

The child distribution at one parent configuration (unbatched indices).

is_normalized(atol=1e-05)[source]#

Whether the stored table exponentiates to a simplex per parent config.

Methods renormalize regardless; this validates externally supplied tables. Returns a boolean array over batch axes.

join(parent_marginal)[source]#

Chain-rule product P(child|parents)·P(parents) as a JointCategorical.

The joint’s event axes are (num_levels, *parent_shape) — child axis first, parent axes in table order. parent_marginal is a Categorical (single parent) or a JointCategorical whose event shape equals parent_shape.

__init__(log_table, parent_ndims)#