aGrUM  0.17.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
 
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
 Retursn true if this Directed Graphical Model is empty. 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 48 of file graphicalModel.h.

Constructor & Destructor Documentation

◆ GraphicalModel() [1/2]

gum::GraphicalModel::GraphicalModel ( )

Default constructor.

Definition at line 30 of file graphicalModel.cpp.

30  : __propertiesMap(nullptr) {
31  GUM_CONSTRUCTOR(GraphicalModel);
32  }
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.

◆ ~GraphicalModel()

gum::GraphicalModel::~GraphicalModel ( )
virtual

Destructor.

Definition at line 44 of file graphicalModel.cpp.

References __propertiesMap.

44  {
45  GUM_DESTRUCTOR(GraphicalModel);
46  if (__propertiesMap) { delete __propertiesMap; }
47  }
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.

◆ GraphicalModel() [2/2]

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

Copy constructor.

Do nothing.

Definition at line 34 of file graphicalModel.cpp.

References __propertiesMap.

34  :
35  __propertiesMap(nullptr) {
36  GUM_CONS_CPY(GraphicalModel);
37 
38  if (from.__propertiesMap) {
40  new HashTable< std::string, std::string >(*(from.__propertiesMap));
41  }
42  }
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
GraphicalModel()
Default constructor.

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

References __propertiesMap.

Referenced by property(), propertyWithDefault(), and setProperty().

47  {
48  if (__propertiesMap == nullptr) {
50  }
51 
52  return *__propertiesMap;
53  }
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
+ Here is the caller graph for this function:

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 85 of file graphicalModel_inl.h.

References nodes(), and 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:

◆ empty()

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

Retursn true if this Directed Graphical Model is empty.

Definition at line 95 of file graphicalModel_inl.h.

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

◆ idFromName()

◆ log10DomainSize()

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

Definition at line 74 of file graphicalModel_inl.h.

References nodes(), and 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:

◆ 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::DAGmodel, and gum::UGmodel.

Referenced by completeInstantiation(), and log10DomainSize().

+ Here is the caller graph for this function:

◆ operator=()

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

Private copy operator.

Definition at line 49 of file graphicalModel.cpp.

References __propertiesMap.

Referenced by gum::UGmodel::operator=(), and gum::DAGmodel::operator=().

49  {
50  if (this != &source) {
51  if (__propertiesMap) {
52  delete __propertiesMap;
53  __propertiesMap = nullptr;
54  }
55 
56  if (source.__propertiesMap != 0) {
58  new HashTable< std::string, std::string >(*(source.__propertiesMap));
59  }
60  }
61  return *this;
62  }
HashTable< std::string, std::string > * __propertiesMap
The properties of this Directed Graphical Model. Initialized using a lazy instantiation.
+ Here is the caller 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 37 of file graphicalModel_inl.h.

References __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

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

Add or change a property of this GraphicalModel.

Definition at line 65 of file graphicalModel_inl.h.

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

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

Returns the number of variables in this Directed Graphical Model.

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

Referenced by empty().

+ Here is the caller graph for this function:

◆ variable()

virtual const DiscreteVariable& gum::GraphicalModel::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.

Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, gum::DAGmodel, gum::UGmodel, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Referenced by completeInstantiation(), and log10DomainSize().

+ Here is the caller graph for this function:

◆ variableFromName()

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

Referenced by __properties(), GraphicalModel(), operator=(), and ~GraphicalModel().


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