aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::DAGmodel Class Referenceabstract

Virtual base class for PGMs using a DAG. More...

#include <agrum/tools/graphicalModels/DAGmodel.h>

+ Inheritance diagram for gum::DAGmodel:
+ Collaboration diagram for gum::DAGmodel:

Public Member Functions

bool hasSameStructure (const DAGmodel &other)
 
double log10DomainSize () const
 
Constructors / Destructors
 DAGmodel ()
 Default constructor. More...
 
virtual ~DAGmodel ()
 Destructor. More...
 
 DAGmodel (const DAGmodel &source)
 Copy constructor. More...
 
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
virtual Size size () const final
 Returns the number of variables in this Directed Graphical Model. More...
 
Size sizeArcs () const
 Returns the number of arcs in this Directed Graphical Model. More...
 
const NodeGraphPartnodes () const final
 Returns a constant reference to the dag of this Bayes Net. More...
 
bool exists (NodeId node) const final
 Return true if this node exists in this graphical model. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 return true if the arc tail->head exists in the DAGmodel More...
 
bool existsArc (const NodeId tail, const NodeId head) const
 return true if the arc tail->head exists in the DAGmodel More...
 
bool existsArc (const std::string &nametail, const std::string &namehead) const
 return true if the arc tail->head exists in the DAGmodel More...
 
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet parents (const NodeSet &ids) const
 returns the parents of a set of nodes More...
 
NodeSet parents (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet family (const NodeId id) const
 returns the parents of a node and the node More...
 
NodeSet family (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
const NodeSetchildren (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet children (const NodeSet &ids) const
 returns the children of a set of nodes More...
 
NodeSet children (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet descendants (const NodeId id) const
 returns the set of nodes with directed path outgoing from a given node More...
 
NodeSet descendants (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet ancestors (const NodeId id) const
 returns the set of nodes with directed path ingoing to a given node More...
 
NodeSet ancestors (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
Graphical methods
UndiGraph moralizedAncestralGraph (const NodeSet &nodes) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
UndiGraph moralizedAncestralGraph (const std::vector< std::string > &nodenames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
bool isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final
 check if node X and node Y are independent given nodes Z More...
 
bool isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const final
 check if nodes X and nodes Y are independent given nodes Z More...
 
bool isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
bool isIndependent (const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
const UndiGraphmoralGraph (bool clear=true) const
 The node's id are coherent with the variables and nodes of the topology. More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this GraphicalModel. More...
 
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel. More...
 
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this GraphicalModel. More...
 
Variable manipulation methods.
virtual const VariableNodeMapvariableNodeMap () const =0
 Returns a constant reference to the VariableNodeMap of this Graphical Model. More...
 
virtual bool empty () const
 Return true if this graphical model is empty. More...
 
bool exists (const std::string &name) const
 Return true if this graphical model is empty. More...
 
std::vector< std::string > names (const std::vector< NodeId > &ids) const
 transform a vector of NodeId in a vector of names More...
 
std::vector< std::string > names (const NodeSet &ids) const
 transform a NodeSet in a vector of names More...
 
std::vector< NodeIdids (const std::vector< std::string > &names) const
 transform a vector of names into a vector of nodeId More...
 
NodeSet nodeset (const std::vector< std::string > &names) const
 transform a vector of names into a NodeSet More...
 
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model. More...
 
virtual const DiscreteVariablevariable (NodeId id) const =0
 Returns a constant reference over a variable given it's node id. More...
 
virtual NodeId nodeId (const DiscreteVariable &var) const =0
 Return id node src discrete var pointer. More...
 
virtual NodeId idFromName (const std::string &name) const =0
 Getter by name. More...
 
virtual const DiscreteVariablevariableFromName (const std::string &name) const =0
 Getter by name. More...
 

Protected Attributes

DAG dag_
 The DAG of this Directed Graphical Model. More...
 

Protected Member Functions

DAGmodeloperator= (const DAGmodel &source)
 Private copy operator. More...
 

Detailed Description

Virtual base class for PGMs using a DAG.

Definition at line 47 of file DAGmodel.h.

Constructor & Destructor Documentation

◆ DAGmodel() [1/2]

gum::DAGmodel::DAGmodel ( )

Default constructor.

Definition at line 29 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

29  : mutableMoralGraph__(nullptr) {
30  GUM_CONSTRUCTOR(DAGmodel);
31  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:29
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
+ Here is the call graph for this function:

◆ ~DAGmodel()

gum::DAGmodel::~DAGmodel ( )
virtual

Destructor.

Definition at line 38 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

38  {
39  GUM_DESTRUCTOR(DAGmodel);
40  if (mutableMoralGraph__ != nullptr) { delete mutableMoralGraph__; }
41  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:29
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
+ Here is the call graph for this function:

◆ DAGmodel() [2/2]

gum::DAGmodel::DAGmodel ( const DAGmodel source)

Copy constructor.

Do nothing.

Definition at line 33 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

33  :
34  dag_(from.dag_), mutableMoralGraph__(nullptr) {
35  GUM_CONS_CPY(DAGmodel);
36  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:29
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

Member Function Documentation

◆ ancestors() [1/2]

INLINE NodeSet gum::DAGmodel::ancestors ( const NodeId  id) const

returns the set of nodes with directed path ingoing to a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is ingoing to the given node.

Parameters
idthe node which is the head of a directed path with the returned nodes
namethe name of the node which is the head of a directed path with the returned nodes

Definition at line 112 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

112  {
113  return dag().ancestors(id);
114  }
NodeSet ancestors(NodeId id) const
returns the set of nodes with directed path ingoing to a given node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ ancestors() [2/2]

INLINE NodeSet gum::DAGmodel::ancestors ( const std::string &  name) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 116 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

116  {
117  return ancestors(idFromName(name));
118  }
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Definition: DAGmodel_inl.h:112
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ arcs()

INLINE const ArcSet & gum::DAGmodel::arcs ( ) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 43 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

43 { return dag_.arcs(); }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:

◆ children() [1/4]

INLINE const NodeSet & gum::DAGmodel::children ( const NodeId  id) const

returns the set of nodes with arc outgoing from a given node

Note that the set of nodes returned may be empty if no node is outgoing from the given node.

Parameters
idthe node which is the tail of an arc with the returned nodes
namethe name of the node which is the tail of an arc with the returned nodes

Definition at line 70 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

70  {
71  return dag_.children(id);
72  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ children() [2/4]

INLINE const NodeSet & gum::DAGmodel::children ( const std::string &  name) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 73 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

73  {
74  return dag_.children(idFromName(name));
75  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ children() [3/4]

INLINE NodeSet gum::DAGmodel::children ( const NodeSet ids) const

returns the children of a set of nodes

Definition at line 77 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

77  {
78  return dag_.children(ids);
79  }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ children() [4/4]

INLINE NodeSet gum::DAGmodel::children ( const std::vector< std::string > &  names) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 82 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

82  {
83  return children(nodeset(names));
84  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:70
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
+ Here is the call graph for this function:

◆ completeInstantiation()

INLINE Instantiation gum::GraphicalModel::completeInstantiation ( ) const
inherited

Get an instantiation over all the variables of the model.

Definition at line 86 of file graphicalModel_inl.h.

86  {
87  Instantiation I;
88 
89  for (const auto node: nodes())
90  I << variable(node);
91 
92  return I;
93  }
virtual const NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.

◆ dag()

INLINE const DAG & gum::DAGmodel::dag ( ) const

Returns a constant reference to the dag of this Bayes Net.

Definition at line 35 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

35 { return dag_; }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ descendants() [1/2]

INLINE NodeSet gum::DAGmodel::descendants ( const NodeId  id) const

returns the set of nodes with directed path outgoing from a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of a directed path with the returned nodes
namethe name of the node which is the tail of a directed path with the returned nodes

Definition at line 104 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

104  {
105  return dag().descendants(id);
106  }
NodeSet descendants(NodeId id) const
returns the set of nodes with directed path outgoing from a given node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ descendants() [2/2]

INLINE NodeSet gum::DAGmodel::descendants ( const std::string &  name) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 108 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

108  {
109  return descendants(idFromName(name));
110  }
NodeSet descendants(const NodeId id) const
returns the set of nodes with directed path outgoing from a given node
Definition: DAGmodel_inl.h:104
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ empty()

INLINE bool gum::GraphicalModel::empty ( ) const
virtualinherited

Return true if this graphical model is empty.

Definition at line 96 of file graphicalModel_inl.h.

96 { return size() == 0; }
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.

◆ exists() [1/2]

INLINE bool gum::DAGmodel::exists ( NodeId  node) const
finalvirtual

Return true if this node exists in this graphical model.

Implements gum::GraphicalModel.

Definition at line 94 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

94 { return dag_.exists(node); }
bool exists(const NodeId id) const
alias for existsNode
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ exists() [2/2]

bool gum::GraphicalModel::exists ( const std::string &  name) const
inlineinherited

Return true if this graphical model is empty.

Definition at line 112 of file graphicalModel.h.

112  {
113  return exists(idFromName(name));
114  };
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.

◆ existsArc() [1/2]

INLINE bool gum::DAGmodel::existsArc ( const NodeId  tail,
const NodeId  head 
) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 45 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

45  {
46  return dag_.existsArc(tail, head);
47  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
+ Here is the call graph for this function:

◆ existsArc() [2/2]

INLINE bool gum::DAGmodel::existsArc ( const std::string &  nametail,
const std::string &  namehead 
) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 49 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

50  {
51  return existsArc(idFromName(nametail), idFromName(namehead));
52  }
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:45
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ family() [1/2]

INLINE NodeSet gum::DAGmodel::family ( const NodeId  id) const

returns the parents of a node and the node

Note that the set of nodes returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node which is the head of an arc with the returned nodes
namethe name of the node the node which is the head of an arc with the returned nodes

Definition at line 62 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

62  {
63  return dag_.family(id);
64  }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ family() [2/2]

INLINE NodeSet gum::DAGmodel::family ( const std::string &  name) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 66 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

66  {
67  return dag_.family(idFromName(name));
68  }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ hasSameStructure()

bool gum::DAGmodel::hasSameStructure ( const DAGmodel other)
Returns
true if all the named node are the same and all the named arcs are the same

Definition at line 74 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

74  {
75  if (this == &other) return true;
76 
77  if (size() != other.size()) return false;
78 
79  if (sizeArcs() != other.sizeArcs()) return false;
80 
81  for (const auto& nid: nodes()) {
82  try {
83  other.idFromName(variable(nid).name());
84  } catch (NotFound) { return false; }
85  }
86 
87  for (const auto& arc: arcs()) {
88  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
89  other.idFromName(variable(arc.head()).name()))))
90  return false;
91  }
92 
93  return true;
94  }
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:43
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:96
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:41
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
+ Here is the call graph for this function:

◆ idFromName()

virtual NodeId gum::GraphicalModel::idFromName ( const std::string &  name) const
pure virtualinherited

◆ ids()

INLINE std::vector< NodeId > gum::GraphicalModel::ids ( const std::vector< std::string > &  names) const
inherited

transform a vector of names into a vector of nodeId

Returns
the vector of names

Definition at line 122 of file graphicalModel_inl.h.

122  {
123  std::vector< NodeId > res;
124  const VariableNodeMap& v = variableNodeMap();
125  std::transform(names.cbegin(),
126  names.cend(),
127  std::back_inserter(res),
128  [v](const std::string& n) { return v.idFromName(n); });
129  return res;
130  }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

◆ isIndependent() [1/4]

INLINE bool gum::DAGmodel::isIndependent ( NodeId  X,
NodeId  Y,
const NodeSet Z 
) const
finalvirtual

check if node X and node Y are independent given nodes Z

Implements gum::GraphicalModel.

Definition at line 131 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

131  {
132  return dag().dSeparation(X, Y, Z);
133  }
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation) ...
Definition: DAG.cpp:102
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ isIndependent() [2/4]

INLINE bool gum::DAGmodel::isIndependent ( const NodeSet X,
const NodeSet Y,
const NodeSet Z 
) const
finalvirtual

check if nodes X and nodes Y are independent given nodes Z

Implements gum::GraphicalModel.

Definition at line 135 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

137  {
138  return dag().dSeparation(X, Y, Z);
139  }
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation) ...
Definition: DAG.cpp:102
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ isIndependent() [3/4]

bool gum::DAGmodel::isIndependent ( const std::string &  Xname,
const std::string &  Yname,
const std::vector< std::string > &  Znames 
) const
inline

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 188 of file DAGmodel.h.

190  {
191  return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
192  };
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z
Definition: DAGmodel_inl.h:131

◆ isIndependent() [4/4]

bool gum::DAGmodel::isIndependent ( const std::vector< std::string > &  Xnames,
const std::vector< std::string > &  Ynames,
const std::vector< std::string > &  Znames 
) const
inline

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 194 of file DAGmodel.h.

196  {
197  return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
198  };
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z
Definition: DAGmodel_inl.h:131

◆ log10DomainSize()

INLINE double gum::GraphicalModel::log10DomainSize ( ) const
inherited

Definition at line 75 of file graphicalModel_inl.h.

75  {
76  double dSize = 0.0;
77 
78  for (const auto node: nodes()) {
79  dSize += std::log10(variable(node).domainSize());
80  }
81 
82  return dSize;
83  }
virtual const NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.

◆ moralGraph()

const UndiGraph & gum::DAGmodel::moralGraph ( bool  clear = true) const

The node's id are coherent with the variables and nodes of the topology.

Parameters
clearIf false returns the previously created moral graph.

Definition at line 58 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

58  {
59  if (clear
61  == nullptr)) { // we have to call dag().moralGraph()
62  if (mutableMoralGraph__ == nullptr) {
63  mutableMoralGraph__ = new UndiGraph();
64  } else {
65  // clear is True ,__mutableMoralGraph exists
67  }
69  }
70 
71  return *mutableMoralGraph__;
72  }
void clear() override
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:46
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
Definition: DAG.cpp:52
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ moralGraph__()

void gum::DAGmodel::moralGraph__ ( ) const
private

Returns the moral graph of this DAGModel.

Warning
mutableMoralGraph__ is assumed to be valid and empty

◆ moralizedAncestralGraph() [1/2]

INLINE UndiGraph gum::DAGmodel::moralizedAncestralGraph ( const NodeSet nodes) const

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 127 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

127  {
129  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:96
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAG.cpp:76
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ moralizedAncestralGraph() [2/2]

INLINE UndiGraph gum::DAGmodel::moralizedAncestralGraph ( const std::vector< std::string > &  nodenames) const

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 121 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

122  {
123  return moralizedAncestralGraph(nodeset(nodenames));
124  }
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAGmodel_inl.h:127
+ Here is the call graph for this function:

◆ names() [1/2]

INLINE std::vector< std::string > gum::GraphicalModel::names ( const std::vector< NodeId > &  ids) const
inherited

transform a vector of NodeId in a vector of names

Returns
the vector of names

Definition at line 100 of file graphicalModel_inl.h.

100  {
101  std::vector< std::string > res;
102  const VariableNodeMap& v = variableNodeMap();
103  std::transform(ids.cbegin(),
104  ids.cend(),
105  std::back_inserter(res),
106  [v](NodeId n) { return v[n].name(); });
107  return res;
108  }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ names() [2/2]

INLINE std::vector< std::string > gum::GraphicalModel::names ( const NodeSet ids) const
inherited

transform a NodeSet in a vector of names

Returns
the vector of names

Definition at line 111 of file graphicalModel_inl.h.

111  {
112  const VariableNodeMap& v = variableNodeMap();
113  std::vector< std::string > res;
114  for (auto n: ids) {
115  res.push_back(v.name(n));
116  }
117  return res;
118  }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

◆ nodeId()

◆ nodes()

INLINE const NodeGraphPart & gum::DAGmodel::nodes ( ) const
finalvirtual

Returns a constant reference to the dag of this Bayes Net.

Implements gum::GraphicalModel.

Definition at line 96 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

96  {
97  return (NodeGraphPart&)dag_;
98  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ nodeset()

NodeSet gum::GraphicalModel::nodeset ( const std::vector< std::string > &  names) const
inherited

transform a vector of names into a NodeSet

Returns
NodeSet

Definition at line 63 of file graphicalModel.cpp.

References gum::Set< Key, Alloc >::emplace().

63  {
64  NodeSet res;
65  for (const auto& name: names) {
66  res.insert(idFromName(name));
67  }
68  return res;
69  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ operator=()

DAGmodel & gum::DAGmodel::operator= ( const DAGmodel source)
protected

Private copy operator.

Definition at line 44 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

44  {
45  if (this != &source) {
47 
48  if (mutableMoralGraph__) {
49  delete mutableMoralGraph__;
50  mutableMoralGraph__ = nullptr;
51  }
52  dag_ = source.dag_;
53  }
54 
55  return *this;
56  }
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
GraphicalModel & operator=(const GraphicalModel &source)
Private copy operator.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ parents() [1/4]

INLINE const NodeSet & gum::DAGmodel::parents ( const NodeId  id) const

returns the set of nodes with arc ingoing to a given node

Note that the set of nodes returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node which is the head of an arc with the returned nodes
namethe name of the node the node which is the head of an arc with the returned nodes

Definition at line 54 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

54  {
55  return dag_.parents(id);
56  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ parents() [2/4]

INLINE const NodeSet & gum::DAGmodel::parents ( const std::string &  name) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 58 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

58  {
59  return parents(idFromName(name));
60  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:54
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ parents() [3/4]

INLINE NodeSet gum::DAGmodel::parents ( const NodeSet ids) const

returns the parents of a set of nodes

Definition at line 86 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

86  {
87  return dag_.children(ids);
88  }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ parents() [4/4]

INLINE NodeSet gum::DAGmodel::parents ( const std::vector< std::string > &  names) const

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 90 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

90  {
91  return parents(nodeset(names));
92  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:54
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
+ Here is the call graph for this function:

◆ property()

INLINE const std::string & gum::GraphicalModel::property ( const std::string &  name) const
inherited

Return the value of the property name of this GraphicalModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 38 of file graphicalModel_inl.h.

38  {
39  try {
40  return properties__()[name];
41  } catch (NotFound&) {
42  std::string msg = "The following property does not exists: ";
43  GUM_ERROR(NotFound, msg + name);
44  }
45  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
HashTable< std::string, std::string > & properties__() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...

◆ propertyWithDefault()

INLINE const std::string & gum::GraphicalModel::propertyWithDefault ( const std::string &  name,
const std::string &  byDefault 
) const
inherited

Return the value of the property name of this GraphicalModel.

return byDefault if the property name is not found

Definition at line 58 of file graphicalModel_inl.h.

59  {
60  try {
61  return properties__()[name];
62  } catch (NotFound&) { return byDefault; }
63  }
HashTable< std::string, std::string > & properties__() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...

◆ setProperty()

INLINE void gum::GraphicalModel::setProperty ( const std::string &  name,
const std::string &  value 
)
inherited

Add or change a property of this GraphicalModel.

Definition at line 66 of file graphicalModel_inl.h.

67  {
68  try {
69  properties__()[name] = value;
70  } catch (NotFound&) { properties__().insert(name, value); }
71  }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
HashTable< std::string, std::string > & properties__() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...

◆ size()

INLINE Size gum::DAGmodel::size ( ) const
finalvirtual

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 38 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

38 { return dag().size(); }
Size size() const
alias for sizeNodes
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ sizeArcs()

INLINE Size gum::DAGmodel::sizeArcs ( ) const

Returns the number of arcs in this Directed Graphical Model.

Definition at line 41 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

41 { return dag_.sizeArcs(); }
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ Here is the call graph for this function:

◆ topologicalOrder()

INLINE const Sequence< NodeId > & gum::DAGmodel::topologicalOrder ( bool  clear = true) const

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.

Definition at line 100 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

100  {
101  return dag().topologicalOrder(clear);
102  }
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:90
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ variable()

virtual const DiscreteVariable& gum::GraphicalModel::variable ( NodeId  id) const
pure virtualinherited

◆ variableFromName()

virtual const DiscreteVariable& gum::GraphicalModel::variableFromName ( const std::string &  name) const
pure virtualinherited

◆ variableNodeMap()

Member Data Documentation

◆ dag_

DAG gum::DAGmodel::dag_
protected

The DAG of this Directed Graphical Model.

Definition at line 225 of file DAGmodel.h.

◆ mutableMoralGraph__

UndiGraph* gum::DAGmodel::mutableMoralGraph__
mutableprivate

The moral graph of this Directed Graphical Model.

Definition at line 233 of file DAGmodel.h.


The documentation for this class was generated from the following files: