![]() |
aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
|
A causal model pairing a causal DAG with an optional observational BayesNet. More...
#include <causalModel.h>
Public Member Functions | |
| CausalModel ()=delete | |
| Default constructor disabled: a causal model must be built from a BN. | |
| CausalModel (const BayesNet< GUM_SCALAR > &observationalBN) | |
| Construct a causal model with no latent variables. | |
| CausalModel (const BayesNet< GUM_SCALAR > &observationalBN, const LatentDescriptorVector &latentVarsDescriptor, bool assumeNonSpurious=false) | |
| Construct a causal model and add a list of latent confounders. | |
| CausalModel (const DAG &dag, const LatentDescriptorVector &latentVarsDescriptor={}, bool assumeNonSpurious=false) | |
| Construct a causal model from a plain (named) DAG, without any BayesNet. | |
| CausalModel (const CausalModel &other) | |
| Copy constructor. | |
| CausalModel (CausalModel &&other) noexcept | |
| Move constructor. | |
| ~CausalModel () | |
| Destructor. | |
| CausalModel & | operator= (const CausalModel &other)=default |
| Copy assignment. | |
| CausalModel & | operator= (CausalModel &&other) noexcept=default |
| Move assignment. | |
| void | addLatentVariable (std::string_view latentName, const std::vector< std::string > &childrenOfLatent, bool assumeNonSpurious=false) |
| Add a latent variable by names of its observed children. | |
| void | addLatentVariable (std::string_view latentName, const std::vector< NodeId > &childrenOfLatent, bool assumeNonSpurious=false) |
| Add a latent variable by **NodeId**s of its observed children. | |
| bool | existsArc (NodeId x, NodeId y) const |
| Whether a causal arc x → y exists (by ids) in the causal DAG. | |
| bool | existsArc (std::string_view x, std::string_view y) const |
| Whether a causal arc x → y exists (by names) in the causal DAG. | |
| void | assumeSpurious (NodeId x, NodeId y) |
| Mark an arc as spurious: present in observationalBN, removed from causalDAG. | |
| void | assumeSpurious (std::string_view x, std::string_view y) |
| void | assumeNonSpurious (NodeId x, NodeId y) |
| Mark an arc as non-spurious: present in observationalBN, added to causalDAG. | |
| void | assumeNonSpurious (std::string_view x, std::string_view y) |
| bool | isAssumedSpurious (NodeId x, NodeId y) const |
| Returns true if arc is present in observationalBN and absent in causalDAG. | |
| bool | isAssumedSpurious (std::string_view x, std::string_view y) const |
| std::optional< NodeSet > | backDoor (NodeId cause, NodeId effect) const |
| Find a backdoor adjustment set (Z) between cause and effect (IDs only). | |
| std::optional< NodeSet > | backDoor (std::string_view cause, std::string_view effect) const |
| std::optional< NodeSet > | frontDoor (NodeId cause, NodeId effect) const |
| Find a frontdoor adjustment set (Z) between cause and effect (IDs only). | |
| std::optional< NodeSet > | frontDoor (std::string_view cause, std::string_view effect) const |
| Find a frontdoor adjustment set (Z) between cause and effect (IDs only). | |
| CausalModel< GUM_SCALAR > | inducedCausalSubModel (const CausalModel< GUM_SCALAR > &cm, NodeSet subset) const |
| Induced causal submodel on a subset of nodes. | |
| std::string | toDot () const |
| DOT representation of the causal DAG (observed + latent), with the look of the configuration. | |
| std::string | toDot (const dot::DotOptions &options) const |
| DOT representation of the causal DAG (observed + latent), with the options given by the caller. | |
| std::string | toDot (const bool SHOW_LATENT_NAMES, const char *NODE_BG=nullptr, const char *NODE_FG=nullptr, const char *EDGE_COL=nullptr) const |
| DOT representation of the causal DAG (observed + latent), with values given by position. | |
| bool | hasObservationalBN () const noexcept |
| Whether this model was built from a BayesNet (CPTs available). | |
| const BayesNet< GUM_SCALAR > & | observationalBN () const |
| Observational BN (observed variables only). | |
| DAG | causalDAG () const |
| Causal DAG (observed + latent variables), with node names set. | |
| Set< std::string > | names () const |
| All variable names appearing in the causal model (observed + latent). | |
| NodeId | idFromName (std::string_view name) const |
| Node id from variable name (observed or latent). | |
| std::string | nameFromId (NodeId id) const |
| Variable name from node id (observed or latent). | |
| Bijection< NodeId, std::string > | id2name (bool includeLatentVariable=false) const |
| Bidirectional mapping between node ids and variable names. | |
| NodeSet | latentVariablesIds () const |
| Node ids of all latent variables. | |
| Set< std::string > | latentVariablesNames () const |
| Names of all latent variables. | |
| NodeSet | parents (NodeId x) const |
| Parents of a node (by id) in the causal DAG (including latents). | |
| NodeSet | parents (std::string_view name) const |
| Parents of a node (by name) in the causal DAG (including latents). | |
| NodeSet | children (NodeId x) const |
| Children of a node (by id) in the causal DAG (including latents). | |
| NodeSet | children (std::string_view name) const |
| Children of a node (by name) in the causal DAG (including latents). | |
| NodeProperty< NodeId > | connectedComponents () const |
| Weakly connected components of the causal DAG. | |
| const DiscreteVariable & | variable (NodeId id) const |
| From id to variable (observed only, by id). | |
| const DiscreteVariable & | variable (std::string_view name) const |
| From name to variable (observed only, by id). | |
Private Member Functions | |
| std::string | _toDot_ (const dot::CausalDotStyle &style, const dot::DotOptions &options) const |
| the dot of the causal DAG, with a look and options | |
Private Attributes | |
| std::optional< BayesNet< GUM_SCALAR > > | _observationalBN_ |
| The observed Bayesian network, when the model was built with CPTs. Absent when built from a plain DAG — see hasObservationalBN(). | |
| DAG | _observedDAG_ |
| Frozen copy of the observed DAG (never mutated after construction); names are set on it directly (setName) — the single source of truth for observed variable names. | |
| DAG | _causalDAG_ |
| The underlying DAG representing the causal structure (observed + latent). | |
| Bijection< NodeId, std::string > | _ids_names_ |
| Bidirectional mapping between node ids and variable names (latents only). | |
A causal model pairing a causal DAG with an optional observational BayesNet.
The class is DAG-centric for causality: all causal-structure queries and edits happen on _causalDAG_, which may include latent variables that do not appear in _observationalBN_. Name/Id bookkeeping is handled so you can work with either.
A CausalModel can be built either from a full BayesNet (CPTs available, the classic use case) or from a plain named DAG (structure only, see the DAG-only constructor and hasObservationalBN()). Every structural operation (backdoor/frontdoor, d-separation, toDot, induced submodels, do-calculus tree construction) works in both cases; anything that reads a CPT (ASTtree::eval, CausalFormula::eval, Counterfactual) throws gum::OperationNotAllowed when no BayesNet is present.
Definition at line 96 of file causalModel.h.
|
delete |
Default constructor disabled: a causal model must be built from a BN.
References assumeNonSpurious(), and observationalBN().
Referenced by CausalModel(), CausalModel(), CausalModel(), CausalModel(), ~CausalModel(), inducedCausalSubModel(), operator=(), and operator=().
|
explicit |
Construct a causal model with no latent variables.
| observationalBN | the observed Bayesian network |
Initializes the causal DAG as the BN's DAG (observed-only).
Definition at line 75 of file causalModel_tpl.h.
References CausalModel(), _causalDAG_, _observationalBN_, _observedDAG_, and observationalBN().
|
explicit |
Construct a causal model and add a list of latent confounders.
| observationalBN | the observed Bayesian network |
| latentVarsDescriptor | list of (latentName, childrenIds) descriptors |
| assumeNonSpurious | whether to preserve existing arcs among the latent's children |
Each latent is created and added as a parent of the provided children in the causal DAG. The observed BN remains unchanged.
Definition at line 87 of file causalModel_tpl.h.
References CausalModel(), _causalDAG_, _observationalBN_, _observedDAG_, addLatentVariable(), assumeNonSpurious(), children(), and observationalBN().
|
explicit |
Construct a causal model from a plain (named) DAG, without any BayesNet.
| dag | a named DAG (every node must have a name, see gum::DAG::hasName) |
| latentVarsDescriptor | list of (latentName, childrenIds) descriptors |
| assumeNonSpurious | whether to preserve existing arcs among the latent's children |
The resulting model has no observational BayesNet: hasObservationalBN() returns false, and observationalBN()/variable()/CausalFormula::eval()/CausalImpact::eval()/Counterfactual throw gum::OperationNotAllowed. All structural operations (backdoor/frontdoor, d-separation, toDot, induced submodels, do-calculus tree construction) work normally.
| gum::InvalidArgument | if some node of dag has no name. |
Definition at line 117 of file causalModel_tpl.h.
References _causalDAG_, _observedDAG_, assumeNonSpurious(), and gum::NodeGraphPart::nodes().
| gum::CausalModel< GUM_SCALAR >::CausalModel | ( | const CausalModel< GUM_SCALAR > & | other | ) |
Copy constructor.
Definition at line 101 of file causalModel_tpl.h.
References CausalModel(), _causalDAG_, _ids_names_, _observationalBN_, and _observedDAG_.
|
noexcept |
Move constructor.
Definition at line 109 of file causalModel_tpl.h.
References CausalModel(), _causalDAG_, _ids_names_, _observationalBN_, and _observedDAG_.
| gum::CausalModel< GUM_SCALAR >::~CausalModel | ( | ) |
Destructor.
Definition at line 82 of file causalModel_tpl.h.
References CausalModel().
|
private |
the dot of the causal DAG, with a look and options
Definition at line 441 of file causalModel_tpl.h.
References _causalDAG_, _toDot_(), gum::dot::addDefaultAttribute(), gum::dot::DotOptions::arc(), gum::dot::arcAttributes(), gum::dot::DotStyle::arcColor, gum::contains(), gum::dot::DotWriter::edge(), gum::dot::CausalDotStyle::latentBgColor, gum::dot::CausalDotStyle::latentFgColor, latentVariablesIds(), nameFromId(), gum::dot::DotOptions::node(), gum::dot::DotWriter::node(), gum::dot::nodeAttributes(), gum::dot::DotStyle::nodeBgColor, gum::dot::CausalDotStyle::showLatentNames, gum::dot::DotWriter::str(), and gum::dot::writePreamble().
Referenced by _toDot_(), toDot(), and toDot().
| void gum::CausalModel< GUM_SCALAR >::addLatentVariable | ( | std::string_view | latentName, |
| const std::vector< NodeId > & | childrenOfLatent, | ||
| bool | assumeNonSpurious = false ) |
Add a latent variable by **NodeId**s of its observed children.
| latentName | new latent variable name |
| childrenOfLatent | node ids of observed children |
| assumeNonSpurious | preserve existing arcs among the children if true. |
A new latent node is inserted into the causal DAG and connected as a parent of each listed child. The observed BN is not modified.
Definition at line 152 of file causalModel_tpl.h.
References _observedDAG_, addLatentVariable(), assumeNonSpurious(), and GUM_ERROR.
| void gum::CausalModel< GUM_SCALAR >::addLatentVariable | ( | std::string_view | latentName, |
| const std::vector< std::string > & | childrenOfLatent, | ||
| bool | assumeNonSpurious = false ) |
Add a latent variable by names of its observed children.
| latentName | new latent variable name |
| childrenOfLatent | names of observed children |
| assumeNonSpurious | preserve existing arcs among the children if true |
A new latent node is inserted into the causal DAG and connected as a parent of each listed child. The observed BN is not modified.
Definition at line 139 of file causalModel_tpl.h.
References addLatentVariable(), assumeNonSpurious(), and idFromName().
Referenced by CausalModel(), addLatentVariable(), addLatentVariable(), and operator=().
| void gum::CausalModel< GUM_SCALAR >::assumeNonSpurious | ( | NodeId | x, |
| NodeId | y ) |
Mark an arc as non-spurious: present in observationalBN, added to causalDAG.
Throws if arc is not present in observationalBN.
Definition at line 257 of file causalModel_tpl.h.
References _observedDAG_, assumeNonSpurious(), and GUM_ERROR.
Referenced by CausalModel(), CausalModel(), CausalModel(), addLatentVariable(), addLatentVariable(), assumeNonSpurious(), assumeNonSpurious(), and operator=().
| void gum::CausalModel< GUM_SCALAR >::assumeNonSpurious | ( | std::string_view | x, |
| std::string_view | y ) |
Definition at line 269 of file causalModel_tpl.h.
References assumeNonSpurious(), and idFromName().
| void gum::CausalModel< GUM_SCALAR >::assumeSpurious | ( | NodeId | x, |
| NodeId | y ) |
Mark an arc as spurious: present in observationalBN, removed from causalDAG.
Throws if arc is not present in observationalBN.
Definition at line 240 of file causalModel_tpl.h.
References _causalDAG_, _observedDAG_, assumeSpurious(), and GUM_ERROR.
Referenced by assumeSpurious(), assumeSpurious(), and operator=().
| void gum::CausalModel< GUM_SCALAR >::assumeSpurious | ( | std::string_view | x, |
| std::string_view | y ) |
Definition at line 252 of file causalModel_tpl.h.
References assumeSpurious(), and idFromName().
| std::optional< NodeSet > gum::CausalModel< GUM_SCALAR >::backDoor | ( | NodeId | cause, |
| NodeId | effect ) const |
Find a backdoor adjustment set (Z) between cause and effect (IDs only).
Enumerates admissible backdoor sets in the current causal DAG (excluding latent variables) and returns the first valid one found. Returns std::nullopt if no backdoor set exists at all. Note: an empty set is a valid backdoor when X has no back-door paths.
Preconditions:
Definition at line 381 of file causalModel_tpl.h.
References backDoor(), and latentVariablesIds().
Referenced by gum::CausalImpact< GUM_SCALAR >::_buildFromNames_(), backDoor(), backDoor(), and operator=().
| std::optional< NodeSet > gum::CausalModel< GUM_SCALAR >::backDoor | ( | std::string_view | cause, |
| std::string_view | effect ) const |
Definition at line 584 of file causalModel_tpl.h.
References backDoor(), and idFromName().
| DAG gum::CausalModel< GUM_SCALAR >::causalDAG | ( | ) | const |
Causal DAG (observed + latent variables), with node names set.
Definition at line 576 of file causalModel_tpl.h.
References _causalDAG_, causalDAG(), nameFromId(), and gum::NodeGraphPart::setName().
Referenced by gum::DoCalculus< GUM_SCALAR >::_cDecomposition_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), gum::DoCalculus< GUM_SCALAR >::_topoObserved_(), causalDAG(), and operator=().
| NodeSet gum::CausalModel< GUM_SCALAR >::children | ( | NodeId | x | ) | const |
Children of a node (by id) in the causal DAG (including latents).
Definition at line 367 of file causalModel_tpl.h.
References _causalDAG_, and children().
Referenced by CausalModel(), gum::DoCalculus< GUM_SCALAR >::_cDecomposition_(), children(), children(), and operator=().
| NodeSet gum::CausalModel< GUM_SCALAR >::children | ( | std::string_view | name | ) | const |
Children of a node (by name) in the causal DAG (including latents).
Definition at line 372 of file causalModel_tpl.h.
References children(), and idFromName().
| NodeProperty< NodeId > gum::CausalModel< GUM_SCALAR >::connectedComponents | ( | ) | const |
Weakly connected components of the causal DAG.
Definition at line 294 of file causalModel_tpl.h.
References _causalDAG_, connectedComponents(), and gum::graph::connectedComponents().
Referenced by connectedComponents(), and operator=().
| bool gum::CausalModel< GUM_SCALAR >::existsArc | ( | NodeId | x, |
| NodeId | y ) const |
Whether a causal arc x → y exists (by ids) in the causal DAG.
Definition at line 202 of file causalModel_tpl.h.
References _causalDAG_, and existsArc().
Referenced by existsArc(), existsArc(), and operator=().
| bool gum::CausalModel< GUM_SCALAR >::existsArc | ( | std::string_view | x, |
| std::string_view | y ) const |
Whether a causal arc x → y exists (by names) in the causal DAG.
Definition at line 207 of file causalModel_tpl.h.
References existsArc(), and idFromName().
| std::optional< NodeSet > gum::CausalModel< GUM_SCALAR >::frontDoor | ( | NodeId | cause, |
| NodeId | effect ) const |
Find a frontdoor adjustment set (Z) between cause and effect (IDs only).
Enumerates admissible frontdoor sets in the current causal DAG (excluding latent variables) and returns the first valid one found. Returns std::nullopt if no frontdoor set exists at all. Note: an empty set is a valid frontdoor in degenerate cases.
Preconditions:
Definition at line 395 of file causalModel_tpl.h.
References gum::Set< Key >::contains(), frontDoor(), and latentVariablesIds().
Referenced by frontDoor(), frontDoor(), and operator=().
| std::optional< NodeSet > gum::CausalModel< GUM_SCALAR >::frontDoor | ( | std::string_view | cause, |
| std::string_view | effect ) const |
Find a frontdoor adjustment set (Z) between cause and effect (IDs only).
Enumerates admissible frontdoor sets in the current causal DAG (excluding latent variables) and returns the first valid one found. Returns std::nullopt if no frontdoor set exists at all. Note: an empty set is a valid frontdoor in degenerate cases.
Preconditions:
| cause | name (string_view) of the cause (X). |
| effect | name (string_view) of the effect (Y). |
Definition at line 590 of file causalModel_tpl.h.
References frontDoor(), and idFromName().
|
noexcept |
Whether this model was built from a BayesNet (CPTs available).
Definition at line 561 of file causalModel_tpl.h.
References _observationalBN_, and hasObservationalBN().
Referenced by hasObservationalBN(), and operator=().
| Bijection< NodeId, std::string > gum::CausalModel< GUM_SCALAR >::id2name | ( | bool | includeLatentVariable = false | ) | const |
Bidirectional mapping between node ids and variable names.
Definition at line 538 of file causalModel_tpl.h.
References _ids_names_, _observedDAG_, id2name(), and gum::BijectionImplementation< T1, T2, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::insert().
Referenced by gum::DoCalculus< GUM_SCALAR >::_ID_(), id2name(), and operator=().
| NodeId gum::CausalModel< GUM_SCALAR >::idFromName | ( | std::string_view | name | ) | const |
Node id from variable name (observed or latent).
Definition at line 513 of file causalModel_tpl.h.
References _ids_names_, _observedDAG_, GUM_ERROR, and idFromName().
Referenced by gum::CausalImpact< GUM_SCALAR >::_buildFromNames_(), gum::CausalImpact< GUM_SCALAR >::_namesToIds_(), gum::CausalFormula< GUM_SCALAR >::_toNodeSetFromNames_(), addLatentVariable(), assumeNonSpurious(), assumeSpurious(), backDoor(), children(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), existsArc(), frontDoor(), idFromName(), isAssumedSpurious(), operator=(), and variable().
| CausalModel< GUM_SCALAR > gum::CausalModel< GUM_SCALAR >::inducedCausalSubModel | ( | const CausalModel< GUM_SCALAR > & | cm, |
| NodeSet | subset ) const |
Induced causal submodel on a subset of nodes.
| cm | a source causal model |
| subset | node set to keep (observed + latent) |
Definition at line 300 of file causalModel_tpl.h.
References CausalModel(), _observedDAG_, gum::Set< Key >::empty(), inducedCausalSubModel(), gum::Set< Key >::insert(), and gum::NodeGraphPart::nodes().
Referenced by gum::DoCalculus< GUM_SCALAR >::_ID_(), inducedCausalSubModel(), and operator=().
| bool gum::CausalModel< GUM_SCALAR >::isAssumedSpurious | ( | NodeId | x, |
| NodeId | y ) const |
Returns true if arc is present in observationalBN and absent in causalDAG.
Definition at line 274 of file causalModel_tpl.h.
References _causalDAG_, _observedDAG_, and isAssumedSpurious().
Referenced by isAssumedSpurious(), isAssumedSpurious(), and operator=().
| bool gum::CausalModel< GUM_SCALAR >::isAssumedSpurious | ( | std::string_view | x, |
| std::string_view | y ) const |
Definition at line 279 of file causalModel_tpl.h.
References idFromName(), and isAssumedSpurious().
| NodeSet gum::CausalModel< GUM_SCALAR >::latentVariablesIds | ( | ) | const |
Node ids of all latent variables.
Definition at line 218 of file causalModel_tpl.h.
References _ids_names_, gum::Set< Key >::insert(), and latentVariablesIds().
Referenced by gum::DoCalculus< GUM_SCALAR >::_cDecomposition_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), _toDot_(), gum::DoCalculus< GUM_SCALAR >::_topoObserved_(), backDoor(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), frontDoor(), latentVariablesIds(), and operator=().
| Set< std::string > gum::CausalModel< GUM_SCALAR >::latentVariablesNames | ( | ) | const |
Names of all latent variables.
Definition at line 227 of file causalModel_tpl.h.
References _ids_names_, gum::Set< Key >::insert(), and latentVariablesNames().
Referenced by latentVariablesNames(), and operator=().
| std::string gum::CausalModel< GUM_SCALAR >::nameFromId | ( | NodeId | id | ) | const |
Variable name from node id (observed or latent).
Definition at line 528 of file causalModel_tpl.h.
References _ids_names_, _observedDAG_, and nameFromId().
Referenced by gum::DoCalculus< GUM_SCALAR >::_hedgeExceptionMsg(), gum::DoCalculus< GUM_SCALAR >::_ID_(), gum::CausalImpact< GUM_SCALAR >::_idsToNames_(), _toDot_(), causalDAG(), gum::CausalModel< GUM_ELEMENT >::inducedCausalSubModel(), nameFromId(), and operator=().
| Set< std::string > gum::CausalModel< GUM_SCALAR >::names | ( | ) | const |
All variable names appearing in the causal model (observed + latent).
Definition at line 500 of file causalModel_tpl.h.
References _ids_names_, _observedDAG_, gum::Set< Key >::insert(), and names().
Referenced by names(), and operator=().
| const BayesNet< GUM_SCALAR > & gum::CausalModel< GUM_SCALAR >::observationalBN | ( | ) | const |
Observational BN (observed variables only).
| gum::OperationNotAllowed | if the model was built from a plain DAG (see hasObservationalBN()). |
Definition at line 566 of file causalModel_tpl.h.
References _observationalBN_, GUM_ERROR, and observationalBN().
Referenced by CausalModel(), CausalModel(), CausalModel(), gum::Counterfactual< GUM_ELEMENT >::_adaptToOriginalVariables_(), gum::Counterfactual< GUM_ELEMENT >::_idAssignToNameAssign_(), gum::Counterfactual< GUM_ELEMENT >::_idsToNames_(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), observationalBN(), operator=(), variable(), and variable().
|
defaultnoexcept |
Move assignment.
References CausalModel(), addLatentVariable(), assumeNonSpurious(), assumeSpurious(), backDoor(), causalDAG(), gum::CausalModel< double >, children(), connectedComponents(), existsArc(), frontDoor(), hasObservationalBN(), id2name(), idFromName(), inducedCausalSubModel(), isAssumedSpurious(), latentVariablesIds(), latentVariablesNames(), nameFromId(), names(), observationalBN(), parents(), toDot(), and variable().
|
default |
| NodeSet gum::CausalModel< GUM_SCALAR >::parents | ( | NodeId | x | ) | const |
Parents of a node (by id) in the causal DAG (including latents).
Definition at line 356 of file causalModel_tpl.h.
References _causalDAG_, and parents().
Referenced by operator=(), parents(), and parents().
| NodeSet gum::CausalModel< GUM_SCALAR >::parents | ( | std::string_view | name | ) | const |
Parents of a node (by name) in the causal DAG (including latents).
Definition at line 362 of file causalModel_tpl.h.
References parents().
| std::string gum::CausalModel< GUM_SCALAR >::toDot | ( | ) | const |
DOT representation of the causal DAG (observed + latent), with the look of the configuration.
The colors of the nodes are the ones of the section causal (nodeBgColor, nodeFgColor for the observed variables, latentBgColor, latentFgColor for the latent ones), the latent variables are drawn as points unless causal.showLatentNames is true, and the color of the arcs is notebook.arcColor.
Definition at line 412 of file causalModel_tpl.h.
References toDot().
Referenced by operator=(), toDot(), toDot(), and toDot().
| std::string gum::CausalModel< GUM_SCALAR >::toDot | ( | const bool | SHOW_LATENT_NAMES, |
| const char * | NODE_BG = nullptr, | ||
| const char * | NODE_FG = nullptr, | ||
| const char * | EDGE_COL = nullptr ) const |
DOT representation of the causal DAG (observed + latent), with values given by position.
| SHOW_LATENT_NAMES | If true, display latent names explicitly. |
| NODE_BG | Node background color (hex code like "#404040" or Graphviz color name), for all the nodes ; the configuration if nullptr. |
| NODE_FG | Node label/text color, for all the nodes ; the configuration if nullptr. |
| EDGE_COL | Edge color ; the configuration if nullptr. |
Definition at line 422 of file causalModel_tpl.h.
References _toDot_(), gum::dot::CausalDotStyle::read(), and toDot().
| std::string gum::CausalModel< GUM_SCALAR >::toDot | ( | const dot::DotOptions & | options | ) | const |
DOT representation of the causal DAG (observed + latent), with the options given by the caller.
The nodes are named after the variables (L<id> for a latent variable without name), with the tooltip "(id) name" ; the options are indexed by the identifiers of the nodes of the causal DAG.
Definition at line 417 of file causalModel_tpl.h.
References _toDot_(), gum::dot::CausalDotStyle::read(), and toDot().
| const DiscreteVariable & gum::CausalModel< GUM_SCALAR >::variable | ( | NodeId | id | ) | const |
From id to variable (observed only, by id).
Throws if id does not correspond to an observed variable.
| id | the node id |
| throws | gum::NotFound if id does not correspond to an observed variable in the model |
| throws | gum::OperationNotAllowed if the model has no observational BN (see hasObservationalBN()). |
Definition at line 596 of file causalModel_tpl.h.
References observationalBN(), and variable().
Referenced by operator=(), variable(), and variable().
| const DiscreteVariable & gum::CausalModel< GUM_SCALAR >::variable | ( | std::string_view | name | ) | const |
From name to variable (observed only, by id).
Throws if id does not correspond to an observed variable.
| name |
| throws | gum::NotFound if id does not correspond to an observed variable in the model |
| throws | gum::OperationNotAllowed if the model has no observational BN (see hasObservationalBN()). |
Definition at line 601 of file causalModel_tpl.h.
References idFromName(), observationalBN(), and variable().
|
private |
The underlying DAG representing the causal structure (observed + latent).
Definition at line 110 of file causalModel.h.
Referenced by CausalModel(), CausalModel(), CausalModel(), CausalModel(), CausalModel(), _toDot_(), assumeSpurious(), causalDAG(), children(), connectedComponents(), existsArc(), isAssumedSpurious(), and parents().
|
private |
Bidirectional mapping between node ids and variable names (latents only).
Definition at line 113 of file causalModel.h.
Referenced by CausalModel(), CausalModel(), id2name(), idFromName(), latentVariablesIds(), latentVariablesNames(), nameFromId(), and names().
|
private |
The observed Bayesian network, when the model was built with CPTs. Absent when built from a plain DAG — see hasObservationalBN().
Definition at line 103 of file causalModel.h.
Referenced by CausalModel(), CausalModel(), CausalModel(), CausalModel(), hasObservationalBN(), and observationalBN().
|
private |
Frozen copy of the observed DAG (never mutated after construction); names are set on it directly (setName) — the single source of truth for observed variable names.
Definition at line 107 of file causalModel.h.
Referenced by CausalModel(), CausalModel(), CausalModel(), CausalModel(), CausalModel(), addLatentVariable(), assumeNonSpurious(), assumeSpurious(), id2name(), idFromName(), inducedCausalSubModel(), isAssumedSpurious(), nameFromId(), and names().