aGrUM  0.20.3
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) { GUM_CONSTRUCTOR(GraphicalModel); }
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 39 of file graphicalModel.cpp.

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

39  {
40  GUM_DESTRUCTOR(GraphicalModel);
41  if (_propertiesMap_) { delete _propertiesMap_; }
42  }
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 31 of file graphicalModel.cpp.

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

31  : _propertiesMap_(nullptr) {
32  GUM_CONS_CPY(GraphicalModel);
33 
34  if (from._propertiesMap_) {
35  _propertiesMap_ = new HashTable< std::string, std::string >(*(from._propertiesMap_));
36  }
37  }
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

◆ _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.

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 84 of file graphicalModel_inl.h.

84  {
85  Instantiation I;
86 
87  for (const auto node: nodes())
88  I << variable(node);
89 
90  return I;
91  }
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 94 of file graphicalModel_inl.h.

94 { 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 { return exists(idFromName(name)); };
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 117 of file graphicalModel_inl.h.

117  {
118  std::vector< NodeId > res;
119  const VariableNodeMap& v = variableNodeMap();
120  std::transform(names.cbegin(),
121  names.cend(),
122  std::back_inserter(res),
123  [v](const std::string& n) { return v.idFromName(n); });
124  return res;
125  }
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 73 of file graphicalModel_inl.h.

73  {
74  double dSize = 0.0;
75 
76  for (const auto node: nodes()) {
77  dSize += std::log10(variable(node).domainSize());
78  }
79 
80  return dSize;
81  }
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 97 of file graphicalModel_inl.h.

97  {
98  std::vector< std::string > res;
99  const VariableNodeMap& v = variableNodeMap();
100  std::transform(ids.cbegin(), ids.cend(), std::back_inserter(res), [v](NodeId n) {
101  return v[n].name();
102  });
103  return res;
104  }
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 107 of file graphicalModel_inl.h.

107  {
108  const VariableNodeMap& v = variableNodeMap();
109  std::vector< std::string > res;
110  for (auto n: ids) {
111  res.push_back(v.name(n));
112  }
113  return res;
114  }
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 58 of file graphicalModel.cpp.

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

58  {
59  NodeSet res;
60  for (const auto& name: names) {
61  res.insert(idFromName(name));
62  }
63  return res;
64  }
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:606
+ Here is the call graph for this function:

◆ operator=()

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

Private copy operator.

Definition at line 44 of file graphicalModel.cpp.

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

44  {
45  if (this != &source) {
46  if (_propertiesMap_) {
47  delete _propertiesMap_;
48  _propertiesMap_ = nullptr;
49  }
50 
51  if (source._propertiesMap_ != 0) {
52  _propertiesMap_ = new HashTable< std::string, std::string >(*(source._propertiesMap_));
53  }
54  }
55  return *this;
56  }
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:

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

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

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...

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

65  {
66  try {
67  _properties_()[name] = value;
68  } catch (NotFound&) { _properties_().insert(name, value); }
69  }
HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ 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 184 of file graphicalModel.h.


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