pymc.model.transform.conditioning.do#
- pymc.model.transform.conditioning.do(model, vars_to_interventions, prune_vars=False)[source]#
Replace model variables by intervention variables.
Intervention variables will either show up as Data or Deterministics in the new model, depending on whether they depend on other RandomVariables or not.
- Parameters:
- model: PyMC Model
- vars_to_interventions: Dict of variable or name to TensorLike
Dictionary that maps model variables (or names) to intervention expressions. Intervention expressions must have a shape and data type that is compatible with the original model variable.
- prune_vars: bool, defaults to False
Whether to prune model variables that are not connected to any observed variables, after the interventions.
- Returns:
- new_model:
PyMC
model
A distinct PyMC model with the relevant variables replaced by the intervention expressions. All remaining variables are cloned and can be retrieved via new_model[“var_name”].
- new_model:
Examples
import pymc as pm with pm.Model() as m: x = pm.Normal("x", 0, 1) y = pm.Normal("y", x, 1) z = pm.Normal("z", y + x, 1) # Dummy posterior, same as calling `pm.sample` idata_m = az.from_dict({rv.name: [pm.draw(rv, draws=500)] for rv in [x, y, z]}) # Replace `y` by a constant `100.0` with pm.do(m, {y: 100.0}) as m_do: idata_do = pm.sample_posterior_predictive(idata_m, var_names="z")