42#ifndef GUM_CAUSAL_MODEL_H
43#define GUM_CAUSAL_MODEL_H
53 template < GUM_Numeric GUM_SCALAR >
83 template < GUM_Numeric GUM_SCALAR >
153 const std::vector< std::string >& childrenOfLatent,
174 const std::vector< NodeId >& childrenOfLatent,
181 bool existsArc(std::string_view x, std::string_view y)
const;
226 std::optional< NodeSet >
backDoor(std::string_view cause, std::string_view effect)
const;
264 std::optional< NodeSet >
frontDoor(std::string_view cause, std::string_view effect)
const;
284 std::string
toDot(
const bool SHOW_LATENT_NAMES =
false,
285 const char* NODE_BG =
"#404040",
286 const char* NODE_FG =
"white",
287 const char* EDGE_COL =
"#4A4A4A")
const;
356#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Class representing Bayesian networks.
Template implementation of CausalModel/causalModel.h.
Root abstract node for the AST of algebraic expressions.
A causal model pairing an observational BayesNet with a causal DAG.
DAG causalDAG() const
Causal DAG (observed + latent variables), with node names set.
std::string toDot(const bool SHOW_LATENT_NAMES=false, const char *NODE_BG="#404040", const char *NODE_FG="white", const char *EDGE_COL="#4A4A4A") const
DOT representation of the causal DAG (observed + latent).
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.
CausalModel< GUM_SCALAR > inducedCausalSubModel(const CausalModel< GUM_SCALAR > &cm, NodeSet subset) const
Induced causal submodel on a subset of nodes.
~CausalModel()
Destructor.
NodeSet latentVariablesIds() const
Node ids of all latent variables.
DAG _causalDAG_
The underlying DAG representing the causal structure (observed + latent).
HashTable< NodeId, NodeSet > connectedComponents() const
Weakly connected components of the causal DAG.
bool isAssumedSpurious(NodeId x, NodeId y) const
Returns true if arc is present in observationalBN and absent in causalDAG.
Set< std::string > latentVariablesNames() const
Names of all latent variables.
std::optional< NodeSet > frontDoor(NodeId cause, NodeId effect) const
Find a frontdoor adjustment set (Z) between cause and effect (IDs only).
Bijection< NodeId, std::string > id2name(bool includeLatentVariable=false) const
Bidirectional mapping between node ids and variable names.
Bijection< NodeId, std::string > _ids_names_
Bidirectional mapping between node ids and variable names (observed + latent).
NodeId idFromName(std::string_view name) const
Node id from variable name (observed or latent).
CausalModel & operator=(const CausalModel &other)=default
Copy assignment.
bool existsArc(NodeId x, NodeId y) const
Whether a causal arc x → y exists (by ids) in the causal DAG.
std::string nameFromId(NodeId id) const
Variable name from node id (observed or latent).
NodeSet children(NodeId x) const
Children of a node (by id) in the causal DAG (including latents).
const DiscreteVariable & variable(NodeId id) const
From id to variable (observed only, by id).
BayesNet< GUM_SCALAR > _observationalBN_
The underlying BayesNet representing the observed part of the model.
CausalModel()=delete
Default constructor disabled: a causal model must be built from a BN.
Set< std::string > names() const
All variable names appearing in the causal model (observed + latent).
CausalModel & operator=(CausalModel &&other) noexcept=default
Move assignment.
void assumeNonSpurious(NodeId x, NodeId y)
Mark an arc as non-spurious: present in observationalBN, added to causalDAG.
std::optional< NodeSet > backDoor(NodeId cause, NodeId effect) const
Find a backdoor adjustment set (Z) between cause and effect (IDs only).
void assumeSpurious(NodeId x, NodeId y)
Mark an arc as spurious: present in observationalBN, removed from causalDAG.
NodeSet parents(NodeId x) const
Parents of a node (by id) in the causal DAG (including latents).
const BayesNet< GUM_SCALAR > & observationalBN() const
Observational BN (observed variables only).
Base class for discrete random variable.
The class for generic Hash Tables.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
std::pair< std::string, std::vector< NodeId > > LatentDescriptorIds
LatentDescriptorIds = (latentName, (child1Id, child2Id, ...)).
std::vector< LatentDescriptorIds > LatentDescriptorVector
Collection of latent descriptors (see LatentDescriptorIds).