42#ifndef GUM_CAUSAL_MODEL_H
43#define GUM_CAUSAL_MODEL_H
58 template < GUM_Numeric GUM_SCALAR >
95 template < GUM_Numeric GUM_SCALAR >
190 const std::vector< std::string >& childrenOfLatent,
211 const std::vector< NodeId >& childrenOfLatent,
218 bool existsArc(std::string_view x, std::string_view y)
const;
263 std::optional< NodeSet >
backDoor(std::string_view cause, std::string_view effect)
const;
301 std::optional< NodeSet >
frontDoor(std::string_view cause, std::string_view effect)
const;
322 std::string
toDot()
const;
347 std::string
toDot(
const bool SHOW_LATENT_NAMES,
348 const char* NODE_BG =
nullptr,
349 const char* NODE_FG =
nullptr,
350 const char* EDGE_COL =
nullptr)
const;
432#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.
Class representing a Bayesian network.
A causal model pairing a causal DAG with an optional observational BayesNet.
DAG causalDAG() const
Causal DAG (observed + latent variables), with node names set.
DAG _observedDAG_
Frozen copy of the observed DAG (never mutated after construction); names are set on it directly (set...
std::string _toDot_(const dot::CausalDotStyle &style, const dot::DotOptions &options) const
the dot of the causal DAG, with a look and options
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.
NodeProperty< NodeId > connectedComponents() const
Weakly connected components of the causal DAG.
bool hasObservationalBN() const noexcept
Whether this model was built from a BayesNet (CPTs available).
NodeSet latentVariablesIds() const
Node ids of all latent variables.
DAG _causalDAG_
The underlying DAG representing the causal structure (observed + latent).
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 (latents only).
NodeId idFromName(std::string_view name) const
Node id from variable name (observed or latent).
CausalModel & operator=(const CausalModel &other)=default
Copy assignment.
std::string toDot() const
DOT representation of the causal DAG (observed + latent), with the look of the configuration.
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).
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).
std::optional< BayesNet< GUM_SCALAR > > _observationalBN_
The observed Bayesian network, when the model was built with CPTs. Absent when built from a plain DAG...
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 options given to a toDot(const DotOptions&).
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
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, ...)).
template class GUM_PUBLIC_CM CausalModel< double >
std::vector< LatentDescriptorIds > LatentDescriptorVector
Collection of latent descriptors (see LatentDescriptorIds).
The style of a causal model (section causal): nodeBgColor and nodeFgColor are the ones of the observe...