aGrUM 2.3.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
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
virtual NodeSet family (const NodeId id) const =0
 returns the family of a noe (parents or neighbours) of a node and the node
virtual NodeSet family (const std::string &name) const =0
Constructors / Destructors
 GraphicalModel ()
 Default constructor.
virtual ~GraphicalModel ()
 Destructor.
 GraphicalModel (const GraphicalModel &source)
 Copy constructor.
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this GraphicalModel.
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel.
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this GraphicalModel.
std::vector< std::string > properties () const
 List of all the properties.
Variable manipulation methods.
virtual const VariableNodeMapvariableNodeMap () const =0
 Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual Size size () const =0
 Returns the number of variables in this Directed Graphical Model.
virtual bool empty () const
 Return true if this graphical model is empty.
virtual bool exists (NodeId node) const =0
 Return true if this node exists in this graphical model.
virtual bool exists (const std::string &name) const =0
 Returns a constant reference to the VariableNodeMap of this Graphical Model.
std::vector< std::string > names (const std::vector< NodeId > &ids) const
 transform a vector of NodeId in a vector of names
std::vector< std::string > names (const NodeSet &ids) const
 transform a NodeSet in a vector of names
std::vector< NodeIdids (const std::vector< std::string > &names) const
 transform a vector of names into a vector of nodeId
NodeSet nodeset (const std::vector< std::string > &names) const
 transform a vector of names into a NodeSet
gum::VariableSet variables (const std::vector< std::string > &l) const
 transform a vector of names into a VariableeSet
gum::VariableSet variables (const NodeSet &ids) const
 transform a vector of NodeId into a VariableeSet
virtual const NodeGraphPartnodes () const =0
 Returns a constant reference to the VariableNodeMap of this Graphical Model.
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model.
virtual const DiscreteVariablevariable (NodeId id) const =0
 Returns a constant reference over a variable given it's node id.
virtual NodeId nodeId (const DiscreteVariable &var) const =0
 Return id node src discrete var pointer.
virtual NodeId idFromName (const std::string &name) const =0
 Getter by name.
virtual const DiscreteVariablevariableFromName (const std::string &name) const =0
 Getter by name.

Static Public Member Functions

static void spaceCplxToStream (std::stringstream &s, double dSize, int dim, Size usedMem)
 send to the stream the space complexity with 3 parametrs

Protected Member Functions

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

Private Member Functions

const HashTable< std::string, std::string > & _properties_ () const
 Return the properties of this Directed Graphical Model.

Private Attributes

HashTable< std::string, std::string > _propertiesMap_
 The properties of this Directed Graphical Model.

Detailed Description

Virtual base class for probabilistic graphical models.

Definition at line 65 of file graphicalModel.h.

Constructor & Destructor Documentation

◆ GraphicalModel() [1/2]

gum::GraphicalModel::GraphicalModel ( )

Default constructor.

Definition at line 49 of file graphicalModel.cpp.

49{ GUM_CONSTRUCTOR(GraphicalModel) }
GraphicalModel()
Default constructor.

References GraphicalModel().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~GraphicalModel()

gum::GraphicalModel::~GraphicalModel ( )
virtual

Destructor.

Definition at line 53 of file graphicalModel.cpp.

53{ GUM_DESTRUCTOR(GraphicalModel); }

References GraphicalModel().

Here is the call graph for this function:

◆ GraphicalModel() [2/2]

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

Copy constructor.

Do nothing.

Definition at line 51 of file graphicalModel.cpp.

51{ GUM_CONS_CPY(GraphicalModel); }

References GraphicalModel().

Here is the call graph for this function:

Member Function Documentation

◆ _properties_()

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

Return the properties of this Directed Graphical Model.

Definition at line 70 of file graphicalModel_inl.h.

70 {
71 return _propertiesMap_;
72 }
HashTable< std::string, std::string > _propertiesMap_
The properties of this Directed Graphical Model.

References _propertiesMap_.

Referenced by property().

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

