mixle.inference.condition module¶
condition() / do() – generic conditioning and causal intervention over any fitted
mixle model, regardless of how it is composed (composite / mixture / HMM / dependency-tree /
Bayesian network / conditional / sequence / optional).
See notes/designs/M0.md for the full design: the recursive rule per combinator, the
self-normalized-importance-sampling (SIR) fallback and its ESS receipt, and do()’s
graph-surgery semantics. In one line: condition composes each family’s own closed-form
conditioning surface where one already exists (MultivariateGaussianDistribution.condition,
MixtureDistribution.conditional, HiddenMarkovModelDistribution’s forward-backward) and
falls back to likelihood-weighted ancestral sampling – reusing each combinator’s own
log_density/sampler – everywhere else; do severs the incoming edges of the assigned
fields (graph surgery) rather than reweighting via Bayes.
Neither this module nor its callers modify any family’s internals – only their existing public surfaces are composed.
- class ConditionReceipt(method, ess=None, ess_ratio=None, n_particles=None, warnings=<factory>)[source]
Bases:
objectWhat
condition()actually did: the method used and (for SIR) the importance-sampling health.
- class Posterior(*, sample_fn, log_density_fn, mean_fn, receipt, model=None)[source]
Bases:
objectA
condition()result: scoreable/samplable over the unobserved fields.Distinct from
mixle.stats.compute.posterior.Posterior(that hierarchy is for parameter/latent/predictive posteriors keyed bysample(rng)); this one is evidence conditioning within a fitted joint model, with the signature the M0 card specifies:sample(n)/log_density(partial_row)/mean(field)/.receipt.- Parameters:
- sample(n=1, *, seed=None)[source]
ndraws over the unobserved fields (a list/array in original field order).
- log_density(partial_row)[source]
Log-density of an assignment to the unobserved fields under the posterior.
- condition(model, evidence, *, method='auto', n_particles=4096, seed=None)[source]
The posterior over
model’s unobserved fields givenevidence(seenotes/designs/M0.md).
- do(model, assignments)[source]
Sever the incoming edges of the assigned fields, then clamp them (Pearl’s
do).Returns a model of the same combinator family wherever possible (
DependencyTreeDistribution,CompositeDistribution,MixtureDistribution) so it can be passed back throughcondition()/do(); for aHeterogeneousBayesianNetworkit returns the existingInterventionalNetwork(sample/expectation/distribution).