mixle.inference.explain module

explain – exact per-part attribution of a model’s score for one observation.

Because mixle models are generative and structured, a prediction’s score decomposes exactly — no surrogate models, no sampling approximations:

  • a Composite / Record factorizes over fields: log p(x) = sum_i log p_i(x_i)

  • a learned Bayesian network factorizes over nodes: log p(x) = sum_i log P(x_i | parents)

  • a Mixture adds the latent view: per-component responsibilities, then the winner’s field breakdown.

explain(model, x) returns those parts with their exact log-likelihood contributions, sorted so the most suspicious part (lowest contribution) is first — “WHICH field makes this record unlikely” is read straight off the model rather than estimated:

ex = explain(model, record)
ex.parts             # [(name, log-contribution), ...] ascending (most anomalous first)
ex.total             # == model.log_density(record), exactly
ex.responsibilities  # mixtures: posterior over components
class Explanation(total, parts=<factory>, responsibilities=None, component=None)[source]

Bases: object

Exact additive attribution of log p(x) (plus the latent posterior for mixtures).

Parameters:
total: float
parts: list[tuple[str, float]]
responsibilities: ndarray | None = None
component: int | None = None
most_anomalous(k=3)[source]
Parameters:

k (int)

Return type:

list[tuple[str, float]]

summary()[source]
Return type:

str

explain(model, x)[source]

Exact per-part attribution of model.log_density(x) (see module docstring).

Parameters:
Return type:

Explanation