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

Virtual base class for probabilistic graphical models. More...

#include <graphicalModel.h>

+ Inheritance diagram for gum::GraphicalModel:
+ Collaboration diagram for gum::GraphicalModel:

Public Member Functions

double log10DomainSize () const
 
virtual bool isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const =0
 check if node X and node Y are independent given nodes Z More...
 
virtual bool isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const =0
 check if nodes X and nodes Y are independent given nodes Z More...
 
Constructors / Destructors
 GraphicalModel ()
 Default constructor. More...
 
virtual ~GraphicalModel ()
 Destructor. More...
 
 GraphicalModel (const GraphicalModel &source)
 Copy constructor. 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 Size size () const =0
 Returns the number of variables in this Directed Graphical Model. More...
 
virtual bool empty () const
 Return true if this graphical model is empty. More...
 
virtual bool exists (NodeId node) const =0
 Return true if this node exists in this graphical model. 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...
 
virtual const NodeGraphPartnodes () const =0
 Returns a constant reference to the VariableNodeMap of this Graphical Model. 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 Member Functions

GraphicalModeloperator= (const GraphicalModel &source)
 Private copy operator. More...
 

Detailed Description

Virtual base class for probabilistic graphical models.

Definition at line 47 of file graphicalModel.h.

Constructor & Destructor Documentation

◆ GraphicalModel() [1/2]

gum::GraphicalModel::GraphicalModel ( )

Default constructor.

Definition at line 29 of file graphicalModel.cpp.

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

29  : propertiesMap__(nullptr) {
30  GUM_CONSTRUCTOR(GraphicalModel);
31  }
HashTable< std::string, std::string > * propertiesMap__
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.
+ Here is the call graph for this function:

◆ ~GraphicalModel()

gum::GraphicalModel::~GraphicalModel ( )
virtual

Destructor.

Definition at line 43 of file graphicalModel.cpp.

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

43  {
44  GUM_DESTRUCTOR(GraphicalModel);
45  if (propertiesMap__) { delete propertiesMap__; }
46  }
HashTable< std::string, std::string > * propertiesMap__
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.
+ Here is the call graph for this function:

◆ GraphicalModel() [2/2]

gum::GraphicalModel::GraphicalModel ( const GraphicalModel source)

Copy constructor.

Do nothing.

Definition at line 33 of file graphicalModel.cpp.

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

33  :
34  propertiesMap__(nullptr) {
35  GUM_CONS_CPY(GraphicalModel);
36 
37  if (from.propertiesMap__) {
39  = new HashTable< std::string, std::string >(*(from.propertiesMap__));
40  }
41  }
HashTable< std::string, std::string > * propertiesMap__
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ completeInstantiation()

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

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.

◆ empty()

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

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]

virtual bool gum::GraphicalModel::exists ( NodeId  node) const
pure virtual

Return true if this node exists in this graphical model.

Implemented in gum::UGmodel, and gum::DAGmodel.

◆ exists() [2/2]

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

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.

◆ idFromName()

◆ ids()

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

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/2]

virtual bool gum::GraphicalModel::isIndependent ( NodeId  X,
NodeId  Y,
const NodeSet Z 
) const
pure virtual

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

Implemented in gum::DAGmodel, and gum::UGmodel.

◆ isIndependent() [2/2]

virtual bool gum::GraphicalModel::isIndependent ( const NodeSet X,
const NodeSet Y,
const NodeSet Z 
) const
pure virtual

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

Implemented in gum::DAGmodel, and gum::UGmodel.

◆ log10DomainSize()

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

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.

◆ names() [1/2]

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

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

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()

virtual const NodeGraphPart& gum::GraphicalModel::nodes ( ) const
pure virtual

Returns a constant reference to the VariableNodeMap of this Graphical Model.

Implemented in gum::UGmodel, and gum::DAGmodel.

◆ nodeset()

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

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=()

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

Private copy operator.

Definition at line 48 of file graphicalModel.cpp.

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

48  {
49  if (this != &source) {
50  if (propertiesMap__) {
51  delete propertiesMap__;
52  propertiesMap__ = nullptr;
53  }
54 
55  if (source.propertiesMap__ != 0) {
57  = new HashTable< std::string, std::string >(*(source.propertiesMap__));
58  }
59  }
60  return *this;
61  }
HashTable< std::string, std::string > * propertiesMap__
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
+ Here is the call graph for this function:

◆ properties__()

INLINE HashTable< std::string, std::string > & gum::GraphicalModel::properties__ ( ) const
private

Return the properties of this Directed Graphical Model and initialize the hash table is necessary.

Definition at line 48 of file graphicalModel_inl.h.

48  {
49  if (propertiesMap__ == nullptr) {
51  }
52 
53  return *propertiesMap__;
54  }
HashTable< std::string, std::string > * propertiesMap__
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.

◆ property()

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

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

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 
)

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()

virtual Size gum::GraphicalModel::size ( ) const
pure virtual

Returns the number of variables in this Directed Graphical Model.

Implemented in gum::UGmodel, and gum::DAGmodel.

◆ variable()

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

◆ variableFromName()

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

◆ variableNodeMap()

Member Data Documentation

◆ propertiesMap__

HashTable< std::string, std::string >* gum::GraphicalModel::propertiesMap__
mutableprivate

The properties of this Directed Graphical Model. Initialized using a lazy instantiation.

Definition at line 189 of file graphicalModel.h.


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