aGrUM 3.3.2
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 >:
[legend]
Collaboration diagram for gum::IMarkovRandomField< GUM_SCALAR >:
[legend]

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 toDot (const dot::DotOptions &options) const
virtual std::string toDotAsFactorGraph () const
virtual std::string toDotAsFactorGraph (const dot::DotOptions &options) 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< NodeId > connectedComponents () 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 UndiGraph & internalGraph () 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 NodeSet & smallestFactorFromNode (NodeId node) const =0
 Returns the smallest factor that contains this variable.
virtual const NodeSet & smallestFactorFromNode (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 NodeGraphPart & nodes () 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 EdgeSet & edges () 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 NodeSet & neighbours (const NodeId id) const
 returns the neighbours of a node as set of nodes
const NodeSet & neighbours (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 VariableNodeMap & variableNodeMap () const override
 Returns a constant reference to the VariableNodeMap of this model.
const DiscreteVariable & variable (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 DiscreteVariable & variableFromName (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< NodeId > ids (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 80 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 64 of file IMarkovRandomField_tpl.h.

64 : UGmodel() {
66 }
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 69 of file IMarkovRandomField_tpl.h.

69 : UGmodel() {
71 this->setProperty("name", name);
72 }
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 89 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 75 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 334 of file IMarkovRandomField_tpl.h.

337 {
338 if (alreadyVisited.contains(node)) return;
340
341 if (soids.contains(node)) {
342 minimal << node;
343 } else {
344 for (auto neig: graph_.neighbours(node))
346 }
347 }
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
const NodeSet & neighbours(const NodeId id) const
returns the neighbours of a node as set of nodes
Definition UGmodel_inl.h:83

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

Referenced by _minimalCondSetVisit_(), factors(), 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(), family(), gum::UGmodel::graph(), and gum::DAGmodel::moralGraph().

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

Referenced by nodes().

Here is the call graph for this function:
Here is the caller 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 {
111 }
NodeProperty< NodeId > connectedComponents() const
returns a property {node:id of weakly connected component}

References gum::UndiGraph::connectedComponents(), and graph_.

Here is the call graph for this function:

◆ 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 94 of file IMarkovRandomField_tpl.h.

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

References factors().

Referenced by factors().

Here is the call graph for this function:
Here is the caller 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(); }
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart

References gum::EdgeGraphPart::edges(), and graph_.

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

Here is the call graph for this function:
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(), gum::BayesNet< GUM_SCALAR >::clear(), and size().

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); }
bool exists(const NodeId id) const
alias for existsNode

References gum::NodeGraphPart::exists(), and graph_.

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

Here is the call graph for this function:
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 }
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists

References gum::EdgeGraphPart::existsEdge(), and graph_.

Referenced by existsEdge().

Here is the call graph for this function:
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 }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

References _propertiesMap_, and gum::HashTable< Key, Val >::exists().

Here is the call graph for this function:

◆ 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(), _minimalCondSetVisit_(), dim(), maxNonOneParam(), maxParam(), maxVarDomainSize(), minimalCondSet(), minNonZeroParam(), minParam(), operator==(), toDot(), toDotAsFactorGraph(), and toString().

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
const std::string & name() const
returns the name of the variable

References UGmodel(), edges(), gum::Set< Key >::exists(), exists(), gum::DiscreteGraphicalModel::idFromName(), gum::Variable::name(), 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

Returns the NodeId of 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 61 of file discreteGraphicalModel_inl.h.

61 {
62 return varMap_.idFromName(name);
63 }
VariableNodeMap varMap_
Mapping between NodeIds and discrete variables.
NodeId idFromName(std::string_view name) const

References gum::VariableNodeMap::idFromName(), and varMap_.

Referenced by gum::ASTposteriorProba< GUM_SCALAR >::_compute_knw_from_bn(), gum::DAGmodel::ancestors(), gum::InfluenceDiagram< GUM_SCALAR >::clear(), gum::DAGmodel::descendants(), gum::ASTjointProba< GUM_SCALAR >::eval(), gum::ASTposteriorProba< GUM_SCALAR >::eval(), gum::ASTsum< GUM_SCALAR >::eval(), gum::UGmodel::exists(), gum::DAGmodel::existsArc(), gum::UGmodel::existsEdge(), gum::DAGmodel::family(), gum::UGmodel::family(), gum::DAGmodel::hasSameStructure(), gum::MarkovBlanket::hasSameStructure(), gum::UGmodel::hasSameStructure(), gum::EssentialGraph::idFromName(), gum::UGmodel::isIndependent(), gum::UGmodel::neighbours(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::DAGmodel::parents(), and gum::IMarkovRandomField< GUM_SCALAR >::smallestFactorFromNode().

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

◆ 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 }
bool hasUndirectedPath(NodeId n1, NodeId n2) const
returns true if n1 and n2 are connected by an undirected path

