Causal Formula¶
CausalFormula is the class that represents a causal query in a causal model. Mainly it consits in
a reference to the CausalModel
Three sets of variables name that represent the 3 sets of variable in the query P(set1 | doing(set2),knowing(set3)).
the AST for compute the query.
- 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 : $P(on|knowing, overhook (doing))$
- Parameters
cm (
CausalModel
) – the causal modelroot (
ASTtree
) – the syntax tree as the root ASTtreeon (
Union
[str
,Set
[str
]]) – the variable or the set of variables of interestdoing (
Union
[str
,Set
[str
]]) – the intervention variablesknowing (
Optional
[Set
[str
]]) – the observation variables
- property cm: pyAgrum.causal._CausalModel.CausalModel¶
return: the causal model
- Return type
- copy()¶
Copy theAST. Note that the causal model is just referenced. The tree is copied.
- Return type
- Returns
the new CausalFormula
- eval()¶
Compute the Potential from the CausalFormula over vars using cond as value for others variables
- Return type
- Returns
- 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 (
Optional
[Dict
[str
,str
]]) – the values to add in the query representation- Return type
str
- Returns
the string representing the causal query for this CausalFormula
- property root: pyAgrum.causal._doAST.ASTtree¶
return: ASTtree root of the CausalFormula tree
- Return type
- toLatex()¶
- Return type
str
- Returns
a LaTeX representation of the CausalFormula
Causal Inference¶
Obtaining and evaluating a CausalFormula is done using one these functions :
- 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 variableson
knowing the states of the variables inknowing
(optional). These last parameters is dictionary <variable name>:<value>. The causal impact is determined in the causal DAGcm
. This function returns a triplet with a latex format formula used to compute the causal impact, a potential representing the probability distribution ofon
given the interventions and observations as parameters, and an explanation of the method allowing the identification. If there is no impact, the joint probability ofon
is simply returned. If the impact is not identifiable the formula and the adjustment will beNone
but an explanation is still given.- Parameters
cm (
CausalModel
) – causal modelon (
Union
[str
,Set
[str
]]) – variable name or variable names setdoing (
Union
[str
,Set
[str
]]) – variable name or variable names setknowing (
Optional
[Set
[str
]]) – variable names setvalues (
Optional
[Dict
[str
,int
]]) – Dictionary
- Return type
Tuple
[CausalFormula
,Potential
,str
]- Returns
the CausalFormula, the computation, the explanation
- 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
on (
str
) – the variables of interestcm (
CausalModel
) – the causal modeldoing (
Set
[str
]) – the interventionsknowing (
Optional
[Set
[str
]]) – the observations
- Return type
- Returns
the CausalFormula for computing this causal impact
- 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 modelY (
Set
[str
]) – The variables of interest (named following the paper)X (
Set
[str
]) – The variable of intervention (named following the paper)P (
Optional
[ASTtree
]) – The ASTtree representing the calculus in construction
- Return type
- Returns
the ASTtree representing the calculus