![]() |
aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
|
A container for an identified causal query. More...
#include <causalFormula.h>
Public Member Functions | |
| CausalFormula (const CausalModel< GUM_SCALAR > &cm, std::unique_ptr< ASTtree< GUM_SCALAR > > root, const Set< std::string > &on, const Set< std::string > &doing, const Set< std::string > &knowing=Set< std::string >{}, std::string_view explanation="") | |
| Constructs a CausalFormula object (variables given by names). | |
| CausalFormula (const CausalModel< GUM_SCALAR > &cm, std::unique_ptr< ASTtree< GUM_SCALAR > > root, const NodeSet &on, const NodeSet &doing, const NodeSet &knowing=NodeSet{}, std::string_view explanation="") | |
| Constructs a CausalFormula object (variables given by node ids). | |
| CausalFormula (const CausalFormula &other) | |
| Copy constructor — performs a deep copy of the AST. | |
| CausalFormula (CausalFormula &&)=default | |
| Move constructor — defaulted (suppressed by the user-defined copy constructor above). | |
| Tensor< GUM_SCALAR > | eval () const |
| Evaluates the formula's AST to compute the resulting probability distribution. | |
| std::string | toString () const |
| Generates a string representation of the formula's AST. | |
| std::string | toLatex (std::string_view doOperatorPrefix="do(", std::string_view doOperatorSuffix=")") const |
| Generates a full LaTeX equation: Query = Formula. | |
| std::string | latexQuery (std::string_view doOperatorPrefix="do(", std::string_view doOperatorSuffix=")") const |
| Generates a LaTeX representation of the original query, e.g., P(Y | do(X), Z). | |
| std::unique_ptr< CausalFormula< GUM_SCALAR > > | copy () const |
| Creates a deep copy of the CausalFormula (including its AST). | |
| bool | isIdentified () const noexcept |
| Whether the causal effect has been identified. | |
| const ASTtree< GUM_SCALAR > & | root () const |
| Access the root AST node of the identified formula. | |
| const CausalModel< GUM_SCALAR > & | cm () const |
| const NodeSet & | on () const |
| const NodeSet & | doing () const |
| const NodeSet & | knowing () const |
| const std::string & | explanation () const |
| std::vector< std::string > | onNames () const |
| Convenience: return names corresponding to stored node ids (sorted). | |
| std::vector< std::string > | doingNames () const |
| std::vector< std::string > | knowingNames () const |
Private Member Functions | |
| void | _ensureVariablesExist () const |
| Verifies that all variables (_on, _knowing, _doing) exist in the BN. | |
| void | _ensureNoVariablesOverlap () const |
| Verifies that all variables (_on, _knowing, _doing) have no intersection. | |
Static Private Member Functions | |
| static NodeSet | _toNodeSetFromNames_ (const CausalModel< GUM_SCALAR > &cm, const Set< std::string > &names) |
| Convert a set of names to a set of node ids (validates existence). | |
Private Attributes | |
| const CausalModel< GUM_SCALAR > & | _cm |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | _root |
| const NodeSet | _on |
| const NodeSet | _doing |
| const NodeSet | _knowing |
| const std::string | _explanation |
A container for an identified causal query.
This class binds an identified formula (as an ASTtree) to the context of the query that produced it: the CausalModel and the sets of variables for on, doing, and knowing.
It provides methods to:
| GUM_SCALAR | The numeric type for tensor computations. |
Definition at line 74 of file causalFormula.h.
| gum::CausalFormula< GUM_SCALAR >::CausalFormula | ( | const CausalModel< GUM_SCALAR > & | cm, |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | root, | ||
| const Set< std::string > & | on, | ||
| const Set< std::string > & | doing, | ||
| const Set< std::string > & | knowing = Set< std::string >{}, | ||
| std::string_view | explanation = "" ) |
Constructs a CausalFormula object (variables given by names).
| cm | The causal model against which the formula was identified. |
| root | The identified formula as an Abstract Syntax Tree (ownership moved). |
| on | The set of outcome variable names (the "Y" in P(Y|...)). |
| doing | The set of intervention variable names (the "do(X)")). |
| knowing | The set of conditioning variable names (optional evidence). |
| explanation | A human-readable explanation of the identification method used (optional). |
Definition at line 97 of file causalFormula_tpl.h.
References _cm, _doing, _ensureNoVariablesOverlap(), _ensureVariablesExist(), _explanation, _knowing, _on, _root, _toNodeSetFromNames_(), cm(), doing(), explanation(), knowing(), on(), and root().
Referenced by CausalFormula(), and CausalFormula().
| gum::CausalFormula< GUM_SCALAR >::CausalFormula | ( | const CausalModel< GUM_SCALAR > & | cm, |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | root, | ||
| const NodeSet & | on, | ||
| const NodeSet & | doing, | ||
| const NodeSet & | knowing = NodeSet{}, | ||
| std::string_view | explanation = "" ) |
Constructs a CausalFormula object (variables given by node ids).
| cm | The causal model against which the formula was identified. |
| root | The identified formula as an Abstract Syntax Tree (ownership moved). |
| on | The set of outcome variable ids (the "Y" in P(Y|...)). |
| doing | The set of intervention variable ids (the "do(X)")). |
| knowing | The set of conditioning variable ids (optional evidence). |
| explanation | A human-readable explanation of the identification method used (optional). |
Definition at line 111 of file causalFormula_tpl.h.
References _cm, _doing, _ensureNoVariablesOverlap(), _ensureVariablesExist(), _explanation, _knowing, _on, _root, cm(), doing(), explanation(), knowing(), on(), and root().
| gum::CausalFormula< GUM_SCALAR >::CausalFormula | ( | const CausalFormula< GUM_SCALAR > & | other | ) |
Copy constructor — performs a deep copy of the AST.
Required so that types containing CausalFormula (e.g. CausalImpact) remain copy-constructible. SWIG's SwigValueWrapper<T> stores the wrapped return value via copy construction, so without this the Windows/MSVC CI fails to compile any binding that returns CausalImpact by value.
Definition at line 124 of file causalFormula_tpl.h.
References CausalFormula(), _cm, _doing, _explanation, _knowing, _on, _root, and copy().
|
default |
Move constructor — defaulted (suppressed by the user-defined copy constructor above).
References CausalFormula(), _ensureNoVariablesOverlap(), _ensureVariablesExist(), _toNodeSetFromNames_(), cm(), doing(), doingNames(), explanation(), knowing(), knowingNames(), on(), onNames(), and root().
|
private |
Verifies that all variables (_on, _knowing, _doing) have no intersection.
| gum::OperationNotAllowed | if any variable appears in two roles. |
Definition at line 80 of file causalFormula_tpl.h.
References _doing, _knowing, _on, and GUM_ERROR.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
|
private |
Verifies that all variables (_on, _knowing, _doing) exist in the BN.
| gum::NotFound | if any variable id is not found. |
Definition at line 68 of file causalFormula_tpl.h.
References _cm, _doing, _knowing, and _on.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
|
staticprivate |
Convert a set of names to a set of node ids (validates existence).
Definition at line 57 of file causalFormula_tpl.h.
References cm(), and gum::Set< Key >::insert().
Referenced by CausalFormula(), and CausalFormula().
| const CausalModel< GUM_SCALAR > & gum::CausalFormula< GUM_SCALAR >::cm | ( | ) | const |
Definition at line 275 of file causalFormula_tpl.h.
References _cm.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), and _toNodeSetFromNames_().
| std::unique_ptr< CausalFormula< GUM_SCALAR > > gum::CausalFormula< GUM_SCALAR >::copy | ( | ) | const |
Creates a deep copy of the CausalFormula (including its AST).
Definition at line 229 of file causalFormula_tpl.h.
References _cm, _doing, _knowing, _on, and _root.
Referenced by CausalFormula().
| const NodeSet & gum::CausalFormula< GUM_SCALAR >::doing | ( | ) | const |
Definition at line 285 of file causalFormula_tpl.h.
References _doing.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
| std::vector< std::string > gum::CausalFormula< GUM_SCALAR >::doingNames | ( | ) | const |
Definition at line 251 of file causalFormula_tpl.h.
Referenced by CausalFormula(), and latexQuery().
| Tensor< GUM_SCALAR > gum::CausalFormula< GUM_SCALAR >::eval | ( | ) | const |
Evaluates the formula's AST to compute the resulting probability distribution.
Definition at line 143 of file causalFormula_tpl.h.
| const std::string & gum::CausalFormula< GUM_SCALAR >::explanation | ( | ) | const |
Definition at line 295 of file causalFormula_tpl.h.
References _explanation.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
|
noexcept |
Whether the causal effect has been identified.
Returns true iff this formula has a valid AST (i.e., identification succeeded and evaluation is possible). When this returns false, calling root() or eval() will throw.
Definition at line 132 of file causalFormula_tpl.h.
References _root.
| const NodeSet & gum::CausalFormula< GUM_SCALAR >::knowing | ( | ) | const |
Definition at line 290 of file causalFormula_tpl.h.
References _knowing.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
| std::vector< std::string > gum::CausalFormula< GUM_SCALAR >::knowingNames | ( | ) | const |
Definition at line 262 of file causalFormula_tpl.h.
Referenced by CausalFormula(), and latexQuery().
| std::string gum::CausalFormula< GUM_SCALAR >::latexQuery | ( | std::string_view | doOperatorPrefix = "do(", |
| std::string_view | doOperatorSuffix = ")" ) const |
Generates a LaTeX representation of the original query, e.g., P(Y | do(X), Z).
Definition at line 181 of file causalFormula_tpl.h.
References _cm, _doing, _knowing, _on, doingNames(), knowingNames(), and onNames().
Referenced by toLatex().
| const NodeSet & gum::CausalFormula< GUM_SCALAR >::on | ( | ) | const |
Definition at line 280 of file causalFormula_tpl.h.
References _on.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
| std::vector< std::string > gum::CausalFormula< GUM_SCALAR >::onNames | ( | ) | const |
Convenience: return names corresponding to stored node ids (sorted).
Definition at line 240 of file causalFormula_tpl.h.
Referenced by CausalFormula(), and latexQuery().
| const ASTtree< GUM_SCALAR > & gum::CausalFormula< GUM_SCALAR >::root | ( | ) | const |
Access the root AST node of the identified formula.
Use this to inspect the symbolic structure of the identified effect.
| gum::OperationNotAllowed | if no AST is available (i.e., the effect is not identifiable with the current methods). |
Definition at line 137 of file causalFormula_tpl.h.
References _root, and GUM_ERROR.
Referenced by CausalFormula(), CausalFormula(), and CausalFormula().
| std::string gum::CausalFormula< GUM_SCALAR >::toLatex | ( | std::string_view | doOperatorPrefix = "do(", |
| std::string_view | doOperatorSuffix = ")" ) const |
Generates a full LaTeX equation: Query = Formula.
Definition at line 158 of file causalFormula_tpl.h.
References _cm, _doing, _knowing, _on, _root, gum::HashTable< Key, Val >::exists(), gum::HashTable< Key, Val >::insert(), and latexQuery().
| std::string gum::CausalFormula< GUM_SCALAR >::toString | ( | ) | const |
Generates a string representation of the formula's AST.
Definition at line 152 of file causalFormula_tpl.h.
References _root.
|
private |
Definition at line 200 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), _ensureVariablesExist(), cm(), copy(), doingNames(), eval(), knowingNames(), latexQuery(), onNames(), and toLatex().
|
private |
Definition at line 203 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), _ensureNoVariablesOverlap(), _ensureVariablesExist(), copy(), doing(), doingNames(), latexQuery(), and toLatex().
|
private |
Definition at line 205 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), and explanation().
|
private |
Definition at line 204 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), _ensureNoVariablesOverlap(), _ensureVariablesExist(), copy(), knowing(), knowingNames(), latexQuery(), and toLatex().
|
private |
Definition at line 202 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), _ensureNoVariablesOverlap(), _ensureVariablesExist(), copy(), latexQuery(), on(), onNames(), and toLatex().
|
private |
Definition at line 201 of file causalFormula.h.
Referenced by CausalFormula(), CausalFormula(), CausalFormula(), copy(), eval(), isIdentified(), root(), toLatex(), and toString().