aGrUM  0.14.2
DAGmodel_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
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  ***************************************************************************/
28 #include <agrum/core/math/math.h>
30 
31 namespace gum {
32 
33  INLINE
34  const std::string& DAGmodel::property(const std::string& name) const {
35  try {
36  return __properties()[name];
37  } catch (NotFound&) {
38  std::string msg = "The following property does not exists: ";
39  GUM_ERROR(NotFound, msg + name);
40  }
41  }
42 
43  INLINE
44  const std::string&
45  DAGmodel::propertyWithDefault(const std::string& name,
46  const std::string& byDefault) const {
47  try {
48  return __properties()[name];
49  } catch (NotFound&) { return byDefault; }
50  }
51 
52  INLINE
53  void DAGmodel::setProperty(const std::string& name, const std::string& value) {
54  try {
55  __properties()[name] = value;
56  } catch (NotFound&) { __properties().insert(name, value); }
57  }
58 
59  INLINE
60  const DAG& DAGmodel::dag() const { return _dag; }
61 
62  INLINE
64  if (__propertiesMap == nullptr) {
66  }
67 
68  return *__propertiesMap;
69  }
70 
71  INLINE
72  double DAGmodel::log10DomainSize() const {
73  double dSize = 0.0;
74 
75  for (const auto node : nodes()) {
76  dSize += std::log10(variable(node).domainSize());
77  }
78 
79  return dSize;
80  }
81 
82  INLINE
84  Instantiation I;
85 
86  for (const auto node : dag())
87  I << variable(node);
88 
89  return I;
90  }
91 
92  INLINE
93  Size DAGmodel::size() const { return dag().size(); }
94 
95  INLINE
96  bool DAGmodel::empty() const { return size() == 0; }
97 
98  INLINE
99  Size DAGmodel::sizeArcs() const { return _dag.sizeArcs(); }
100 
101  INLINE const ArcSet& DAGmodel::arcs() const { return _dag.arcs(); }
102 
103  INLINE const NodeSet& DAGmodel::parents(const NodeId id) const {
104  return _dag.parents(id);
105  }
106 
107 
108  INLINE const NodeSet& DAGmodel::children(const NodeId id) const {
109  return _dag.children(id);
110  }
111 
112  INLINE const NodeGraphPart& DAGmodel::nodes() const {
113  return (NodeGraphPart&)_dag;
114  }
115 } /* namespace gum */
Useful macros for maths.
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:101
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:108
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
Size size() const
alias for sizeNodes
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
Definition: DAGmodel.h:212
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 std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:34
Class representing probabilistic DAG model.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this DAGModel.
Definition: DAGmodel_inl.h:53
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
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 NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
bool empty() const
Retursn true if this Directed Graphical Model is empty.
Definition: DAGmodel_inl.h:96
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
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
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
double log10DomainSize() const
Definition: DAGmodel_inl.h:72
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
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
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52