mixle.reason.discrete module

reason_discrete – fuse multi-source evidence over a finite hypothesis set, with attribution.

The discrete sibling of mixle.reason.core.reason(): the latent is one of K alternatives (“which regime / fault / explanation”), each evidence source contributes a per-hypothesis log-likelihood, and the answer is the exact posterior plus how many nats of uncertainty each source removed. Sources can be raw log-likelihood vectors or fitted mixle models — one generative model per hypothesis, scored on the raw observation (model_evidence) — so the same distributions you fit elsewhere become reasoning evidence with no glue.

model_evidence(name, models, x)[source]

Evidence from fitted mixle models: hypothesis k <-> models[k], scored on observation x.

Returns (name, log_lik) with log_lik[k] = models[k].log_density(x).

Parameters:
Return type:

tuple[str, ndarray]

class DiscreteAnswer(belief, attribution=<factory>)[source]

Bases: object

The posterior over hypotheses plus per-source attribution (nats of entropy removed).

Parameters:
belief: CategoricalBelief
attribution: list[tuple[str, float]]
property probs: ndarray
map()[source]
Return type:

Any

top(k=3)[source]
Parameters:

k (int)

Return type:

list[tuple[Any, float]]

summary()[source]
Return type:

str

decide(loss, actions=None, *, abstain_cost=None)[source]

The Bayes-optimal action under this posterior — EXACT over the finite hypothesis set.

Parameters:
  • loss (Any) – an (A, K) matrix (loss[a, k] = cost of action a when hypothesis k is true) or a callable loss(action, hypothesis) -> float.

  • actions (Any) – action labels (defaults to the hypothesis labels — the “declare k” actions).

  • abstain_cost (float | None) – when given, an extra "abstain" action with this flat cost — chosen whenever every committal action’s expected loss exceeds it (the escalate-don’t-guess decision, priced explicitly).

Returns:

{action, expected_loss, alternatives} with the exact expected loss of every candidate.

Return type:

dict[str, Any]

reason_discrete(prior, evidence)[source]

Fold evidence into a categorical belief and return the posterior with per-source attribution.

Parameters:
  • prior (Any) – a CategoricalBelief, an int K (uniform over K), or a list of hypothesis labels (uniform over them).

  • evidence (Any) – a sequence of (name, log_lik_vector) pairs — e.g. from model_evidence() — assimilated in order by exact Bayes.

Return type:

DiscreteAnswer