aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
gum::IMarkovNet< GUM_SCALAR > Class Template Referenceabstract

Class representing the minimal interface for Bayesian Network. More...

#include <agrum/BN/IMarkovNet.h>

+ Inheritance diagram for gum::IMarkovNet< GUM_SCALAR >:
+ Collaboration diagram for gum::IMarkovNet< GUM_SCALAR >:

Public Member Functions

bool operator== (const IMarkovNet< GUM_SCALAR > &from) const
 This operator compares 2 BNs ! More...
 
bool operator!= (const IMarkovNet< GUM_SCALAR > &from) const
 
Size dim () const
 Returns the dimension (the number of free parameters) in this bayes net. More...
 
Size maxVarDomainSize () const
 
GUM_SCALAR minParam () const
 
GUM_SCALAR maxParam () const
 
GUM_SCALAR minNonZeroParam () const
 
GUM_SCALAR maxNonOneParam () const
 
virtual std::string toDot () const
 
std::string toString () const
 
bool hasSameStructure (const UGmodel &other)
 
double log10DomainSize () const
 
Constructors / Destructors
 IMarkovNet ()
 Default constructor. More...
 
 IMarkovNet (std::string name)
 Default constructor. More...
 
virtual ~IMarkovNet ()
 Destructor. More...
 
 IMarkovNet (const IMarkovNet< GUM_SCALAR > &source)
 Copy constructor. More...
 
IMarkovNet< GUM_SCALAR > & operator= (const IMarkovNet< GUM_SCALAR > &source)
 Copy operator. More...
 
Pure Virtual methods
virtual const Potential< GUM_SCALAR > & factor (const NodeSet &varIds) const =0
 Returns the factor of a set of variable. More...
 
virtual const FactorTable< GUM_SCALAR > & factors () const =0
 Returns the set of factors as a IMarkovNet::FactorTable. More...
 
virtual const VariableNodeMapvariableNodeMap () const =0
 Returns a constant reference to the VariableNodeMap of thisBN. 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 from 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...
 
Variable manipulation methods.
const UndiGraphgraph () 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 sizeEdges () 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...
 
Edge manipulation methods.
const EdgeSetedges () const
 returns the neighbours of a node as set of nodes More...
 
const NodeSetneighbours (const NodeId id) const
 returns the neighbours of a node as set of nodes More...
 
const NodeSetneighbours (const std::string &name) const
 returns the neighbours of a node as set of nodes 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 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

UndiGraph _graph
 The DAG of this Directed Graphical Model. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::IMarkovNet< GUM_SCALAR >

Class representing the minimal interface for Bayesian Network.

