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.

class Scenario(name, interventions=<factory>)[source]

Bases: object

A named simulation condition: which fields are clamped to which values (an intervention).

Parameters:
name: str
interventions: dict[int, Any]
class Simulator(model)[source]

Bases: object

A fitted model packaged as a data generator, runnable under a baseline or named scenarios.

Parameters:

model (Any)

scenarios: dict[str, Scenario]
scenario(name, interventions)[source]

Register a named intervention scenario (requires a learned Bayesian network to apply).

Parameters:
Return type:

Simulator

run(n=100, *, scenario=None, interventions=None, seed=0)[source]

Generate n synthetic records under the baseline, a registered scenario, or ad-hoc interventions.

Parameters:
Return type:

list[Any]

outcome_mean(field_index, *, scenario=None, n=2000, seed=0)[source]

The mean of a numeric field under a scenario – the quantity to compare across conditions.

Parameters:
  • field_index (int)

  • scenario (str | None)

  • n (int)

  • seed (int)

Return type:

float

compare(field_index, scenario_a, scenario_b, *, n=4000, seed=0)[source]

mean(field | scenario_a) - mean(field | scenario_b) – the simulated effect of A vs B.

Parameters:
  • field_index (int)

  • scenario_a (str | None)

  • scenario_b (str | None)

  • n (int)

  • seed (int)

Return type:

float

simulate(model)[source]

Package a fitted model as a Simulator (see module docstring).

Parameters:

model (Any)

Return type:

Simulator