Abstract Syntax Tree for Do-Calculus

The pyCausal package compute every causal query into an Abstract Syntax Tree (CausalFormula) that represents the exact computations to be done in order to answer to the probabilistic causal query.

The different types of node in an CausalFormula are presented below and are organized as a hierarchy of classes from pyAgrum.causal.ASTtree.

Inheritance diagram of pyAgrum.causal.ASTplus, pyAgrum.causal.ASTminus, pyAgrum.causal.ASTdiv, pyAgrum.causal.ASTmult, pyAgrum.causal.ASTsum, pyAgrum.causal.ASTjointProba, pyAgrum.causal.ASTposteriorProba

Internal node structure

class pyAgrum.causal.ASTtree(typ, verbose=False)

Represents a generic node for the CausalFormula. The type of the node will be registered in a string.

Parameters
  • type – the type of the node (will be specified in concrete children classes.

  • typ (str) –

copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new causal tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

class pyAgrum.causal.ASTBinaryOp(typ, op1, op2)

Represents a generic binary node for the CausalFormula. The op1 and op2 are the two operands of the class.

Parameters
  • type – the type of the node (will be specified in concrete children classes

  • op1 (ASTtree) – left operand

  • op2 (ASTtree) – right operand

  • typ (str) –

copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new causal tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property op1: pyAgrum.causal._doAST.ASTtree

return: the left operand

Return type

ASTtree

property op2: pyAgrum.causal._doAST.ASTtree

return: the right operand

Return type

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

Basic Binary Operations

class pyAgrum.causal.ASTplus(op1, op2)

Represents the sum of 2 causal.ASTtree

Parameters
copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property op1: pyAgrum.causal._doAST.ASTtree

return: the left operand

Return type

ASTtree

property op2: pyAgrum.causal._doAST.ASTtree

return: the right operand

Return type

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

class pyAgrum.causal.ASTminus(op1, op2)

Represents the substraction of 2 causal.ASTtree

Parameters
copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property op1: pyAgrum.causal._doAST.ASTtree

return: the left operand

Return type

ASTtree

property op2: pyAgrum.causal._doAST.ASTtree

return: the right operand

Return type

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

class pyAgrum.causal.ASTdiv(op1, op2)

Represents the division of 2 causal.ASTtree

Parameters
copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property op1: pyAgrum.causal._doAST.ASTtree

return: the left operand

Return type

ASTtree

property op2: pyAgrum.causal._doAST.ASTtree

return: the right operand

Return type

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

class pyAgrum.causal.ASTmult(op1, op2)

Represents the multiplication of 2 causal.ASTtree

Parameters
copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property op1: pyAgrum.causal._doAST.ASTtree

return: the left operand

Return type

ASTtree

property op2: pyAgrum.causal._doAST.ASTtree

return: the right operand

Return type

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

Complex operations

class pyAgrum.causal.ASTsum(var, term)

Represents a sum over a variable of a causal.ASTtree.

Parameters
  • var (List[str]) – name of the variable

  • term (ASTtree) – the tree to be evaluated

copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of the sum

Parameters

contextual_bn (BayesNet) – BN where to infer

Return type

Potential

Returns

the value of the sum

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property term: pyAgrum.causal._doAST.ASTtree

return: the ASTtree of the expression inside the sum

Return type

ASTtree

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

class pyAgrum.causal.ASTjointProba(varNames)

Represent a joint probability in the base observational part of the causal.CausalModel

Parameters

varNames (Set[str]) – a set of variable names

copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree :rtype: str :return: the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

property varNames: Set[str]

return: the set of names of var

Return type

Set[str]

class pyAgrum.causal.ASTposteriorProba(bn, varset, knw)

Represent a conditional probability \(P_{bn}(vars|knw)\) that can be computed by an inference in a BN.

Parameters
  • bn (BayesNet) – the pyAgrum:pyAgrum.BayesNet

  • varset (Set[str]) – a set of variable names (in the BN)

  • knw (Set[str]) – a set of variable names (in the BN)

property bn: pyAgrum.pyAgrum.BayesNet

return: bn in \(P_{bn}(vars|knw)\)

Return type

BayesNet

copy()

Copy an CausalFormula tree

Return type

ASTtree

Returns

the new CausalFormula tree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN :type contextual_bn: BayesNet :param contextual_bn: the BN in which will be done the computations :rtype: Potential :return: the resulting Potential

fastToLatex(nameOccur)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

property knw: Set[str]

return: knw in \(P_{bn}(vars|knw)\)

Return type

Set[str]

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Dict[str, int]) –

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Return type

str

Returns

the LaTeX string

Parameters

nameOccur (Optional[Dict[str, int]]) –

property type: str

return: the type of the node

Return type

str

property vars: Set[str]

return: vars in \(P_{bn}(vars|knw)\)

Return type

Set[str]