This class is used as a base class for different versions of Bayesian Networks. No data (except the dag herited from DAGmodel are included in this class. Many algorithms (inference for instance) may use this class when a simple BN is needed.

Definition at line 64 of file IMarkovNet.h.

Constructor & Destructor Documentation

◆ IMarkovNet() [1/3]

template<typename GUM_SCALAR >
INLINE gum::IMarkovNet< GUM_SCALAR >::IMarkovNet ( )

Default constructor.

Definition at line 40 of file IMarkovNet_tpl.h.

40  : UGmodel() {
41  GUM_CONSTRUCTOR(IMarkovNet);
42  }
UGmodel()
Default constructor.
Definition: UGmodel.cpp:30
IMarkovNet()
Default constructor.

◆ IMarkovNet() [2/3]

template<typename GUM_SCALAR >
INLINE gum::IMarkovNet< GUM_SCALAR >::IMarkovNet ( std::string  name)
explicit

Default constructor.

Definition at line 45 of file IMarkovNet_tpl.h.

References gum::GraphicalModel::setProperty().

45  : UGmodel() {
46  GUM_CONSTRUCTOR(IMarkovNet);
47  this->setProperty("name", name);
48  }
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this GraphicalModel.
UGmodel()
Default constructor.
Definition: UGmodel.cpp:30
IMarkovNet()
Default constructor.
+ Here is the call graph for this function:

◆ ~IMarkovNet()

template<typename GUM_SCALAR >
gum::IMarkovNet< GUM_SCALAR >::~IMarkovNet ( )
virtual

Destructor.

Definition at line 65 of file IMarkovNet_tpl.h.

65  {
66  GUM_DESTRUCTOR(IMarkovNet);
67  }
IMarkovNet()
Default constructor.

◆ IMarkovNet() [3/3]

template<typename GUM_SCALAR >
gum::IMarkovNet< GUM_SCALAR >::IMarkovNet ( const IMarkovNet< GUM_SCALAR > &  source)

Copy constructor.

Definition at line 51 of file IMarkovNet_tpl.h.

51  :
52  UGmodel(source) {
53  GUM_CONS_CPY(IMarkovNet);
54  }
UGmodel()
Default constructor.
Definition: UGmodel.cpp:30
IMarkovNet()
Default constructor.

Member Function Documentation

◆ 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:

◆ dim()

template<typename GUM_SCALAR >
Size gum::IMarkovNet< GUM_SCALAR >::dim ( ) const

Returns the dimension (the number of free parameters) in this bayes net.

\( dim(G)=\sum_{i \in nodes} ((r_i-1)\cdot q_i) \) where \( r_i \) is the number of instantiations of node \( i \) and \( q_i \) is the number of instantiations of its parents.

Definition at line 70 of file IMarkovNet_tpl.h.

References gum::IMarkovNet< GUM_SCALAR >::factors().

70  {
71  Size res = 0;
72  for (auto f: factors()) {
73  res += f.second->domainSize();
74  }
75  return res;
76  }
virtual const FactorTable< GUM_SCALAR > & factors() const =0
Returns the set of factors as a IMarkovNet::FactorTable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:

◆ edges()

INLINE const EdgeSet & gum::UGmodel::edges ( ) const
inherited

returns the neighbours of a node as set of nodes

Note that the set of nodes returned may be empty if no edge within the EdgeGraphPart contains the given node.

Parameters
idthe node toward which the edge returned are pointing

Definition at line 44 of file UGmodel_inl.h.

References gum::UGmodel::_graph, and gum::EdgeGraphPart::edges().

Referenced by gum::UGmodel::hasSameStructure().

44 { return _graph.edges(); }
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
+ Here is the call graph for this function:
+ Here is the caller 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:

◆ factor()

template<typename GUM_SCALAR>
virtual const Potential< GUM_SCALAR >& gum::IMarkovNet< GUM_SCALAR >::factor ( const NodeSet varIds) const
pure virtual

Returns the factor of a set of variable.

Exceptions
NotFoundIf no variable's id matches varId.

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

+ Here is the caller graph for this function:

◆ factors()

template<typename GUM_SCALAR>
virtual const FactorTable< GUM_SCALAR >& gum::IMarkovNet< GUM_SCALAR >::factors ( ) const
pure virtual

Returns the set of factors as a IMarkovNet::FactorTable.

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

+ Here is the caller graph for this function:

◆ graph()

INLINE const UndiGraph & gum::UGmodel::graph ( ) const
inherited

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

Definition at line 36 of file UGmodel_inl.h.

References gum::UGmodel::_graph.

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

36 { return _graph; }
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
+ Here is the caller graph for this function:

◆ hasSameStructure()

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

Definition at line 47 of file UGmodel.cpp.

References gum::UGmodel::edges(), gum::Set< Key, Alloc >::exists(), gum::UGmodel::idFromName(), gum::UGmodel::nodes(), gum::UGmodel::size(), gum::UGmodel::sizeEdges(), and gum::UGmodel::variable().

47  {
48  if (this == &other) return true;
49 
50  if (size() != other.size()) return false;
51 
52  if (sizeEdges() != other.sizeEdges()) return false;
53 
54  for (const auto& nid: nodes()) {
55  try {
56  other.idFromName(variable(nid).name());
57  } catch (NotFound) { return false; }
58  }
59 
60  for (const auto& edge: edges()) {
61  if (!other.edges().exists(
62  Edge(other.idFromName(variable(edge.first()).name()),
63  other.idFromName(variable(edge.second()).name()))))
64  return false;
65  }
66 
67  return true;
68  }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const EdgeSet & edges() const
returns the neighbours of a node as set of nodes
Definition: UGmodel_inl.h:44
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:53
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Definition: UGmodel_inl.h:42
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: UGmodel_inl.h:39
+ Here is the call graph for this function:

◆ idFromName()

template<typename GUM_SCALAR>
virtual NodeId gum::IMarkovNet< GUM_SCALAR >::idFromName ( const std::string &  name) const
pure virtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::UGmodel.

◆ 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:

◆ maxNonOneParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IMarkovNet< GUM_SCALAR >::maxNonOneParam ( ) const
Returns
the biggest value (not equal to 1) in the CPTs of *this

Definition at line 132 of file IMarkovNet_tpl.h.

References GUM_ERROR.

132  {
133  /*
134  GUM_SCALAR res = 0.0;
135  for (auto node: nodes()) {
136  auto v = factor(node).maxNonOne();
137  if (v > res) { res = v; }
138  }
139  return res;
140  */
141  GUM_ERROR(FatalError, "Not Implemented Yet")
142  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ maxParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IMarkovNet< GUM_SCALAR >::maxParam ( ) const
Returns
the biggest value in the CPTs of *this

Definition at line 105 of file IMarkovNet_tpl.h.

References GUM_ERROR.

105  {
106  /*
107  GUM_SCALAR res = 1.0;
108  for (auto node: nodes()) {
109  auto v = factor(node).max();
110  if (v > res) { res = v; }
111  }
112  return res;*/
113 
114  GUM_ERROR(FatalError, "Not Implemented Yet")
115  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ maxVarDomainSize()

template<typename GUM_SCALAR >
Size gum::IMarkovNet< GUM_SCALAR >::maxVarDomainSize ( ) const
Returns
the biggest domainSize among the variables of *this

Definition at line 79 of file IMarkovNet_tpl.h.

References GUM_ERROR.

79  {
80  /*
81  Size res = 0;
82  for (auto node: nodes()) {
83  auto v = variable(node).domainSize();
84  if (v > res) { res = v; }
85  }
86  return res;*/
87 
88  GUM_ERROR(FatalError, "Not Implemented Yet")
89  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ minNonZeroParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IMarkovNet< GUM_SCALAR >::minNonZeroParam ( ) const
Returns
the smallest value (not equal to 0) in the CPTs of *this

Definition at line 118 of file IMarkovNet_tpl.h.

References GUM_ERROR.

118  {
119  /*
120  GUM_SCALAR res = 1.0;
121  for (auto node: nodes()) {
122  auto v = factor(node).minNonZero();
123  if (v < res) { res = v; }
124  }
125  return res;
126  */
127 
128  GUM_ERROR(FatalError, "Not Implemented Yet")
129  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ minParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IMarkovNet< GUM_SCALAR >::minParam ( ) const
Returns
the smallest value in the CPTs of *this

Definition at line 92 of file IMarkovNet_tpl.h.

References GUM_ERROR.

92  {
93  /*
94  GUM_SCALAR res = 1.0;
95  for (auto node: nodes()) {
96  auto v = factor(node).min();
97  if (v < res) { res = v; }
98  }
99  return res;*/
100 
101  GUM_ERROR(FatalError, "Not Implemented Yet")
102  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ neighbours() [1/2]

INLINE const NodeSet & gum::UGmodel::neighbours ( const NodeId  id) const
inherited

returns the neighbours of a node as set of nodes

Note that the set of nodes returned may be empty if no edge within the EdgeGraphPart contains the given node.

Parameters
idthe node toward which the edge returned are pointing

Definition at line 46 of file UGmodel_inl.h.

References gum::UGmodel::_graph, and gum::EdgeGraphPart::neighbours().

Referenced by gum::UGmodel::neighbours().

46  {
47  return _graph.neighbours(id);
48  }
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neighbours() [2/2]

INLINE const NodeSet & gum::UGmodel::neighbours ( const std::string &  name) const
inherited

returns the neighbours of a node as set of nodes

Note that the set of nodes returned may be empty if no edge within the EdgeGraphPart contains the given node.

Parameters
idthe node toward which the edge returned are pointing

Definition at line 49 of file UGmodel_inl.h.

References gum::UGmodel::idFromName(), and gum::UGmodel::neighbours().

49  {
50  return neighbours(idFromName(name));
51  }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeSet & neighbours(const NodeId id) const
returns the neighbours of a node as set of nodes
Definition: UGmodel_inl.h:46
+ Here is the call graph for this function:

◆ nodeId()

template<typename GUM_SCALAR>
virtual NodeId gum::IMarkovNet< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
pure virtual

Return id node from discrete var pointer.

Exceptions
NotFoundIf no variable matches var.

Implements gum::UGmodel.

◆ nodes()

INLINE const NodeGraphPart & gum::UGmodel::nodes ( ) const
virtualinherited

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

Implements gum::GraphicalModel.

Definition at line 53 of file UGmodel_inl.h.

References gum::UGmodel::_graph.

Referenced by gum::UGmodel::hasSameStructure().

53  {
54  return (NodeGraphPart&)_graph;
55  }
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
+ Here is the caller graph for this function:

◆ operator!=()

template<typename GUM_SCALAR >
bool gum::IMarkovNet< GUM_SCALAR >::operator!= ( const IMarkovNet< GUM_SCALAR > &  from) const
Returns
Returns false if the src and this are equal.

Definition at line 254 of file IMarkovNet_tpl.h.

References gum::IMarkovNet< GUM_SCALAR >::operator==().

254  {
255  return !this->operator==(from);
256  }
bool operator==(const IMarkovNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
IMarkovNet< GUM_SCALAR > & gum::IMarkovNet< GUM_SCALAR >::operator= ( const IMarkovNet< GUM_SCALAR > &  source)

Copy operator.

Definition at line 58 of file IMarkovNet_tpl.h.

References gum::UGmodel::operator=().

Referenced by gum::build_node().

58  {
59  if (this != &source) { UGmodel::operator=(source); }
60 
61  return *this;
62  }
UGmodel & operator=(const UGmodel &source)
Private copy operator.
Definition: UGmodel.cpp:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator==()

template<typename GUM_SCALAR >
bool gum::IMarkovNet< GUM_SCALAR >::operator== ( const IMarkovNet< GUM_SCALAR > &  from) const

This operator compares 2 BNs !

Warning
To identify nodes between BNs, it is assumed that they share the same name.
Returns
true if the src and this are equal.

Definition at line 208 of file IMarkovNet_tpl.h.

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

208  {
209  return "Not Implemented Yet";
210  /*
211  if (size() != from.size()) { return false; }
212 
213  if (sizeEdges() != from.sizeEdges()) { return false; }
214 
215  // alignment of variables between the 2 BNs
216  Bijection< const DiscreteVariable*, const DiscreteVariable* > alignment;
217 
218  for (auto node: nodes()) {
219  try {
220  alignment.insert(&variable(node),
221  &from.variableFromName(variable(node).name()));
222  } catch (NotFound&) {
223  // a name is not found in from
224  return false;
225  }
226  }
227 
228  for (auto node: nodes()) {
229  NodeId fromnode = from.idFromName(variable(node).name());
230 
231  if (factor(node).nbrDim() != from.factor(fromnode).nbrDim()) { return
232  false; }
233 
234  Instantiation i(factor(node));
235  Instantiation j(from.factor(fromnode));
236 
237  for (i.setFirst(); !i.end(); i.inc()) {
238  for (Idx indice = 0; indice < factor(node).nbrDim(); ++indice) {
239  const DiscreteVariable* p = &(i.variable(indice));
240  j.chgVal(*(alignment.second(p)), i.val(*p));
241  }
242 
243  if (std::pow(factor(node).get(i) - from.factor(fromnode).get(j),
244  (GUM_SCALAR)2) > (GUM_SCALAR)1e-6) { return false;
245  }
246  }
247  }
248 
249  return true;
250  */
251  }
+ Here is the caller 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::GraphicalModel::__properties(), and GUM_ERROR.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toDot().

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  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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().

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:

◆ 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::GraphicalModel::__properties(), and gum::HashTable< Key, Val, Alloc >::insert().

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::UGmodel::size ( ) const
finalvirtualinherited

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 39 of file UGmodel_inl.h.

References gum::UGmodel::graph(), and gum::NodeGraphPart::size().

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

39 { return graph().size(); }
Size size() const
alias for sizeNodes
const UndiGraph & graph() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeEdges()

INLINE Size gum::UGmodel::sizeEdges ( ) const
inherited

Returns the number of arcs in this Directed Graphical Model.

Definition at line 42 of file UGmodel_inl.h.

References gum::UGmodel::_graph, and gum::EdgeGraphPart::sizeEdges().

Referenced by gum::UGmodel::hasSameStructure().

42 { return _graph.sizeEdges(); }
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
Size sizeEdges() const
indicates the number of edges stored within the EdgeGraphPart
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDot()

template<typename GUM_SCALAR >
std::string gum::IMarkovNet< GUM_SCALAR >::toDot ( ) const
virtual
Returns
Returns a dot representation of this IMarkovNet.

Definition at line 166 of file IMarkovNet_tpl.h.

166  {
167  return "Not Implemented Yet"; /*
168  std::stringstream output;
169  output << "digraph \"";
170 
171  std::string bn_name;
172 
173  try {
174  bn_name = this->property("name");
175  } catch (NotFound&) { bn_name = "no_name"; }
176 
177  output << bn_name << "\" {" << std::endl;
178  output << " graph [bgcolor=transparent,label=\"" << bn_name << "\"];"
179  << std::endl;
180  output << " node [style=filled fillcolor=\"#ffffaa\"];" << std::endl
181  << std::endl;
182 
183  for (auto node: nodes())
184  output << "\"" << variable(node).name() << "\" [comment=\"" << node << ":"
185  << variable(node).toStringWithDescription() << "\"];" << std::endl;
186 
187  output << std::endl;
188 
189  std::string tab = " ";
190 
191  for (auto node: nodes()) {
192  if (children(node).size() > 0) {
193  for (auto child: children(node)) {
194  output << tab << "\"" << variable(node).name() << "\" -> "
195  << "\"" << variable(child).name() << "\";" << std::endl;
196  }
197  } else if (parents(node).size() == 0) {
198  output << tab << "\"" << variable(node).name() << "\";" << std::endl;
199  }
200  }
201 
202  output << "}" << std::endl;
203 
204  return output.str();*/
205  }

◆ toString()

template<typename GUM_SCALAR >
INLINE std::string gum::IMarkovNet< GUM_SCALAR >::toString ( ) const
Returns
Returns a string representation of this IMarkovNet.

Definition at line 145 of file IMarkovNet_tpl.h.

References gum::IMarkovNet< GUM_SCALAR >::factor(), gum::IMarkovNet< GUM_SCALAR >::factors(), gum::UGmodel::graph(), gum::GraphicalModel::log10DomainSize(), gum::UGmodel::size(), and gum::EdgeGraphPart::sizeEdges().

Referenced by gum::operator<<().

145  {
146  Size param = 0;
147  double dSize = log10DomainSize();
148 
149  for (auto factor: factors())
150  param += factor.second->content()->realSize();
151 
152  std::stringstream s;
153  s << "MN{nodes: " << size() << ", edges: " << graph().sizeEdges() << ", ";
154 
155  if (dSize > 6)
156  s << "domainSize: 10^" << dSize;
157  else
158  s << "domainSize: " << std::round(std::pow(10.0, dSize));
159 
160  s << ", dim: " << param << "}";
161 
162  return s.str();
163  }
double log10DomainSize() const
virtual const FactorTable< GUM_SCALAR > & factors() const =0
Returns the set of factors as a IMarkovNet::FactorTable.
const UndiGraph & graph() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:36
Size sizeEdges() const
indicates the number of edges stored within the EdgeGraphPart
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: UGmodel_inl.h:39
virtual const Potential< GUM_SCALAR > & factor(const NodeSet &varIds) const =0
Returns the factor of a set of variable.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variable()

template<typename GUM_SCALAR>
virtual const DiscreteVariable& gum::IMarkovNet< GUM_SCALAR >::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::UGmodel.

◆ variableFromName()

template<typename GUM_SCALAR>
virtual const DiscreteVariable& gum::IMarkovNet< GUM_SCALAR >::variableFromName ( const std::string &  name) const
pure virtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::UGmodel.

◆ variableNodeMap()

template<typename GUM_SCALAR>
virtual const VariableNodeMap& gum::IMarkovNet< GUM_SCALAR >::variableNodeMap ( ) const
pure virtual

Returns a constant reference to the VariableNodeMap of thisBN.

Implements gum::GraphicalModel.

Member Data Documentation

◆ _graph

UndiGraph gum::UGmodel::_graph
protectedinherited

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