106 {
107 Instantiation I;
108
109 for (const auto node: nodes())
110 I << variable(node);
111
112 return I;
113 }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
virtual const NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

References nodes().

Here is the call graph for this function:

◆ empty()

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

Return true if this graphical model is empty.

Definition at line 116 of file graphicalModel_inl.h.

116{ return size() == 0; }
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.

References size().

Referenced by gum::IBayesNet< GUM_SCALAR >::check(), and gum::BayesNet< GUM_SCALAR >::clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exists() [1/2]

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

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

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

References ids(), and names().

Here is the call graph for this function:

◆ exists() [2/2]

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

Return true if this node exists in this graphical model.

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

◆ family() [1/2]

virtual NodeSet gum::GraphicalModel::family ( const NodeId id) const
pure virtual

returns the family of a noe (parents or neighbours) of a node and the node

Parameters
idthe node which is the head of an arc with the returned nodes
namethe name of the node the node which is the head of an arc with the returned nodes

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

◆ family() [2/2]

virtual NodeSet gum::GraphicalModel::family ( const std::string & name) const
pure virtual

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

References GraphicalModel().

Here is the call graph for this function:

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

139 {
140 std::vector< NodeId > res;
141 const VariableNodeMap& v = variableNodeMap();
142 std::transform(names.cbegin(),
143 names.cend(),
144 std::back_inserter(res),
145 [v](const std::string& n) { return v.idFromName(n); });
146 return res;
147 }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
std::vector< std::string > names(const std::vector< NodeId > &ids) const
transform a vector of NodeId in a vector of names

References names().

