Causal Inference (a.k.a. do-calculus)
Obtaining and evaluating a CausalFormula is done using one these functions :
pyagrum.causal.causalImpact(cm, on, doing, knowing=None, values=None)
Section titled “pyagrum.causal.causalImpact(cm, on, doing, knowing=None, values=None)”Determines the causal impact of interventions.
Determines the causal impact of the interventions specified in doing on the single or list of variables on
knowing the states of the variables in knowing (optional). These last parameters is dictionary cm.
This function returns a triplet with a latex format formula used to compute the causal impact, a tensor
representing the probability distribution of on given the interventions and observations as parameters,
and an explanation of the method allowing the identification. If there is no impact, the joint probability of
on is simply returned. If the impact is not identifiable the formula and the adjustment will be None but an
explanation is still given.
- Parameters:
- cm (CausalModel) – the causal model
- on (str |**NameSet) – variable name or variable names set of interest
- doing (str |**NameSet) – the interventions
- knowing (str |**NameSet) – the observations
- values (Dict [**str ,**int ] default=None) – the values of interventions and observations
- Returns: the CausalFormula, the computation, the explanation
- Return type: Tuple[CausalFormula,pyagrum.Tensor,str]
pyagrum.causal.doCalculusWithObservation(cm, on, doing, knowing=None)
Section titled “pyagrum.causal.doCalculusWithObservation(cm, on, doing, knowing=None)”Compute the CausalFormula for an impact analysis given the causal model, the observed variables and the variable on which there will be intervention.
- Parameters:
- cm (CausalModel) – the causal model
- on (Set [**str ]) – the variables of interest
- doing (Set [**str ]) – the interventions
- knowing (Set [**str ] default=None) – the observations
- Returns: if possible, returns the formula to compute this intervention
- Return type: CausalFormula
- Raises: HedgeException, UnidentifiableException – if this calculous is not possible
pyagrum.causal.identifyingIntervention(cm, Y, X, P=None)
Section titled “pyagrum.causal.identifyingIntervention(cm, Y, X, P=None)”Following Shpitser, Ilya and Judea Pearl. ‘Identification of Conditional Interventional Distributions.’ UAI2006 and ‘Complete Identification Methods for the Causal Hierarchy’ JMLR 2008
- Parameters:
- cm (
CausalModel) – the causal model - Y (
Set[str]) – The variables of interest (named following the paper) - X (
Set[str]) – The variable of intervention (named following the paper) - P (
ASTtree) – The ASTtree representing the calculus in construction
- cm (
- Return type:
ASTtree - Returns: the ASTtree representing the calculus
Other functions for causal inference
Section titled “Other functions for causal inference”CausalFormula is the class that represents a causal query within a causal model. It mainly consists of:
- a reference to the associated
pyagrum.CausalModel, - three sets of variable names representing the groups in the query ,
- and an abstract syntax tree (AST) used to compute or display the query.
class pyagrum.causal.CausalFormula(cm, root, on, doing, knowing=None)
Section titled “class pyagrum.causal.CausalFormula(cm, root, on, doing, knowing=None)”Represents a causal query in a causal model. The query is encoded as an CausalFormula that can be evaluated in the causal model :
- Parameters:
- cm (CausalModel) – the causal model
- root (ASTtree) – the syntax tree
- on (str |**Set [**str ]) – the variable or the set of variables of interest
- doing (str |**Set [**str ]) – the intervention variable(s)
- knowing (None |**str |**Set [**str ]) – the observation variable(s)
property cm : CausalModel
Section titled “property cm : CausalModel”- Returns: the causal model
- Return type: CausalModel
copy()
Section titled “copy()”Copy theAST. Note that the causal model is just referenced. The tree is copied.
- Returns: the copu
- Return type: CausalFormula
eval()
Section titled “eval()”Compute the Tensor from the CausalFormula over vars using cond as value for others variables
- Returns: The resulting distribution
- Return type: pyagrum.Tensor
latexQuery(values=None)
Section titled “latexQuery(values=None)”Returns a string representing the query compiled by this Formula. If values, the query is annotated with the values in the dictionary.
- Parameters: values (None |**Dict [**str ,**str ]) – the values to add in the query representation
- Returns: the LaTeX representation of the causal query for this CausalFormula
- Return type: str
property root : ASTtree
Section titled “property root : ASTtree”- Returns: the causalFormula as an ASTtree
- Return type: ASTtree
toLatex()
Section titled “toLatex()”- Returns: a LaTeX representation of the CausalFormula
- Return type: str
pyagrum.causal.backdoor_generator(bn, cause, effect, not_bd=None)
Section titled “pyagrum.causal.backdoor_generator(bn, cause, effect, not_bd=None)”Generates backdoor sets for the pair of nodes (cause, effect) in the graph bn excluding the nodes in the set not_bd (optional)
- Parameters:
- bn (pyagrum.BayesNet)
- cause (int)
- effect (int)
- not_bd (Set [**int ] default=None)
- Yields: List[int] – the different backdoors
pyagrum.causal.frontdoor_generator(bn, x, y, not_fd=None)
Section titled “pyagrum.causal.frontdoor_generator(bn, x, y, not_fd=None)”Generates frontdoor sets for the pair of nodes (x, y) in the graph bn excluding the nodes in the set not_fd (optional)
- Parameters:
- bn (pyagrum.BayesNet)
- x (int)
- y (int)
- not_fd (Set [**int ] default=None)
- Yields: List[int] – the different frontdoors