References graph_, and gum::UndiGraph::hasUndirectedPath().

Here is the call graph for this function:

◆ 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_, and gum::UndiGraph::hasUndirectedPath().

Referenced by isIndependent(), and isIndependent().

Here is the call graph for this function:
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(), gum::InfluenceDiagram< GUM_SCALAR >::toString(), and variableFromName().

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 143 of file IMarkovRandomField_tpl.h.

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

References factors().

Referenced by factors().

Here is the call graph for this function:
Here is the caller 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 123 of file IMarkovRandomField_tpl.h.

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

References factors().

Referenced by factors().

Here is the call graph for this function:
Here is the caller 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 103 of file IMarkovRandomField_tpl.h.

103 {
104 Size res = 0;
105 for (auto node: nodes()) {
106 auto v = variable(node).domainSize();
107 if (v > res) { res = v; }
108 }
109 return res;
110 }

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

Referenced by factors().

Here is the call graph for this function:
Here is the caller 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 364 of file IMarkovRandomField_tpl.h.

365 {
366 NodeSet res;
367 for (auto node: targets) {
369 }
370 return res;
371 }
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 350 of file IMarkovRandomField_tpl.h.

351 {
352 if (soids.contains(target)) return NodeSet({target});
353
354 NodeSet res;
357
358 for (auto neig: graph_.neighbours(target))
360 return res;
361 }

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

Referenced by factors(), and 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 133 of file IMarkovRandomField_tpl.h.

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

References factors().

Referenced by factors().

Here is the call graph for this function:
Here is the caller 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 113 of file IMarkovRandomField_tpl.h.

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

References factors().

Referenced by factors().

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
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); }
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node

References graph_, and gum::EdgeGraphPart::neighbours().

Referenced by neighbours().

Here is the call graph for this function:
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 }

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 }
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it's node id.

References gum::VariableNodeMap::get(), and varMap_.

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

Here is the call graph for this function:
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::DAGmodel::children(), exists(), 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=()

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

Copy operator.

Definition at line 82 of file IMarkovRandomField_tpl.h.

82 {
83 if (this != &source) { UGmodel::operator=(source); }
84
85 return *this;
86 }
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 269 of file IMarkovRandomField_tpl.h.

269 {
270 if (size() != from.size()) { return false; }
271
272 if (sizeEdges() != from.sizeEdges()) { return false; }
273
274 // alignment of variables between the 2 BNs
276
277 for (auto node: nodes()) {
278 const auto& v1 = variable(node);
279 if (!from.exists(v1.name())) return false;
280 const auto& v2 = from.variableFromName(v1.name());
281 if (v1 != v2) return false;
282
283 alignment.insert(&variable(node), &from.variableFromName(v1.name()));
284 }
285
286 for (const auto& elt: factors()) {
287 const auto& key = elt.first;
288 const auto& factor = *elt.second;
289
291 for (const auto n: key)
292 fromkey.insert(from.idFromName(variable(n).name()));
293
294 if (!from.factors().exists(fromkey)) { return false; }
295
296 const auto& fromfactor = from.factor(fromkey);
297
300 // the tolerance applies to the squared difference: two values are equal when
301 // |a - b| <= sqrt(epsilonStandard), i.e. 1e-3 by default
302 const GUM_SCALAR tolerance = static_cast< GUM_SCALAR >(config().epsilonStandard());
303 for (i.setFirst(); !i.end(); i.inc()) {
304 for (Idx indice = 0; indice < factor.nbrDim(); ++indice) {
305 const DiscreteVariable* p = &(i.variable(indice));
306 j.chgVal(*(alignment.second(p)), i.val(*p));
307 }
308
309 if (std::pow(factor.get(i) - fromfactor.get(j), (GUM_SCALAR)2) > tolerance) {
310 return false;
311 }
312 }
313 }
314 return true;
315 }
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::config(), gum::Instantiation::end(), gum::Configuration::epsilonStandard(), 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().

Referenced by factors().

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
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_, and gum::HashTable< Key, Val >::tryGet().

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:

◆ 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 }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

References _propertiesMap_, gum::HashTable< Key, Val >::insert(), and gum::HashTable< Key, Val >::tryGet().

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 call graph for this function:
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(); }
Size size() const
alias for sizeNodes

References graph_, and gum::NodeGraphPart::size().

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

Here is the call graph for this function:
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(); }
Size sizeEdges() const
indicates the number of edges stored within the EdgeGraphPart

References graph_, and gum::EdgeGraphPart::sizeEdges().

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

