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

Class representing the minimal interface for Markov random field. More...

#include <agrum/BN/IMarkovRandomField.h>

Inheritance diagram for gum::IMarkovRandomField< GUM_SCALAR >:
Collaboration diagram for gum::IMarkovRandomField< GUM_SCALAR >:

Public Member Functions

bool operator== (const IMarkovRandomField< GUM_SCALAR > &from) const
 This operator compares 2 BNs !
Size dim () const
 Returns the dimension (the number of free parameters) in this bayes net.
Size maxVarDomainSize () const
GUM_SCALAR minParam () const
GUM_SCALAR maxParam () const
GUM_SCALAR minNonZeroParam () const
GUM_SCALAR maxNonOneParam () const
virtual std::string toDot () const
virtual std::string toDotAsFactorGraph () const
std::string toString () const
NodeSet minimalCondSet (NodeId target, const NodeSet &soids) const
NodeSet minimalCondSet (const NodeSet &targets, const NodeSet &soids) const
bool hasSameStructure (const UGmodel &other) const
 check if nodes X and nodes Y are independent given nodes Z
NodeProperty< NodeIdconnectedComponents () const
 Returns the connected components of the underlying undirected graph. Each node maps to the id of its component root.
NodeSet family (const NodeId id) const final
 returns the node as a NodeSet (in mixed graph : family is the node and its parents
NodeSet family (std::string_view name) const final
const UndiGraphinternalGraph () const
 Returns a const reference to the internal (unnamed) graph. O(1), no copy. Use for stable references or pointers (graph listeners). For named node access, use graph() instead.
double log10DomainSize () const
Constructors / Destructors
 IMarkovRandomField ()
 Default constructor.
 IMarkovRandomField (std::string_view name)
 Default constructor.
 ~IMarkovRandomField () override
 Destructor.
 IMarkovRandomField (const IMarkovRandomField< GUM_SCALAR > &source)
 Copy constructor.
IMarkovRandomField< GUM_SCALAR > & operator= (const IMarkovRandomField< GUM_SCALAR > &source)
 Copy operator.
Pure Virtual methods
virtual const Tensor< GUM_SCALAR > & factor (const NodeSet &varIds) const =0
 Returns the factor of a set of variable.
virtual const NodeSetsmallestFactorFromNode (NodeId node) const =0
 Returns the smallest factor that contains this variable.
virtual const NodeSetsmallestFactorFromNode (std::string_view name) const
 Returns the smallest factor that contains this variable.
virtual const FactorTable< GUM_SCALAR > & factors () const =0
 Returns the set of factors as a IMarkovRandomField::FactorTable.
Variable manipulation methods.
UndiGraph graph () const
 Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.
Size size () const final
 Returns the number of variables in this Directed Graphical Model.
Size sizeEdges () const
 Returns the number of arcs in this Directed Graphical Model.
const NodeGraphPartnodes () const final
 Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.
bool exists (NodeId node) const final
 Return true if this node exists in this graphical model.
bool exists (std::string_view name) const final
 Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.
Edge manipulation methods.
const EdgeSetedges () const
 return true if the edge node1-node2 exists in the UGModel
bool existsEdge (const NodeId node1, const NodeId node2) const
 return true if the edge node1-node2 exists in the UGModel
bool existsEdge (std::string_view name1, std::string_view name2) const
 return true if the edge node1-node2 exists in the UGModel
const NodeSetneighbours (const NodeId id) const
 returns the neighbours of a node as set of nodes
const NodeSetneighbours (std::string_view name) const
 return true if the edge node1-node2 exists in the UGModel
bool isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final
 check if X and Y are independent given Z
bool isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const final
 check if nodes X and nodes Y are independent given nodes Z
bool isIndependent (std::string_view Xname, std::string_view Yname, const std::vector< std::string > &Znames) const
 return true if the edge node1-node2 exists in the UGModel
bool isIndependent (const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const
 return true if the edge node1-node2 exists in the UGModel
Variable accessor methods
const VariableNodeMapvariableNodeMap () const override
 Returns a constant reference to the VariableNodeMap of this model.
const DiscreteVariablevariable (NodeId id) const override
 Returns a constant reference over a variable given its node id.
NodeId nodeId (const DiscreteVariable &var) const override
 Returns the NodeId of a variable.
NodeId idFromName (std::string_view name) const override
 Returns the NodeId of a variable given its name.
const DiscreteVariablevariableFromName (std::string_view name) const override
 Returns a constant reference over a variable given its name.
Getter and setters
const std::string & property (std::string_view name) const
 Return the value of the property name of this GraphicalModel.
const std::string & propertyWithDefault (std::string_view name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel.
void setProperty (std::string_view name, std::string_view value)
 Add or change a property of this GraphicalModel.
std::vector< std::string > properties () const
 List of all the names of property in the Graphical model.
bool existsProperty (std::string_view name) const
 check wether a property exists in this GraphicalModel
void updateMetaData ()
 update the meta data of this Graphical Model (version, creation date, last modification date) This method is called by the writers ONLY before writing the model to a file.
Variable manipulation methods.
virtual bool empty () const
 Return true if this graphical model is empty.
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
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model.

Static Public Member Functions

static std::string spaceCplxToString (double dSize, int dim, Size usedMem)
 send to the stream the space complexity with 3 parametrs

Protected Member Functions

void _nameNodes_ (NodeGraphPart &g) const
 Names every node of g using variable(id).name() for each node id in g.

Protected Attributes

UndiGraph graph_
 The DAG of this Directed Graphical Model.
VariableNodeMap varMap_
 Mapping between NodeIds and discrete variables.

Private Member Functions

void _minimalCondSetVisit_ (NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisited) const
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

template<GUM_Numeric GUM_SCALAR>
class gum::IMarkovRandomField< GUM_SCALAR >

Class representing the minimal interface for Markov random field.

This class is used as a base class for different versions of Markov random fields. No data (except the graph herited from UGModel are included in this class. Many algorithms (inference for instance) may use this class when a simple MRF is needed.

Definition at line 75 of file IMarkovRandomField.h.

Constructor & Destructor Documentation

◆ IMarkovRandomField() [1/3]

template<GUM_Numeric GUM_SCALAR>
gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField ( )

Default constructor.

Definition at line 61 of file IMarkovRandomField_tpl.h.

61 : UGmodel() {
63 }
Class representing the minimal interface for Markov random field.
IMarkovRandomField()
Default constructor.
UGmodel()
Default constructor.
Definition UGmodel.cpp:49

References IMarkovRandomField(), and gum::UGmodel::UGmodel().

Referenced by IMarkovRandomField(), IMarkovRandomField(), IMarkovRandomField(), ~IMarkovRandomField(), factors(), operator=(), and operator==().

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

◆ IMarkovRandomField() [2/3]

template<GUM_Numeric GUM_SCALAR>
gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField ( std::string_view name)
explicit

Default constructor.

Definition at line 66 of file IMarkovRandomField_tpl.h.

66 : UGmodel() {
68 this->setProperty("name", name);
69 }
void setProperty(std::string_view name, std::string_view value)
Add or change a property of this GraphicalModel.

References IMarkovRandomField(), gum::UGmodel::UGmodel(), and gum::GraphicalModel::setProperty().

Here is the call graph for this function:

◆ ~IMarkovRandomField()

template<GUM_Numeric GUM_SCALAR>
gum::IMarkovRandomField< GUM_SCALAR >::~IMarkovRandomField ( )
override

Destructor.

Definition at line 86 of file IMarkovRandomField_tpl.h.

References IMarkovRandomField().

Here is the call graph for this function:

◆ IMarkovRandomField() [3/3]

template<GUM_Numeric GUM_SCALAR>
gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField ( const IMarkovRandomField< GUM_SCALAR > & source)

Copy constructor.

Definition at line 72 of file IMarkovRandomField_tpl.h.

References IMarkovRandomField(), and gum::UGmodel::UGmodel().

Here is the call graph for this function:

Member Function Documentation

◆ _minimalCondSetVisit_()

template<GUM_Numeric GUM_SCALAR>
void gum::IMarkovRandomField< GUM_SCALAR >::_minimalCondSetVisit_ ( NodeId node,
const NodeSet & soids,
NodeSet & minimal,
NodeSet & alreadyVisited ) const
private

Definition at line 319 of file IMarkovRandomField_tpl.h.

322 {
323 if (alreadyVisited.contains(node)) return;
325
326 if (soids.contains(node)) {
327 minimal << node;
328 } else {
329 for (auto neig: graph_.neighbours(node))
331 }
332 }
void _minimalCondSetVisit_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisited) const
UndiGraph graph_
The DAG of this Directed Graphical Model.
Definition UGmodel.h:195

References _minimalCondSetVisit_(), gum::Set< Key >::contains(), and gum::UGmodel::graph_.

Referenced by _minimalCondSetVisit_(), and minimalCondSet().

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

◆ _nameNodes_()

INLINE void gum::GraphicalModel::_nameNodes_ ( NodeGraphPart & g) const
protectedinherited

Names every node of g using variable(id).name() for each node id in g.

Call this before returning any newly constructed graph from a model method.

Definition at line 175 of file graphicalModel_inl.h.

175 {
176 for (auto id: g)
177 g.setName(id, variable(id).name());
178 }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.

References gum::NodeGraphPart::setName(), and variable().

Referenced by gum::DAGmodel::dag(), gum::UGmodel::graph(), gum::DAGmodel::moralGraph(), and gum::DAGmodel::moralizedAncestralGraph().

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

◆ _properties_()

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

Return the properties of this Directed Graphical Model.

Definition at line 67 of file graphicalModel_inl.h.

67 {
68 return _propertiesMap_;
69 }
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
inherited

Get an instantiation over all the variables of the model.

Definition at line 104 of file graphicalModel_inl.h.

104 {
105 Instantiation I;
106
107 for (const auto node: nodes())
108 I << variable(node);
109
110 return I;
111 }
virtual const NodeGraphPart & nodes() const =0
Returns the number of variables in this Directed Graphical Model.

References nodes(), and variable().

Here is the call graph for this function:

◆ connectedComponents()

INLINE NodeProperty< NodeId > gum::UGmodel::connectedComponents ( ) const
inherited

Returns the connected components of the underlying undirected graph. Each node maps to the id of its component root.

Definition at line 109 of file UGmodel_inl.h.

109 {
110 return graph_.connectedComponents();
111 }

References graph_.

◆ dim()

template<GUM_Numeric GUM_SCALAR>
Size gum::IMarkovRandomField< 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 91 of file IMarkovRandomField_tpl.h.

91 {
92 Size res = 0;
93 for (auto f: factors()) {
94 res += f.second->domainSize();
95 }
96 return res;
97 }
virtual const FactorTable< GUM_SCALAR > & factors() const =0
Returns the set of factors as a IMarkovRandomField::FactorTable.

References factors().

Here is the call graph for this function:

◆ edges()

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

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 73 of file UGmodel_inl.h.

73{ return graph_.edges(); }

References graph_.

Referenced by hasSameStructure().

Here is the caller graph for this function:

◆ empty()

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

Return true if this graphical model is empty.

Definition at line 114 of file graphicalModel_inl.h.

114{ 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]

INLINE bool gum::UGmodel::exists ( NodeId node) const
finalvirtualinherited

Return true if this node exists in this graphical model.

Implements gum::GraphicalModel.

Definition at line 89 of file UGmodel_inl.h.

89{ return graph_.exists(node); }

References graph_.

Referenced by exists(), hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), and gum::IMarkovRandomField< GUM_SCALAR >::smallestFactorFromNode().

Here is the caller graph for this function:

◆ exists() [2/2]

INLINE bool gum::UGmodel::exists ( std::string_view name) const
finalvirtualinherited

Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new graph. For a stable reference (listeners, long-lived pointers), use internalGraph().

Implements gum::GraphicalModel.

Definition at line 91 of file UGmodel_inl.h.

91 {
92 try {
93 return exists(idFromName(name));
94 } catch ([[maybe_unused]] gum::NotFound& e) { return false; }
95 }
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
Definition UGmodel_inl.h:89

References exists(), and gum::DiscreteGraphicalModel::idFromName().

Here is the call graph for this function:

◆ existsEdge() [1/2]

INLINE bool gum::UGmodel::existsEdge ( const NodeId node1,
const NodeId node2 ) const
inherited

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 75 of file UGmodel_inl.h.

75 {
76 return graph_.existsEdge(node1, node2);
77 }

References graph_.

Referenced by existsEdge().

Here is the caller graph for this function:

◆ existsEdge() [2/2]

INLINE bool gum::UGmodel::existsEdge ( std::string_view name1,
std::string_view name2 ) const
inherited

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 79 of file UGmodel_inl.h.

79 {
80 return existsEdge(idFromName(name1), idFromName(name2));
81 }
bool existsEdge(const NodeId node1, const NodeId node2) const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:75

References existsEdge(), and gum::DiscreteGraphicalModel::idFromName().

Here is the call graph for this function:

◆ existsProperty()

INLINE bool gum::GraphicalModel::existsProperty ( std::string_view name) const
inherited

check wether a property exists in this GraphicalModel

Definition at line 170 of file graphicalModel_inl.h.

170 {
171 return _propertiesMap_.exists(name);
172 }

References _propertiesMap_.

◆ factor()

template<GUM_Numeric GUM_SCALAR>
virtual const Tensor< GUM_SCALAR > & gum::IMarkovRandomField< 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 operator==(), and toString().

Here is the caller graph for this function:

◆ factors()

template<GUM_Numeric GUM_SCALAR>
virtual const FactorTable< GUM_SCALAR > & gum::IMarkovRandomField< GUM_SCALAR >::factors ( ) const
pure virtual

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

References IMarkovRandomField().

Referenced by dim(), maxNonOneParam(), maxParam(), minNonZeroParam(), minParam(), operator==(), toDotAsFactorGraph(), and toString().

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

◆ family() [1/2]

INLINE NodeSet gum::UGmodel::family ( const NodeId id) const
finalvirtualinherited

returns the node as a NodeSet (in mixed graph : family is the node and its parents

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

Implements gum::GraphicalModel.

Definition at line 113 of file UGmodel_inl.h.

113 {
114 // family is the set of the note and its parent. So for a completely undirected model, it is
115 // just the node.
116 return gum::NodeSet{id};
117 }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

Referenced by family().

Here is the caller graph for this function:

◆ family() [2/2]

INLINE NodeSet gum::UGmodel::family ( std::string_view name) const
finalvirtualinherited

Implements gum::GraphicalModel.

Definition at line 119 of file UGmodel_inl.h.

119{ return family(idFromName(name)); }
NodeSet family(const NodeId id) const final
returns the node as a NodeSet (in mixed graph : family is the node and its parents

References family(), and gum::DiscreteGraphicalModel::idFromName().

Here is the call graph for this function:

◆ graph()

INLINE UndiGraph gum::UGmodel::graph ( ) const
nodiscardinherited

Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new graph. For a stable reference (listeners, long-lived pointers), use internalGraph().

Definition at line 61 of file UGmodel_inl.h.

61 {
62 UndiGraph g = graph_;
63 _nameNodes_(g);
64 return g;
65 }
void _nameNodes_(NodeGraphPart &g) const
Names every node of g using variable(id).name() for each node id in g.

References gum::GraphicalModel::_nameNodes_(), and graph_.

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

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

◆ hasSameStructure()

bool gum::UGmodel::hasSameStructure ( const UGmodel & other) const
inherited

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

Returns
true if all the named node are the same and all the named arcs are the same

Definition at line 82 of file UGmodel.cpp.

82 {
83 if (this == &other) return true;
84
85 if (size() != other.size()) return false;
86
87 if (sizeEdges() != other.sizeEdges()) return false;
88
89 for (const auto& nid: nodes()) {
90 if (!other.exists(variable(nid).name())) return false;
91 }
92
93 for (const auto& edge: edges()) {
94 if (!other.edges().exists(Edge(other.idFromName(variable(edge.first()).name()),
95 other.idFromName(variable(edge.second()).name()))))
96 return false;
97 }
98
99 return true;
100 }
const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variable given its node id.
const NodeGraphPart & nodes() const final
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
Definition UGmodel_inl.h:97
const EdgeSet & edges() const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:73
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Definition UGmodel_inl.h:71
Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition UGmodel_inl.h:68

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

Here is the call graph for this function:

◆ idFromName()

INLINE NodeId gum::DiscreteGraphicalModel::idFromName ( std::string_view name) const
overridevirtualinherited

◆ ids()

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

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(), and variableNodeMap().

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

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

◆ internalGraph()

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

Returns a const reference to the internal (unnamed) graph. O(1), no copy. Use for stable references or pointers (graph listeners). For named node access, use graph() instead.

Definition at line 58 of file UGmodel_inl.h.

58{ return graph_; }

References graph_.

◆ isIndependent() [1/4]

INLINE bool gum::UGmodel::isIndependent ( const NodeSet & X,
const NodeSet & Y,
const NodeSet & Z ) const
finalvirtualinherited

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

Implements gum::GraphicalModel.

Definition at line 105 of file UGmodel_inl.h.

105 {
106 return !graph_.hasUndirectedPath(X, Y, Z);
107 }

References graph_.

◆ isIndependent() [2/4]

INLINE bool gum::UGmodel::isIndependent ( const std::vector< std::string > & Xnames,
const std::vector< std::string > & Ynames,
const std::vector< std::string > & Znames ) const
inherited

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 127 of file UGmodel_inl.h.

129 {
130 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
131 }
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if X and Y are independent given Z

References isIndependent(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ isIndependent() [3/4]

INLINE bool gum::UGmodel::isIndependent ( NodeId X,
NodeId Y,
const NodeSet & Z ) const
finalvirtualinherited

check if X and Y are independent given Z

Implements gum::GraphicalModel.

Definition at line 101 of file UGmodel_inl.h.

101 {
102 return !graph_.hasUndirectedPath(X, Y, Z);
103 }

References graph_.

Referenced by isIndependent(), and isIndependent().

Here is the caller graph for this function:

◆ isIndependent() [4/4]

INLINE bool gum::UGmodel::isIndependent ( std::string_view Xname,
std::string_view Yname,
const std::vector< std::string > & Znames ) const
inherited

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 121 of file UGmodel_inl.h.

123 {
124 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
125 }

References gum::DiscreteGraphicalModel::idFromName(), isIndependent(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ log10DomainSize()

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

Definition at line 93 of file graphicalModel_inl.h.

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

References nodes().

Referenced by 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:

◆ maxNonOneParam()

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

Definition at line 140 of file IMarkovRandomField_tpl.h.

140 {
141 GUM_SCALAR res = 0.0;
142 for (auto elt: factors()) {
143 auto v = elt.second->maxNonOne();
144 if (v > res) { res = v; }
145 }
146 return res;
147 }

References factors().

Here is the call graph for this function:

◆ maxParam()

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

Definition at line 120 of file IMarkovRandomField_tpl.h.

120 {
121 GUM_SCALAR res = 1.0;
122 for (auto elt: factors()) {
123 auto v = elt.second->max();
124 if (v > res) { res = v; }
125 }
126 return res;
127 }

References factors().

Here is the call graph for this function:

◆ maxVarDomainSize()

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

Definition at line 100 of file IMarkovRandomField_tpl.h.

100 {
101 Size res = 0;
102 for (auto node: nodes()) {
103 auto v = variable(node).domainSize();
104 if (v > res) { res = v; }
105 }
106 return res;
107 }
virtual Size domainSize() const =0

References gum::UGmodel::nodes(), and gum::DiscreteGraphicalModel::variable().

Here is the call graph for this function:

◆ minimalCondSet() [1/2]

template<GUM_Numeric GUM_SCALAR>
NodeSet gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet ( const NodeSet & targets,
const NodeSet & soids ) const

Definition at line 349 of file IMarkovRandomField_tpl.h.

350 {
351 NodeSet res;
352 for (auto node: targets) {
354 }
355 return res;
356 }
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const

References minimalCondSet().

Here is the call graph for this function:

◆ minimalCondSet() [2/2]

template<GUM_Numeric GUM_SCALAR>
NodeSet gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet ( NodeId target,
const NodeSet & soids ) const

Definition at line 335 of file IMarkovRandomField_tpl.h.

336 {
337 if (soids.contains(target)) return NodeSet({target});
338
339 NodeSet res;
342
343 for (auto neig: graph_.neighbours(target))
345 return res;
346 }

References _minimalCondSetVisit_(), gum::Set< Key >::contains(), and gum::UGmodel::graph_.

Referenced by minimalCondSet().

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

◆ minNonZeroParam()

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

Definition at line 130 of file IMarkovRandomField_tpl.h.

130 {
131 GUM_SCALAR res = 1.0;
132 for (auto elt: factors()) {
133 auto v = elt.second->minNonZero();
134 if (v < res) { res = v; }
135 }
136 return res;
137 }

References factors().

Here is the call graph for this function:

◆ minParam()

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

Definition at line 110 of file IMarkovRandomField_tpl.h.

110 {
111 GUM_SCALAR res = 1.0;
112 for (auto elt: factors()) {
113 auto v = elt.second->min();
114 if (v < res) { res = v; }
115 }
116 return res;
117 }

References factors().

Here is the call graph for this function:

◆ names() [1/2]

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

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

References ids(), gum::VariableNodeMap::name(), and variableNodeMap().

Here is the call graph for this function:

◆ names() [2/2]

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

transform a vector of NodeId in a vector of names

Returns
the vector of names

Definition at line 117 of file graphicalModel_inl.h.

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

References ids().

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:

◆ 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 83 of file UGmodel_inl.h.

83{ return graph_.neighbours(id); }

References graph_.

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

Here is the caller graph for this function:

◆ neighbours() [2/2]

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

return true if the edge node1-node2 exists in the UGModel

Parameters
node1the nodeId (or the name) of the node1
node2the nodeId (or the name) of the node2
Returns
true if the edge exists

Definition at line 85 of file UGmodel_inl.h.

85 {
86 return neighbours(idFromName(name));
87 }
const NodeSet & neighbours(const NodeId id) const
returns the neighbours of a node as set of nodes
Definition UGmodel_inl.h:83

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

Here is the call graph for this function:

◆ nodeId()

INLINE NodeId gum::DiscreteGraphicalModel::nodeId ( const DiscreteVariable & var) const
overridevirtualinherited

Returns the NodeId of a variable.

Exceptions
NotFoundif no variable matches var.

Implements gum::GraphicalModel.

Reimplemented in gum::InfluenceDiagram< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Definition at line 56 of file discreteGraphicalModel_inl.h.

56 {
57 return varMap_.get(var);
58 }

References varMap_.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::clear(), gum::BayesBall::relevantTensors(), and gum::dSeparationAlgorithm::relevantTensors().

Here is the caller graph for this function:

◆ nodes()

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

Returns a named copy of the internal undirected graph: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new graph. For a stable reference (listeners, long-lived pointers), use internalGraph().

Implements gum::GraphicalModel.

Definition at line 97 of file UGmodel_inl.h.

97 {
98 return static_cast< const NodeGraphPart& >(graph_);
99 }

References graph_.

Referenced by hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::maxVarDomainSize(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().

Here is the caller graph for this function:

◆ nodeset()

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

transform a vector of names into a NodeSet

Returns
NodeSet

Definition at line 102 of file graphicalModel.cpp.

102 {
103 NodeSet res;
104 for (const auto& name: names) {
105 res.insert(idFromName(name));
106 }
107 return res;
108 }
virtual NodeId idFromName(std::string_view name) const =0
Getter by name.

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

Referenced by gum::BayesNet< double >::ancestors(), gum::DAGmodel::children(), gum::DAGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::DAGmodel::minimalCondSet(), and gum::DAGmodel::moralizedAncestralGraph().

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

◆ operator=()

template<GUM_Numeric GUM_SCALAR>
IMarkovRandomField< GUM_SCALAR > & gum::IMarkovRandomField< GUM_SCALAR >::operator= ( const IMarkovRandomField< GUM_SCALAR > & source)

Copy operator.

Definition at line 79 of file IMarkovRandomField_tpl.h.

79 {
80 if (this != &source) { UGmodel::operator=(source); }
81
82 return *this;
83 }
UGmodel & operator=(const UGmodel &source)
Private copy operator.
Definition UGmodel.cpp:62

References IMarkovRandomField(), and gum::UGmodel::operator=().

Here is the call graph for this function:

◆ operator==()

template<GUM_Numeric GUM_SCALAR>
bool gum::IMarkovRandomField< GUM_SCALAR >::operator== ( const IMarkovRandomField< 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 257 of file IMarkovRandomField_tpl.h.

257 {
258 if (size() != from.size()) { return false; }
259
260 if (sizeEdges() != from.sizeEdges()) { return false; }
261
262 // alignment of variables between the 2 BNs
264
265 for (auto node: nodes()) {
266 const auto& v1 = variable(node);
267 if (!from.exists(v1.name())) return false;
268 const auto& v2 = from.variableFromName(v1.name());
269 if (v1 != v2) return false;
270
271 alignment.insert(&variable(node), &from.variableFromName(v1.name()));
272 }
273
274 for (const auto& elt: factors()) {
275 const auto& key = elt.first;
276 const auto& factor = *elt.second;
277
279 for (const auto n: key)
280 fromkey.insert(from.idFromName(variable(n).name()));
281
282 if (!from.factors().exists(fromkey)) { return false; }
283
284 const auto& fromfactor = from.factor(fromkey);
285
288 for (i.setFirst(); !i.end(); i.inc()) {
289 for (Idx indice = 0; indice < factor.nbrDim(); ++indice) {
290 const DiscreteVariable* p = &(i.variable(indice));
291 j.chgVal(*(alignment.second(p)), i.val(*p));
292 }
293
294 if (std::pow(factor.get(i) - fromfactor.get(j), (GUM_SCALAR)2) > (GUM_SCALAR)1e-6) {
295 return false;
296 }
297 }
298 }
299 return true;
300 }
const DiscreteVariable & variableFromName(std::string_view name) const override
Returns a constant reference over a variable given its name.
virtual const Tensor< GUM_SCALAR > & factor(const NodeSet &varIds) const =0
Returns the factor of a set of variable.

References IMarkovRandomField(), gum::Instantiation::chgVal(), gum::Instantiation::end(), gum::UGmodel::exists(), factor(), factors(), gum::DiscreteGraphicalModel::idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Gen >::insert(), gum::Set< Key >::insert(), gum::UGmodel::nodes(), gum::BijectionImplementation< T1, T2, Gen >::second(), gum::Instantiation::setFirst(), gum::UGmodel::size(), gum::UGmodel::sizeEdges(), gum::Instantiation::val(), gum::DiscreteGraphicalModel::variable(), gum::Instantiation::variable(), and gum::DiscreteGraphicalModel::variableFromName().

Here is the call graph for this function:

◆ properties()

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

List of all the names of property in the Graphical model.

Definition at line 79 of file graphicalModel_inl.h.

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

References _propertiesMap_.

◆ property()

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

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 auto p = _properties_().tryGet(name);
62 if (!p) { GUM_ERROR(NotFound, "The following property does not exists: " << name) }
63 return *p;
64 }
const HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model.
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _properties_(), GUM_ERROR, and gum::HashTable< Key, Val >::tryGet().

Here is the call graph for this function:

◆ propertyWithDefault()

INLINE const std::string & gum::GraphicalModel::propertyWithDefault ( std::string_view 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 72 of file graphicalModel_inl.h.

73 {
74 auto p = _propertiesMap_.tryGet(name);
75 return p ? *p : byDefault;
76 }

References _propertiesMap_.

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

Here is the caller graph for this function:

◆ setProperty()

INLINE void gum::GraphicalModel::setProperty ( std::string_view name,
std::string_view value )
inherited

Add or change a property of this GraphicalModel.

Definition at line 87 of file graphicalModel_inl.h.

87 {
88 if (auto p = _propertiesMap_.tryGet(name)) *p = value;
89 else _propertiesMap_.insert(std::string(name), std::string(value));
90 }

References _propertiesMap_.

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

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 68 of file UGmodel_inl.h.

68{ return graph_.size(); }

References graph_.

Referenced by hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toString().

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 71 of file UGmodel_inl.h.

71{ return graph_.sizeEdges(); }

References graph_.

Referenced by hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), and gum::IMarkovRandomField< GUM_SCALAR >::toString().

Here is the caller graph for this function:

◆ smallestFactorFromNode() [1/2]

template<GUM_Numeric GUM_SCALAR>
virtual const NodeSet & gum::IMarkovRandomField< GUM_SCALAR >::smallestFactorFromNode ( NodeId node) const
pure virtual

Returns the smallest factor that contains this variable.

Exceptions
NotFoundIf no variable's id matches varId.

Referenced by smallestFactorFromNode().

Here is the caller graph for this function:

◆ smallestFactorFromNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
const NodeSet & gum::IMarkovRandomField< GUM_SCALAR >::smallestFactorFromNode ( std::string_view name) const
virtual

Returns the smallest factor that contains this variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 310 of file IMarkovRandomField_tpl.h.

310 {
311 if (!this->exists(name)) {
312 GUM_ERROR(NotFound, "No factor containing the variable <" << name << ">")
313 }
315 }
virtual const NodeSet & smallestFactorFromNode(NodeId node) const =0
Returns the smallest factor that contains this variable.

References gum::UGmodel::exists(), GUM_ERROR, gum::DiscreteGraphicalModel::idFromName(), and smallestFactorFromNode().

Here is the call graph for this function:

◆ spaceCplxToString()

std::string gum::GraphicalModel::spaceCplxToString ( double dSize,
int dim,
Size usedMem )
staticinherited

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

110 {
111 std::string result;
112 if (dSize > 6) result = std::format("domainSize: 10^{:.6g}", dSize);
113 else result = std::format("domainSize: {}", (long long)std::round(std::pow(10.0, dSize)));
114
115 result += std::format(", dim: {}, mem: ", dim);
116
117 if (const Size go = usedMem / (1024 * 1024 * 1024); go > 0) result += std::format("{}Go ", go);
118 if (const Size mo = (usedMem / (1024 * 1024)) % 1024; mo > 0)
119 result += std::format("{}Mo ", mo);
120 if (const Size ko = (usedMem / 1024) % 1024; ko > 0) result += std::format("{}Ko ", ko);
121 result += std::format("{}o", usedMem % 1024);
122 return result;
123 }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

◆ toDot()

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

Definition at line 169 of file IMarkovRandomField_tpl.h.

169 {
171
172 std::string mn_name = this->propertyWithDefault("name", "no_name");
173
174 output << std::format("graph \"{}\" {{\n", mn_name);
175 output << std::format(" graph [bgcolor=transparent,label=\"{}\"];\n", mn_name);
176 output << " node [style=filled fillcolor=\"#ffffaa\"];" << std::endl << std::endl;
177
178 for (auto node: nodes())
179 output << std::format(" \"{}\" [comment=\"{}:{}\"];\n",
180 variable(node).name(),
181 node,
183
184 output << std::endl;
185
186 std::string tab = " ";
187
188 for (auto node: nodes()) {
189 if (neighbours(node).size() > 0) {
190 for (auto nei: neighbours(node)) {
191 if (variable(node).name() < variable(nei).name()) {
192 output << std::format(" \"{}\" -- \"{}\";\n",
193 variable(node).name(),
194 variable(nei).name());
195 }
196 }
197 } else {
198 output << std::format(" \"{}\";\n", variable(node).name());
199 }
200 }
201
202 output << "}" << std::endl;
203
204 return output.str();
205 }
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.

References gum::UGmodel::neighbours(), gum::UGmodel::nodes(), gum::GraphicalModel::propertyWithDefault(), gum::UGmodel::size(), and gum::DiscreteGraphicalModel::variable().

Here is the call graph for this function:

◆ toDotAsFactorGraph()

template<GUM_Numeric GUM_SCALAR>
std::string gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph ( ) const
virtual
Returns
Returns a dot representation of this IMarkovRandomField.

Definition at line 208 of file IMarkovRandomField_tpl.h.

208 {
210 std::string mn_name = this->propertyWithDefault("name", "no_name");
211
212 output << std::format("graph FG_{} {{\n", mn_name);
213 output << " layout=neato;" << std::endl;
214 output << std::format(" graph [bgcolor=transparent,label=\"factor graph for {}\"];\n",
215 mn_name);
216
217 // the variables
218 output << " node [shape=rectangle,margin=0.04,width=0,height=0, "
219 "style=filled,color=\"coral\"];"
220 << std::endl;
221 for (auto nod: nodes()) {
222 output << std::format("\"{}\";\n", variable(nod).name());
223 }
224 output << std::endl;
225
226 // the factor
227 output << "node[shape = point,width = 0.1,height = 0.1,style = filled,color = "
228 "\"burlywood\"];"
229 << std::endl;
230 for (const auto& kv: factors()) {
231 output << " \"f";
232 for (NodeId nod: kv.first) {
233 output << "#" << variable(nod).name();
234 }
235 output << "\";" << std::endl;
236 }
237
238 // the link variable--factors
239 output << " edge[len = 0.7];" << std::endl;
240 for (const auto& kv: factors()) {
241 std::string clicname = "\"f";
242 for (NodeId nod: kv.first) {
243 clicname += "#";
245 }
246 clicname += "\"";
247
248 for (NodeId nod: kv.first)
249 output << std::format(" {} -- \"{}\";\n", clicname, variable(nod).name());
250 }
251 output << "}" << std::endl;
252
253 return output.str();
254 }
const std::string & name() const
returns the name of the variable

References factors(), gum::UGmodel::nodes(), gum::GraphicalModel::propertyWithDefault(), and gum::DiscreteGraphicalModel::variable().

Here is the call graph for this function:

◆ toString()

template<GUM_Numeric GUM_SCALAR>
std::string gum::IMarkovRandomField< GUM_SCALAR >::toString ( ) const
Returns
Returns a string representation of this IMarkovRandomField.

Definition at line 150 of file IMarkovRandomField_tpl.h.

150 {
151 Size param = 0;
152 double dSize = log10DomainSize();
153
154 for (auto factor: factors())
155 param += factor.second->content()->realSize();
156
158 s << std::format("MRF{{nodes: {}, edges: {}, ", size(), graph().sizeEdges());
159
160 if (dSize > 6) s << std::format("domainSize: 10^{}", dSize);
161 else s << std::format("domainSize: {}", std::round(std::pow(10.0, dSize)));
162
163 s << std::format(", dim: {}}}", param);
164
165 return s.str();
166 }
double log10DomainSize() const
UndiGraph graph() const
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
Definition UGmodel_inl.h:61

References factor(), factors(), gum::UGmodel::graph(), gum::GraphicalModel::log10DomainSize(), gum::UGmodel::size(), and gum::UGmodel::sizeEdges().

Referenced by gum::operator<<().

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

◆ updateMetaData()

void gum::GraphicalModel::updateMetaData ( )
inherited

update the meta data of this Graphical Model (version, creation date, last modification date) This method is called by the writers ONLY before writing the model to a file.

Definition at line 81 of file graphicalModel.cpp.

81 {
82 auto const time = std::chrono::time_point_cast< std::chrono::milliseconds >(
83 std::chrono::system_clock::now());
84 auto const currentdate = std::format("{:%Y-%m-%d %T}", time);
85
86 const std::string currentSoftware = "aGrUM " GUM_VERSION;
87 if (auto software = _propertiesMap_.tryGet("software")) {
88 *software = currentSoftware;
89 } else {
90 _propertiesMap_.insert("software", currentSoftware);
91 }
92
93 if (!_propertiesMap_.tryGet("creation")) { _propertiesMap_.insert("creation", currentdate); }
94
95 if (auto lastModification = _propertiesMap_.tryGet("lastModification")) {
96 *lastModification = currentdate;
97 } else {
98 _propertiesMap_.insert("lastModification", currentdate);
99 }
100 }

References _propertiesMap_.

◆ variable()

INLINE const DiscreteVariable & gum::DiscreteGraphicalModel::variable ( NodeId id) const
overridevirtualinherited

◆ variableFromName()

INLINE const DiscreteVariable & gum::DiscreteGraphicalModel::variableFromName ( std::string_view name) const
overridevirtualinherited

Returns a constant reference over a variable given its name.

Exceptions
NotFoundif no such name exists in the model.

Implements gum::GraphicalModel.

Reimplemented in gum::InfluenceDiagram< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Definition at line 66 of file discreteGraphicalModel_inl.h.

66 {
67 return varMap_.variableFromName(name);
68 }

References varMap_.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::clear(), gum::IBayesNet< GUM_SCALAR >::evEq(), gum::IBayesNet< GUM_SCALAR >::evGt(), gum::IBayesNet< GUM_SCALAR >::evIn(), gum::IBayesNet< GUM_SCALAR >::evLt(), gum::IBayesNet< GUM_SCALAR >::operator==(), and gum::IMarkovRandomField< GUM_SCALAR >::operator==().

Here is the caller graph for this function:

◆ variableNodeMap()

INLINE const VariableNodeMap & gum::DiscreteGraphicalModel::variableNodeMap ( ) const
overridevirtualinherited

Returns a constant reference to the VariableNodeMap of this model.

Implements gum::GraphicalModel.

Reimplemented in gum::InfluenceDiagram< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Definition at line 48 of file discreteGraphicalModel_inl.h.

48{ return varMap_; }

References varMap_.

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

Here is the caller graph for this function:

◆ variables() [1/2]

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

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

◆ variables() [2/2]

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

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 gum::Set< Key >::insert(), gum::VariableNodeMap::variableFromName(), and variableNodeMap().

Here is the call graph for this function:

Member Data Documentation

◆ _propertiesMap_

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

The properties of this Directed Graphical Model.

Definition at line 262 of file graphicalModel.h.

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

◆ graph_

◆ varMap_


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