Referenced by gum::DAGmodel::children(), exists(), names(), and gum::DAGmodel::parents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIndependent() [1/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.

◆ isIndependent() [2/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.

◆ log10DomainSize()

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

Definition at line 95 of file graphicalModel_inl.h.

95 {
96 double dSize = 0.0;
97
98 for (const auto node: nodes()) {
99 dSize += std::log10(variable(node).domainSize());
100 }
101
102 return dSize;
103 }

References nodes().

Referenced by gum::IBayesNet< GUM_SCALAR >::toString(), gum::IMarkovRandomField< GUM_SCALAR >::toString(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ names() [1/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 129 of file graphicalModel_inl.h.

129 {
130 const VariableNodeMap& v = variableNodeMap();
131 std::vector< std::string > res;
132 for (auto n: ids) {
133 res.push_back(v.name(n));
134 }
135 return res;
136 }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId

◆ names() [2/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 119 of file graphicalModel_inl.h.

119 {
120 std::vector< std::string > res;
121 const VariableNodeMap& v = variableNodeMap();
122 std::transform(ids.cbegin(), ids.cend(), std::back_inserter(res), [v](NodeId n) {
123 return v[n].name();
124 });
125 return res;
126 }
Size NodeId
Type for node ids.

References ids(), and variableNodeMap().

Referenced by gum::DAGmodel::children(), exists(), ids(), nodeset(), and gum::DAGmodel::parents().

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:

◆ 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 60 of file graphicalModel.cpp.

60 {
61 NodeSet res;
62 for (const auto& name: names) {
63 res.insert(idFromName(name));
64 }
65 return res;
66 }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

References idFromName(), gum::Set< Key >::insert(), and names().

Referenced by gum::IBayesNet< double >::children(), gum::IBayesNet< double >::children(), gum::DAGmodel::isIndependent(), gum::DAGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::DAGmodel::moralizedAncestralGraph(), and gum::DAGmodel::parents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

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

Private copy operator.

Definition at line 55 of file graphicalModel.cpp.

55 {
56 if (this != &source) { _propertiesMap_ = source._propertiesMap_; }
57 return *this;
58 }

References GraphicalModel(), and _propertiesMap_.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ properties()

INLINE std::vector< std::string > gum::GraphicalModel::properties ( ) const

List of all the properties.

Definition at line 81 of file graphicalModel_inl.h.

81 {
82 std::vector< std::string > prop;
83 for (const auto& [p, v]: _propertiesMap_)
84 prop.push_back(p);
85 return prop;
86 }

References _propertiesMap_.

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

60 {
61 try {
62 return _properties_()[name];
63 } catch (NotFound const&) {
64 std::string msg = "The following property does not exists: ";
65 GUM_ERROR(NotFound, msg + name)
66 }
67 }
const HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _properties_(), and GUM_ERROR.

Referenced by gum::IMarkovRandomField< GUM_SCALAR >::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().

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

76 {
77 return (_propertiesMap_.exists(name)) ? _propertiesMap_[name] : byDefault;
78 }

References _propertiesMap_.

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

89 {
90 if (_propertiesMap_.exists(name)) _propertiesMap_[name] = value;
91 else _propertiesMap_.insert(name, value);
92 }

References _propertiesMap_.

Referenced by gum::IBayesNet< GUM_SCALAR >::IBayesNet(), gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField(), and gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype().

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:

◆ spaceCplxToStream()

void gum::GraphicalModel::spaceCplxToStream ( std::stringstream & s,
double dSize,
int dim,
Size usedMem )
static

send to the stream the space complexity with 3 parametrs

Parameters
sthe stream
dSizethe log10domainSize
dimthe dimension
usedMemthe memory needed for the params

Definition at line 69 of file graphicalModel.cpp.

69 {
70 if (dSize > 6) s << "domainSize: 10^" << dSize;
71 else s << "domainSize: " << std::round(std::pow(10.0, dSize));
72
73 s << ", dim: " << dim << ", mem: ";
74
75 if (const Size go = usedMem / (1024 * 1024 * 1024); go > 0) s << go << "Go ";
76 if (const Size mo = (usedMem / (1024 * 1024)) % 1024; mo > 0) s << mo << "Mo ";
77 if (const Size ko = (usedMem / 1024) % 1024; ko > 0) s << ko << "Ko ";
78 s << usedMem % 1024 << "o";
79 }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

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

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::BayesNetFragment< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::IMarkovRandomField< GUM_SCALAR >, gum::InfluenceDiagram< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Referenced by gum::DAGmodel::hasSameStructure(), and gum::UGmodel::hasSameStructure().

Here is the caller graph for this function:

◆ variableFromName()

◆ variableNodeMap()

virtual const VariableNodeMap & gum::GraphicalModel::variableNodeMap ( ) const
pure virtual

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

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

Referenced by gum::IBayesNet< double >::empty(), names(), variables(), and variables().

Here is the caller graph for this function:

◆ variables() [1/2]

INLINE VariableSet gum::GraphicalModel::variables ( const NodeSet & ids) const

transform a vector of NodeId into a VariableeSet

Returns
NodeSet

Definition at line 160 of file graphicalModel_inl.h.

160 {
161 VariableSet s;
162 const VariableNodeMap& v = variableNodeMap();
163 for (const auto& node: l) {
164 s.insert(&v.get(node));
165 }
166 return s;
167 }
Set< const DiscreteVariable * > VariableSet

References gum::VariableNodeMap::get(), gum::Set< Key >::insert(), and variableNodeMap().

Here is the call graph for this function:

◆ variables() [2/2]

INLINE VariableSet gum::GraphicalModel::variables ( const std::vector< std::string > & l) const

transform a vector of names into a VariableeSet

Returns
NodeSet

Definition at line 150 of file graphicalModel_inl.h.

150 {
151 VariableSet s;
152 const VariableNodeMap& v = variableNodeMap();
153 for (const auto& name: l) {
154 s.insert(&v.variableFromName(name));
155 }
156 return s;
157 }

References variableNodeMap().

Here is the call graph for this function:

Member Data Documentation

◆ _propertiesMap_

HashTable< std::string, std::string > gum::GraphicalModel::_propertiesMap_
private

The properties of this Directed Graphical Model.

Definition at line 236 of file graphicalModel.h.

Referenced by _properties_(), operator=(), properties(), propertyWithDefault(), and setProperty().


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