Here is the call graph for this function:
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.

References smallestFactorFromNode().

Referenced by smallestFactorFromNode(), and smallestFactorFromNode().

Here is the call graph for this function:
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 325 of file IMarkovRandomField_tpl.h.

325 {
326 if (!this->exists(name)) {
327 GUM_ERROR(NotFound, "No factor containing the variable <" << name << ">")
328 }
330 }
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
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

Referenced by isIndependent().

Here is the caller graph for this function:

◆ toDot() [1/2]

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

Definition at line 172 of file IMarkovRandomField_tpl.h.

172 {
173 return toDot(dot::DotOptions());
174 }
virtual std::string toDot() const

References toDot().

Referenced by factors(), and toDot().

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

◆ toDot() [2/2]

template<GUM_Numeric GUM_SCALAR>
std::string gum::IMarkovRandomField< GUM_SCALAR >::toDot ( const dot::DotOptions & options) const
virtual
Returns
Returns a dot representation of this IMarkovRandomField (its graph of variables), with the options given by the caller. The variables are nodes named after the variables, with the tooltip "(id) name" ; the options are indexed by the identifiers of the nodes and the edges.

Definition at line 177 of file IMarkovRandomField_tpl.h.

177 {
178 const auto style = dot::DotStyle::read();
179 dot::DotWriter writer(false, this->propertyWithDefault("name", ""));
181
182 for (const auto node: nodes()) {
183 const auto& name = variable(node).name();
184 writer.node(name,
186 options.node(node),
187 "",
188 "(" + std::to_string(node) + ") " + name));
189 }
190
191 for (const auto& edge: edges()) {
192 auto attributes = dot::arcAttributes(options.edge(edge.first(), edge.second()));
194 "tooltip",
195 std::to_string(edge.first()) + "&nbsp;&mdash;&nbsp;"
196 + std::to_string(edge.second()));
197 dot::addDefaultAttribute(attributes, "fontsize", "10");
198 writer.edge(variable(edge.first()).name(), variable(edge.second()).name(), attributes);
199 }
200
201 return writer.str();
202 }
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.
void writePreamble(DotWriter &writer, const DotStyle &style, const DotOptions &options, std::string_view defaultLabel)
Writes the beginning of a graph, as pyAgrum displays it.
void addDefaultAttribute(DotAttributes &attributes, std::string_view key, std::string_view value)
Adds an attribute at the beginning of the list, unless the list already gives a value for this key : ...
DotAttributes arcAttributes(const DotArcOptions *options)
The attributes of an arc or an edge given by the options : color, penwidth, label,...
static DotStyle read()
the style of the graphs of the section notebook
Definition dotStyle.cpp:89

References gum::dot::addDefaultAttribute(), gum::dot::arcAttributes(), gum::dot::DotOptions::edge(), gum::dot::DotWriter::edge(), gum::UGmodel::edges(), gum::dot::DotOptions::node(), gum::dot::DotWriter::node(), gum::dot::nodeAttributes(), gum::UGmodel::nodes(), gum::GraphicalModel::propertyWithDefault(), gum::dot::DotStyle::read(), gum::dot::DotWriter::str(), gum::DiscreteGraphicalModel::variable(), and gum::dot::writePreamble().

Here is the call graph for this function:

◆ toDotAsFactorGraph() [1/2]

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

Definition at line 205 of file IMarkovRandomField_tpl.h.

205 {
207 }
virtual std::string toDotAsFactorGraph() const

References toDotAsFactorGraph().

Referenced by factors(), and toDotAsFactorGraph().

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

◆ toDotAsFactorGraph() [2/2]

template<GUM_Numeric GUM_SCALAR>
std::string gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph ( const dot::DotOptions & options) const
virtual
Returns
Returns a dot representation of this IMarkovRandomField as a factor graph, with the options given by the caller : the options of the nodes are the ones of the variables, the options of a factor are given for the identifiers of its variables.

Definition at line 211 of file IMarkovRandomField_tpl.h.

