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.

digraph inheritancead9e9c6ac4 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "pyAgrum.causal.ASTBinaryOp" [URL="#pyAgrum.causal.ASTBinaryOp",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents a generic binary node for the CausalFormula. The op1 and op2 are the two operands of the class."]; "pyAgrum.causal.ASTtree" -> "pyAgrum.causal.ASTBinaryOp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTdiv" [URL="#pyAgrum.causal.ASTdiv",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents the division of 2 :class:`causal.ASTtree`"]; "pyAgrum.causal.ASTBinaryOp" -> "pyAgrum.causal.ASTdiv" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTjointProba" [URL="#pyAgrum.causal.ASTjointProba",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represent a joint probability in the base observational part of the :class:`causal.CausalModel`"]; "pyAgrum.causal.ASTtree" -> "pyAgrum.causal.ASTjointProba" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTminus" [URL="#pyAgrum.causal.ASTminus",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents the substraction of 2 :class:`causal.ASTtree`"]; "pyAgrum.causal.ASTBinaryOp" -> "pyAgrum.causal.ASTminus" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTmult" [URL="#pyAgrum.causal.ASTmult",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents the multiplication of 2 :class:`causal.ASTtree`"]; "pyAgrum.causal.ASTBinaryOp" -> "pyAgrum.causal.ASTmult" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTplus" [URL="#pyAgrum.causal.ASTplus",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents the sum of 2 :class:`causal.ASTtree`"]; "pyAgrum.causal.ASTBinaryOp" -> "pyAgrum.causal.ASTplus" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTposteriorProba" [URL="#pyAgrum.causal.ASTposteriorProba",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represent a conditional probability :math:`P_{bn}(vars|knw)` that can be computed by an inference in a BN."]; "pyAgrum.causal.ASTtree" -> "pyAgrum.causal.ASTposteriorProba" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTsum" [URL="#pyAgrum.causal.ASTsum",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents a sum over a variable of a :class:`causal.ASTtree`."]; "pyAgrum.causal.ASTtree" -> "pyAgrum.causal.ASTsum" [arrowsize=0.5,style="setlinewidth(0.5)"]; "pyAgrum.causal.ASTtree" [URL="#pyAgrum.causal.ASTtree",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents a generic node for the CausalFormula. The type of the node will be registered in a string."]; }

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:
  • typ (str) – the type of the node (will be specified in concrete children classes.

  • verbose (bool) – if True, add some messages

copy()

Copy an CausalFormula tree

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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:
  • typ (str) – the type of the node (will be specified in concrete children classes

  • op1 (ASTtree) – left operand

  • op2 (ASTtree) – right operand

copy()

Copy an CausalFormula tree

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property op1: ASTtree
Returns:

the left operand

Return type:

ASTtree

property op2: ASTtree
Returns:

the right operand

Return type:

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property op1: ASTtree
Returns:

the left operand

Return type:

ASTtree

property op2: ASTtree
Returns:

the right operand

Return type:

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property op1: ASTtree
Returns:

the left operand

Return type:

ASTtree

property op2: ASTtree
Returns:

the right operand

Return type:

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property op1: ASTtree
Returns:

the left operand

Return type:

ASTtree

property op2: ASTtree
Returns:

the right operand

Return type:

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property op1: ASTtree
Returns:

the left operand

Return type:

ASTtree

property op2: ASTtree
Returns:

the right operand

Return type:

ASTtree

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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 (str) – name of the variable on which to sum

  • term (ASTtree) – the tree to be evaluated

copy()

Copy an CausalFormula tree

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

property term: ASTtree
Returns:

the term to sum

Return type:

ASTtree

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

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

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

the type of the node

Return type:

str

property varNames: Set[str]
Returns:

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 (pyAgrum.BayesNet) – the pyAgrum:pyAgrum.BayesNet

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

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

property bn: BayesNet
Returns:

the observationnal BayesNet in \(P_{bn}(vars|knw)\)

Return type:

pyAgrum.BayesNet

copy()

Copy an CausalFormula tree

Returns:

the new causal tree

Return type:

ASTtree

eval(contextual_bn)

Evaluation of a AST tree from inside a BN

Parameters:

contextual_bn (pyAgrum.BayesNet) – the observational Bayesian network in which will be done the computations

Returns:

the resulting Potential

Return type:

pyAgrum.Potential

fastToLatex(nameOccur)

Internal virtual function to create a LaTeX representation of the ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property knw: Set[str]
Returns:

(Conditioning) knw in \(P_{bn}(vars|knw)\)

Return type:

Set[str]

protectToLatex(nameOccur)

Create a protected LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int]) – the number of occurrence for each variable

Returns:

a protected version of LaTeX representation of the tree

Return type:

str

toLatex(nameOccur=None)

Create a LaTeX representation of a ASTtree

Parameters:

nameOccur (Dict[str,int] default=None) – the number of occurrence for each variable

Returns:

LaTeX representation of the tree

Return type:

str

property type: str
Returns:

the type of the node

Return type:

str

property vars: Set[str]
Returns:

(Conditioned) vars in \(P_{bn}(vars|knw)\)

Return type:

Set[str]