aGrUM  0.18.1
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
 Returns a constant reference to the dag of this Bayes Net. 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...
 
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...
 
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 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
 check if X and Y are independent given Z More...
 
bool isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Zanmes) 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
 Retursn true if this Directed Graphical Model is empty. More...
 
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model. 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 30 of file DAGmodel.cpp.

30  : mutableMoralGraph__(nullptr) {
31  GUM_CONSTRUCTOR(DAGmodel);
32  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:30
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221

◆ ~DAGmodel()

gum::DAGmodel::~DAGmodel ( )
virtual

Destructor.

Definition at line 39 of file DAGmodel.cpp.

References mutableMoralGraph__.

39  {
40  GUM_DESTRUCTOR(DAGmodel);
42  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:30
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221

◆ DAGmodel() [2/2]

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

Copy constructor.

Do nothing.

Definition at line 34 of file DAGmodel.cpp.

34  :
35  dag_(from.dag_), mutableMoralGraph__(nullptr) {
36  GUM_CONS_CPY(DAGmodel);
37  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:30
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213

Member Function Documentation

◆ ancestors() [1/2]

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 145 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::begin(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), gum::Set< Key, Alloc >::insert(), and parents().

Referenced by ancestors().

145  {
146  NodeSet res;
147  NodeSet tmp;
148  for (auto next: parents(id))
149  tmp.insert(next);
150 
151  while (!tmp.empty()) {
152  auto current = *(tmp.begin());
153  tmp.erase(current);
154  res.insert(current);
155  for (auto next: parents(current)) {
156  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
157  }
158  }
159  return res;
160  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:55
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ancestors() [2/2]

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 162 of file DAGmodel.cpp.

References ancestors(), and idFromName().

162  {
163  return ancestors(idFromName(name));
164  }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Definition: DAGmodel.cpp:145
+ 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 44 of file DAGmodel_inl.h.

References gum::ArcGraphPart::arcs(), and dag_.

Referenced by gum::EssentialGraph::buildEssentialGraph__(), gum::MarkovBlanket::hasSameStructure(), hasSameStructure(), moralGraph__(), and gum::BayesNetFragment< GUM_SCALAR >::toBN().

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

◆ children() [1/2]

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 63 of file DAGmodel_inl.h.

References gum::ArcGraphPart::children(), and dag_.

Referenced by gum::MarkovBlanket::buildMarkovBlanket__(), descendants(), gum::MarkovBlanket::MarkovBlanket(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

63  {
64  return dag_.children(id);
65  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ children() [2/2]

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 66 of file DAGmodel_inl.h.

References gum::ArcGraphPart::children(), dag_, and idFromName().

66  {
67  return dag_.children(idFromName(name));
68  }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ 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 85 of file graphicalModel_inl.h.

References gum::GraphicalModel::nodes(), and gum::GraphicalModel::variable().

85  {
86  Instantiation I;
87 
88  for (const auto node: nodes())
89  I << variable(node);
90 
91  return I;
92  }
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.
+ Here is the call graph for this function:

◆ dag()

◆ descendants() [1/2]

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 124 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::begin(), children(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), and gum::Set< Key, Alloc >::insert().

Referenced by descendants().

124  {
125  NodeSet res;
126  NodeSet tmp;
127  for (auto next: children(id))
128  tmp.insert(next);
129 
130  while (!tmp.empty()) {
131  auto current = *(tmp.begin());
132  tmp.erase(current);
133  res.insert(current);
134  for (auto next: children(current)) {
135  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
136  }
137  }
138  return res;
139  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:63
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ descendants() [2/2]

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 141 of file DAGmodel.cpp.

References descendants(), and idFromName().

141  {
142  return descendants(idFromName(name));
143  }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
NodeSet descendants(const NodeId id) const
returns the set of nodes with directed path outgoing from a given node
Definition: DAGmodel.cpp:124
+ Here is the call graph for this function:

◆ empty()

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

Retursn true if this Directed Graphical Model is empty.

Definition at line 95 of file graphicalModel_inl.h.

References gum::GraphicalModel::size().

95 { return size() == 0; }
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.
+ Here is the call graph for this function:

◆ 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 46 of file DAGmodel_inl.h.

References dag_, and gum::ArcGraphPart::existsArc().

Referenced by existsArc(), gum::BayesNetFragment< GUM_SCALAR >::toDot(), and gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted().

46  {
47  return dag_.existsArc(tail, head);
48  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
+ Here is the call graph for this function:
+ Here is the caller 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 50 of file DAGmodel_inl.h.

References existsArc(), and idFromName().

51  {
52  return existsArc(idFromName(nametail), idFromName(namehead));
53  }
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:46
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 102 of file DAGmodel.cpp.

References arcs(), gum::Set< Key, Alloc >::exists(), idFromName(), nodes(), size(), sizeArcs(), and variable().

102  {
103  if (this == &other) return true;
104 
105  if (size() != other.size()) return false;
106 
107  if (sizeArcs() != other.sizeArcs()) return false;
108 
109  for (const auto& nid: nodes()) {
110  try {
111  other.idFromName(variable(nid).name());
112  } catch (NotFound) { return false; }
113  }
114 
115  for (const auto& arc: arcs()) {
116  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
117  other.idFromName(variable(arc.head()).name()))))
118  return false;
119  }
120 
121  return true;
122  }
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:44
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:42
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:39
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:70
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::DAGmodel::idFromName ( const std::string &  name) const
pure virtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::GraphicalModel.

Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Referenced by ancestors(), children(), descendants(), existsArc(), gum::MarkovBlanket::hasSameStructure(), hasSameStructure(), isIndependent(), moralizedAncestralGraph(), and parents().

+ Here is the caller graph for this function:

◆ isIndependent() [1/2]

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

check if X and Y are independent given Z

Definition at line 200 of file DAGmodel.cpp.

References moralizedAncestralGraph().

Referenced by isIndependent().

200  {
201  NodeSet cumul{Z};
202  cumul << X << Y;
203  auto g = moralizedAncestralGraph(cumul);
204  for (auto node: Z)
205  g.eraseNode(node);
206  return !g.hasUndirectedPath(X, Y);
207  }
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAGmodel.cpp:166
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIndependent() [2/2]

bool gum::DAGmodel::isIndependent ( const std::string &  Xname,
const std::string &  Yname,
const std::vector< std::string > &  Zanmes 
) 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 209 of file DAGmodel.cpp.

References idFromName(), gum::Set< Key, Alloc >::insert(), and isIndependent().

211  {
212  NodeSet Z;
213  for (const auto& name: Znames)
214  Z.insert(idFromName(name));
215  return isIndependent(idFromName(Xname), idFromName(Yname), Z);
216  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const
check if X and Y are independent given Z
Definition: DAGmodel.cpp:200
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ Here is the call graph for this function:

◆ log10DomainSize()

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

Definition at line 74 of file graphicalModel_inl.h.

References gum::GraphicalModel::nodes(), and gum::GraphicalModel::variable().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toString(), and gum::IMarkovNet< GUM_SCALAR >::toString().

74  {
75  double dSize = 0.0;
76 
77  for (const auto node: nodes()) {
78  dSize += std::log10(variable(node).domainSize());
79  }
80 
81  return dSize;
82  }
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 82 of file DAGmodel.cpp.

References gum::UndiGraph::clear(), moralGraph__(), and mutableMoralGraph__.

Referenced by gum::prm::SVED< GUM_SCALAR >::eliminateNodes__(), gum::prm::SVE< GUM_SCALAR >::eliminateNodes__(), gum::prm::SVED< GUM_SCALAR >::eliminateNodesWithEvidence__(), gum::prm::SVE< GUM_SCALAR >::eliminateNodesWithEvidence__(), gum::prm::SVED< GUM_SCALAR >::initLiftedNodes__(), and gum::prm::SVE< GUM_SCALAR >::initLiftedNodes__().

82  {
83  if (clear
84  || (mutableMoralGraph__ == nullptr)) { // we have to call moralGraph_
85  if (mutableMoralGraph__ == nullptr) {
86  mutableMoralGraph__ = new UndiGraph();
87  } else {
88  // clear is True ,__mutableMoralGraph exists
90  }
91 
92  moralGraph__();
93  }
94 
95  return *mutableMoralGraph__;
96  }
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:47
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221
void moralGraph__() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:44
+ Here is the call graph for this function:
+ Here is the caller 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

Definition at line 44 of file DAGmodel.cpp.

References gum::UndiGraph::addEdge(), arcs(), dag(), mutableMoralGraph__, nodes(), parents(), and gum::NodeGraphPart::populateNodes().

Referenced by moralGraph().

44  {
46  // transform the arcs into edges
47 
48  for (const auto& arc: arcs())
49  mutableMoralGraph__->addEdge(arc.first(), arc.second());
50 
51  //}
52 
53  // marry the parents
54  for (const auto node: nodes()) {
55  const auto& par = parents(node);
56 
57  for (auto it1 = par.begin(); it1 != par.end(); ++it1) {
58  auto it2 = it1;
59 
60  for (++it2; it2 != par.end(); ++it2) {
61  // will automatically check if this edge already exists
62  mutableMoralGraph__->addEdge(*it1, *it2);
63  }
64  }
65  }
66  }
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:44
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:55
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:35
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:70
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moralizedAncestralGraph() [1/2]

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 166 of file DAGmodel.cpp.

References gum::NodeGraphPart::addNodeWithId(), gum::Set< Key, Alloc >::erase(), gum::NodeGraphPart::exists(), and parents().

Referenced by isIndependent(), and moralizedAncestralGraph().

166  {
167  UndiGraph res;
168  NodeSet tmp{nodes};
169 
170  // findings all nodes
171  while (!tmp.empty()) {
172  auto current = *(tmp.begin());
173  tmp.erase(current);
174 
175  res.addNodeWithId(current);
176  for (auto next: parents(current))
177  if (!tmp.contains(next) && !res.exists(next)) tmp.insert(next);
178  }
179 
180  // finding all edges and moralizing
181  for (auto current: res)
182  for (auto father: parents(current)) {
183  res.addEdge(current,
184  father); // addEdge does not complain if edge already exists
185  for (auto other_father: parents(current))
186  if (other_father != father) res.addEdge(father, other_father);
187  }
188 
189  return res;
190  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:55
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moralizedAncestralGraph() [2/2]

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 192 of file DAGmodel.cpp.

References idFromName(), gum::Set< Key, Alloc >::insert(), moralizedAncestralGraph(), and nodes().

193  {
194  NodeSet nodes;
195  for (const auto& name: nodenames)
196  nodes.insert(idFromName(name));
197  return moralizedAncestralGraph(nodes);
198  }
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAGmodel.cpp:166
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:70
+ Here is the call graph for this function:

◆ nodeId()

◆ nodes()

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

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

Implements gum::GraphicalModel.

Definition at line 70 of file DAGmodel_inl.h.

References dag_.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::credal::CredalNet< GUM_SCALAR >::bnCopy__(), gum::build_node(), gum::EssentialGraph::buildEssentialGraph__(), gum::MarkovBlanket::buildMarkovBlanket__(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::AggregatorDecomposition< GUM_SCALAR >::getDecomposedAggregator(), gum::getMaxModality(), hasSameStructure(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), moralGraph__(), moralizedAncestralGraph(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::credal::CredalNet< GUM_SCALAR >::sort_varType__(), gum::BayesNetFragment< GUM_SCALAR >::toBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::credal::CredalNet< GUM_SCALAR >::toString(), gum::ImportanceSampling< GUM_SCALAR >::unsharpenBN_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::verticesSampling__(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

70  {
71  return (NodeGraphPart&)dag_;
72  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213
+ Here is the caller graph for this function:

◆ operator=()

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

Private copy operator.

Definition at line 68 of file DAGmodel.cpp.

References dag_, mutableMoralGraph__, and gum::GraphicalModel::operator=().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::operator=().

68  {
69  if (this != &source) {
71 
72  if (mutableMoralGraph__) {
73  delete mutableMoralGraph__;
74  mutableMoralGraph__ = nullptr;
75  }
76  dag_ = source.dag_;
77  }
78 
79  return *this;
80  }
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:221
GraphicalModel & operator=(const GraphicalModel &source)
Private copy operator.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parents() [1/2]

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 55 of file DAGmodel_inl.h.

References dag_, and gum::ArcGraphPart::parents().

Referenced by ancestors(), gum::MarkovBlanket::buildMarkovBlanket__(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::AggregatorDecomposition< GUM_SCALAR >::decomposeAggregator_(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::installCPT_(), moralGraph__(), moralizedAncestralGraph(), parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

55  {
56  return dag_.parents(id);
57  }
const NodeSet & parents(const 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:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parents() [2/2]

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 59 of file DAGmodel_inl.h.

References idFromName(), and parents().

59  {
60  return parents(idFromName(name));
61  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:55
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ 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 37 of file graphicalModel_inl.h.

References GUM_ERROR, and gum::GraphicalModel::properties__().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::IMarkovNet< GUM_SCALAR >::toDot(), and gum::IMarkovNet< GUM_SCALAR >::toDotAsFactorGraph().

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

◆ 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 57 of file graphicalModel_inl.h.

References gum::GraphicalModel::properties__().

Referenced by gum::build_node().

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

◆ 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 65 of file graphicalModel_inl.h.

References gum::HashTable< Key, Val, Alloc >::insert(), and gum::GraphicalModel::properties__().

Referenced by gum::BayesNet< double >::fastPrototype(), and gum::IMarkovNet< GUM_SCALAR >::IMarkovNet().

66  {
67  try {
68  properties__()[name] = value;
69  } catch (NotFound&) { properties__().insert(name, value); }
70  }
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 39 of file DAGmodel_inl.h.

References dag(), and gum::NodeGraphPart::size().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), gum::MarkovBlanket::hasSameStructure(), hasSameStructure(), gum::credal::CredalNet< GUM_SCALAR >::initCNNets__(), gum::IBayesNet< double >::operator==(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

39 { 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:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeArcs()

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

Returns the number of arcs in this Directed Graphical Model.

Definition at line 42 of file DAGmodel_inl.h.

References dag_, and gum::ArcGraphPart::sizeArcs().

Referenced by gum::MarkovBlanket::hasSameStructure(), hasSameStructure(), and gum::IBayesNet< double >::operator==().

42 { 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:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ topologicalOrder()

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 98 of file DAGmodel.cpp.

References dag(), and gum::DiGraph::topologicalOrder().

Referenced by gum::EssentialGraph::buildEssentialGraph__(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::checkTemporalOrder__(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

98  {
99  return this->dag().topologicalOrder(clear);
100  }
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:91
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variable()

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

Returns a constant reference over a variable given it's node id.

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::GraphicalModel.

Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Referenced by gum::MarkovBlanket::hasSameStructure(), hasSameStructure(), gum::MarkovBlanket::toDot(), and gum::EssentialGraph::toDot().

+ Here is the caller graph for this function:

◆ variableFromName()

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

◆ variableNodeMap()

Member Data Documentation

◆ dag_

◆ mutableMoralGraph__

UndiGraph* gum::DAGmodel::mutableMoralGraph__
mutableprivate

The moral graph of this Directed Graphical Model.

Definition at line 221 of file DAGmodel.h.

Referenced by moralGraph(), moralGraph__(), operator=(), and ~DAGmodel().


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