211 {
213 dot::DotWriter writer(false, this->propertyWithDefault("name", ""));
215 writer.edgeDefaults({{"len", dot::DotWriter::number(style.edgeLength)}});
216
217 // the variables
218 for (const auto node: nodes()) {
219 const auto& name = variable(node).name();
221 options.node(node),
222 "",
223 "(" + std::to_string(node) + ") " + name);
224 dot::addDefaultAttribute(attributes, "height", "0");
226 dot::addDefaultAttribute(attributes, "margin", "0.04");
227 dot::addDefaultAttribute(attributes, "shape", "rectangle");
228 writer.node(name, attributes);
229 }
230
231 // the factors, in the order of the identifiers of their variables
233 for (const auto& kv: factors()) {
234 std::vector< NodeId > scope(kv.first.begin(), kv.first.end());
235 std::sort(scope.begin(), scope.end());
236 scopes.push_back(std::move(scope));
237 }
238 std::sort(scopes.begin(), scopes.end());
239
240 auto factorName = [this](const std::vector< NodeId >& scope) {
241 std::string name = "f";
242 for (const auto node: scope)
243 name += "#" + variable(node).name();
244 return name;
245 };
246
247 // a factor is a point, whose font color is adaptive against its own background
248 auto factorStyle = static_cast< dot::DotStyle >(style);
249 factorStyle.nodeBgColor = style.factorBgColor;
250 for (const auto& scope: scopes) {
252 dot::addDefaultAttribute(attributes, "height", "0.1");
253 dot::addDefaultAttribute(attributes, "width", "0.1");
254 dot::addDefaultAttribute(attributes, "shape", "point");
255 dot::addDefaultAttribute(attributes, "fontcolor", style.factorFgColor);
256 dot::addDefaultAttribute(attributes, "fillcolor", style.factorBgColor);
258 }
259
260 // the links variable -- factor
261 for (const auto& scope: scopes)
262 for (const auto node: scope)
264
265 return writer.str();
266 }
static std::string number(double value)
The shortest text that reads back as value (0.5, 1, 1e-05).
Definition dotWriter.cpp:93
DotAttributes nodeAttributes(const DotStyle &style, const DotNodeOptions *options, std::string_view defaultLabel, std::string_view defaultTooltip)
The attributes of a node : its label and tooltip, and its colors if the options give some.
static FactorGraphDotStyle read()
Definition dotStyle.cpp:120

References gum::dot::addDefaultAttribute(), gum::dot::DotWriter::edge(), gum::dot::DotWriter::edgeDefaults(), gum::dot::DotOptions::factor(), factors(), gum::dot::DotOptions::node(), gum::dot::DotWriter::node(), gum::dot::nodeAttributes(), gum::dot::DotStyle::nodeBgColor, gum::UGmodel::nodes(), gum::dot::DotWriter::number(), gum::GraphicalModel::propertyWithDefault(), gum::dot::FactorGraphDotStyle::read(), gum::dot::DotWriter::str(), gum::DiscreteGraphicalModel::variable(), and gum::dot::writePreamble().

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 153 of file IMarkovRandomField_tpl.h.

153 {
154 Size param = 0;
155 double dSize = log10DomainSize();
156
157 for (auto factor: factors())
158 param += factor.second->content()->realSize();
159
161 s << std::format("MRF{{nodes: {}, edges: {}, ", size(), graph().sizeEdges());
162
163 if (dSize > 6) s << std::format("domainSize: 10^{}", dSize);
164 else s << std::format("domainSize: {}", std::round(std::pow(10.0, dSize)));
165
166 s << std::format(", dim: {}}}", param);
167
168 return s.str();
169 }
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 factors(), and 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_, gum::HashTable< Key, Val >::insert(), and gum::HashTable< Key, Val >::tryGet().

Here is the call graph for this function:

◆ variable()

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

Returns a constant reference over a variable given its node id.

Exceptions
NotFoundif no variable's id matches id.

Implements gum::GraphicalModel.

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

Definition at line 51 of file discreteGraphicalModel_inl.h.

51 {
52 return varMap_.get(id);
53 }

References gum::VariableNodeMap::get(), and varMap_.

Referenced by gum::Estimator< GUM_SCALAR >::Estimator(), gum::EssentialGraph::_buildEssentialGraph_(), gum::ASTposteriorProba< GUM_SCALAR >::_compute_knw_from_bn(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_insertEvidence_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_verticesSampling_(), gum::IBayesNet< GUM_SCALAR >::check(), gum::InfluenceDiagram< GUM_SCALAR >::clear(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::ASTsum< GUM_SCALAR >::eval(), gum::DAGmodel::hasSameStructure(), gum::MarkovBlanket::hasSameStructure(), gum::UGmodel::hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IMarkovRandomField< GUM_SCALAR >::maxVarDomainSize(), gum::EssentialGraph::nameFromId(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::EssentialGraph::skeleton(), gum::EssentialGraph::toDot(), gum::IMarkovRandomField< GUM_SCALAR >::toDot(), gum::MarkovBlanket::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().

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

◆ 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 }
const DiscreteVariable & variableFromName(std::string_view name) const

References gum::VariableNodeMap::variableFromName(), and 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 call graph for this function:
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(), and gum::DAGmodel::exists().

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

Referenced by exists().

Here is the call graph for this function:
Here is the caller 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: