Abstract Syntax Tree for Do-Calculus
The causal module computes every causal query as an Abstract Syntax Tree (AST) that represents the exact probabilistic computations needed to answer a causal query.
The AST is an internal C++ data structure built by the do-calculus identification algorithm. It is organised as a hierarchy of node types:
- Leaf nodes: joint probability and posterior probability
- Binary operations: , , ,
- Sum-out node: marginalisation over a set of variables
Accessing the AST
Section titled “Accessing the AST”pyagrum.causalImpact() returns a tuple (formula, tensor, explanation) where formula
is a pyagrum.CausalImpact object carrying the identified AST. From it you can:
import pyagrum as gum
bn = gum.fastBN("X->Y->Z;X->Z")cm = gum.CausalModel(bn)
formula, tensor, explanation = gum.causalImpact(cm, on="Z", doing="X")
## Render the identified formula as a LaTeX stringprint(formula.toLatex())
## Inspect the AST as a nested dictprint(formula.toDict())
## Pretty-print the AST in the terminalformula.print_ast()Note
The AST node classes are internal to the C++ library and are not directly exposed in
the Python API. Use pyagrum.causalImpact() to obtain and inspect a causal formula.
SEE ALSO
Section titled “SEE ALSO”Causal computation in pyAgrum
: pyagrum.causalImpact() and pyagrum.CausalImpact — the entry point for obtaining an AST.