BayesNet.contextualize
- BayesNet.contextualize(observations=None, interventions=None)
Return a new Bayesian network conditioned on observations and interventions.
- Parameters:
observations (
dict, optional) – a dict mapping variable names (str) or ids (int) to observed values (str or int)interventions (
dict, optional) – a dict mapping variable names (str) or ids (int) to intervened values (str or int)
- Returns:
a new BayesNet representing the interventional/observational distribution
- Return type:
- Raises:
pyagrum.InvalidArgument – if arguments are not dicts
Warning
contextualize is deprecated after 3.4.0, use
pyagrum.mutilateBNinstead (a hard intervention removes the variable instead of keeping it with a deterministic CPT).
Example
import pyagrum as gum
bn = gum.fastBN("A->B->C")
bn2 = bn.contextualize(observations={"A": 1}, interventions={"C": 0}) # deprecated: use pyagrum.mutilateBN
bn2.arcs()
# set()
bool((bn2.cpt("B")[:] == bn.cpt("B")[{"A": 1}]).all()) # P(B | A=1)
# True
bn2.cpt("C").tolist()
# [1.0, 0.0]
Class