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: 'CausalModel', root: ASTtree, on: Union(str, NameSet), doing: Union(str, NameSet), knowing: Optional[NameSet] = 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 – the causal model root – the syntax tree as the root ASTtree on – the variable or the set of variables of interest doing – the intervention variables knowing – the observation variables
cm

return: the causal model

copy() → CausalFormula

Copy theAST. Note that the causal model is just referenced. The tree is copied.

Returns: the new CausalFormula
eval() → pyAgrum.Potential

Compute the Potential from the CausalFormula over vars using cond as value for others variables

Parameters: bn – the BN where to infer
latexQuery(values: Optional[Dict[str, str]] = None) → str

Returns a string representing the query compiled by this Formula. If values, the query is annotated with the values in the dictionary.

Parameters: values – the values to add in the query representation the string representing the causal query for this CausalFormula
root

return: ASTtree root of the CausalFormula tree

toLatex() → 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: pyAgrum.causal._CausalModel.CausalModel, on: Union[str, Set[str]], doing: Union[str, Set[str]], knowing: Optional[Set[str]] = None, values: Optional[Dict[str, int]] = None) → Tuple[pyAgrum.causal._CausalFormula.CausalFormula, pyAgrum.Potential, str]

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 <variable name>:<value>. The causal impact is determined in the causal DAG cm. This function returns a triplet with a latex format formula used to compute the causal impact, a potential 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 – causal model on – variable name or variable names set doing – variable name or variable names set knowing – variable names set values – Dictionary the CausalFormula, the computation, the explanation
pyAgrum.causal.doCalculusWithObservation(cm: pyAgrum.causal._CausalModel.CausalModel, on: str, doing: Set[str], knowing: Optional[Set[str]] = None) → pyAgrum.causal._CausalFormula.CausalFormula

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 – the variables of interest cm – the causal model doing – the interventions knowing – the observations the CausalFormula for computing this causal impact
pyAgrum.causal.identifyingIntervention(cm: pyAgrum.causal._CausalModel.CausalModel, Y: Set[str], X: Set[str], P: pyAgrum.causal._doAST.ASTtree = None) → pyAgrum.causal._doAST.ASTtree

Following Shpitser, Ilya and Judea Pearl. ‘Identification of Conditional Interventional Distributions.’ UAI2006 and ‘Complete Identification Methods for the Causal Hierarchy’ JMLR 2008

Parameters: cm – the causal model Y – The variables of interest (named following the paper) X – The variable of intervention (named following the paper) P – The ASTtree representing the calculus in construction the ASTtree representing the calculus