aGrUM  0.14.2
DAGmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_DAGMODEL_H
28 #define GUM_DAGMODEL_H
29 #include <agrum/agrum.h>
31 
32 #include <agrum/graphs/DAG.h>
33 #include <agrum/graphs/undiGraph.h>
34 
36 
37 namespace gum {
38 
45  class DAGmodel {
46  public:
49 
53  DAGmodel();
54 
58  virtual ~DAGmodel();
59 
63  DAGmodel(const DAGmodel& source);
64 
68 
73  const std::string& property(const std::string& name) const;
74 
79  const std::string& propertyWithDefault(const std::string& name,
80  const std::string& byDefault) const;
81 
85  void setProperty(const std::string& name, const std::string& value);
86 
90 
93  const DAG& dag() const;
94 
100  virtual const VariableNodeMap& variableNodeMap() const = 0;
101 
105  Size size() const;
106 
110  Size sizeArcs() const;
111 
115  bool empty() const;
116 
117  const NodeGraphPart& nodes() const;
118 
123  virtual const DiscreteVariable& variable(NodeId id) const = 0;
124 
129  virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
130 
133  virtual NodeId idFromName(const std::string& name) const = 0;
134 
137  virtual const DiscreteVariable&
138  variableFromName(const std::string& name) const = 0;
139 
141  virtual Instantiation completeInstantiation() const final;
143 
146  const ArcSet& arcs() const;
147 
149 
152  const NodeSet& parents(const NodeId id) const;
153  const NodeSet& parents(const std::string& name) const {
154  return parents(idFromName(name));
155  };
156 
158 
161  const NodeSet& children(const NodeId id) const;
162  const NodeSet& children(const std::string& name) const {
163  return parents(idFromName(name));
164  };
166 
169 
174  const UndiGraph& moralGraph(bool clear = true) const;
175 
181  const Sequence< NodeId >& topologicalOrder(bool clear = true) const;
182 
184 
187  double log10DomainSize() const;
188 
191  bool hasSameStructure(const DAGmodel& other);
192 
193  protected:
197  DAGmodel& operator=(const DAGmodel& source);
198 
201 
202  private:
205  void __moralGraph() const;
206 
209 
213 
219  };
220 } // namespace gum
221 
222 #ifndef GUM_NO_INLINE
224 #endif /* GUM_NO_INLINE */
225 
226 #endif /* GUM_DAGMODEL_H */
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition: DAGmodel.cpp:76
virtual const DiscreteVariable & variableFromName(const std::string &name) const =0
Getter by name.
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:101
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:45
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:108
UndiGraph * __mutableMoralGraph
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:208
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:99
const NodeSet & parents(const std::string &name) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel.h:153
Container used to map discrete variables with nodes.
virtual ~DAGmodel()
Destructor.
Definition: DAGmodel.cpp:42
Base classes for undirected graphs.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Directed Graphical Model.
Header of class VariableNodeMap.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
Definition: DAGmodel.h:212
bool hasSameStructure(const DAGmodel &other)
Definition: DAGmodel.cpp:119
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
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: DAGmodel.cpp:115
const std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:34
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this DAGModel.
Definition: DAGmodel_inl.h:53
void __moralGraph() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:51
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:28
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
Interface-like class encapsulating basic functionalities for a IBayesNet.
Header files of gum::Instantiation.
Class for node sets in graph.
const std::string & propertyWithDefault(const std::string &name, const std::string &byDefault) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:45
virtual Instantiation completeInstantiation() const final
Get an instantiation over all the variables of the model.
Definition: DAGmodel_inl.h:83
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
const UndiGraph & moralGraph(bool clear=true) const
The node&#39;s id are coherent with the variables and nodes of the topology.
Definition: DAGmodel.cpp:99
bool empty() const
Retursn true if this Directed Graphical Model is empty.
Definition: DAGmodel_inl.h:96
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:63
const NodeSet & children(const std::string &name) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel.h:162
Base class for undirected graphs.
Definition: undiGraph.h:106
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
double log10DomainSize() const
Definition: DAGmodel_inl.h:72
Base class for dag.
Definition: DAG.h:99
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Base classes for directed acyclic graphs.
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.