mixle.inference.simulate module¶
Turn a fitted model into a reusable simulator with scenarios.
A fitted generative model already has sampling behavior. simulate()
packages that behavior into a Simulator that can produce baseline
synthetic data and, for learned Bayesian networks, named intervention
scenarios.
Non-graph models simulate from their baseline distribution. Interventions
require the causal structure exposed by
HeterogeneousBayesianNetwork.
Every draw count is an exact positive integer and every run returns exactly that
many records: a Monte Carlo precision claim, an effect comparison, or a receipt
that says n trials were run is only worth what the realized sample size is,
so an underproducing generator raises IncompleteSimulationError rather
than silently shrinking the experiment.
- exception IncompleteSimulationError(message, records, requested)[source]
Bases:
RuntimeErrorA generator produced a different number of records than the experiment requested.
recordsholds what it did produce andrequestedthe size that was asked for, so a caller can decide what to do with a short run instead of summarizing it as though it were the full one.
- class Scenario(name, interventions=<factory>)[source]
Bases:
objectA named simulation condition: which fields are clamped to which values (an intervention).
- class Simulator(model)[source]
Bases:
objectA fitted model packaged as a data generator, runnable under a baseline or named scenarios.
- Parameters:
model (Any)
- scenario(name, interventions)[source]
Register a named intervention scenario (requires a learned Bayesian network to apply).
- run(n=100, *, scenario=None, interventions=None, seed=0)[source]
Generate exactly
nsynthetic records under the baseline, a registeredscenario, or ad-hocinterventions.nmust be an exact positive integer. RaisesIncompleteSimulationErrorif the underlying generator yields a different number of records than requested.
- outcome_mean(field_index, *, scenario=None, n=2000, seed=0)[source]
The mean of a numeric field over exactly
ndraws – the quantity to compare across conditions.The run is size-checked first (see
run()), so the returned mean is always overnobservations rather than over however many the generator happened to yield.