aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::UGmodel Class Reference

Virtual base class for PGMs using a undirected graph. More...

#include <agrum/base/graphicalModels/UGmodel.h>

Inheritance diagram for gum::UGmodel:
Collaboration diagram for gum::UGmodel:

Public Member Functions

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
 UGmodel ()
 Default constructor.
 ~UGmodel () override
 Destructor.
 UGmodel (const UGmodel &source)
 Copy constructor.
 UGmodel (UGmodel &&source)
 move constructor
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

UGmodeloperator= (const UGmodel &source)
 Private copy operator.
UGmodeloperator= (UGmodel &&source)
 move assignment operator
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

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

Private Attributes

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

Detailed Description

Virtual base class for PGMs using a undirected graph.

Definition at line 64 of file UGmodel.h.

Constructor & Destructor Documentation

◆ UGmodel() [1/3]

gum::UGmodel::UGmodel ( )

Default constructor.

Definition at line 49 of file UGmodel.cpp.

49{ GUM_CONSTRUCTOR(UGmodel); }
UGmodel()
Default constructor.
Definition UGmodel.cpp:49

References UGmodel().

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

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

◆ ~UGmodel()

gum::UGmodel::~UGmodel ( )
override

Destructor.

Definition at line 60 of file UGmodel.cpp.

60{ GUM_DESTRUCTOR(UGmodel); }

References UGmodel().

Here is the call graph for this function:

◆ UGmodel() [2/3]

gum::UGmodel::UGmodel ( const UGmodel & source)

Copy constructor.

Do nothing.

Definition at line 51 of file UGmodel.cpp.

51 : DiscreteGraphicalModel(from), graph_(from.graph_) {
52 GUM_CONS_CPY(UGmodel);
53 }
UndiGraph graph_
The DAG of this Directed Graphical Model.
Definition UGmodel.h:195

References gum::DiscreteGraphicalModel::DiscreteGraphicalModel(), UGmodel(), and graph_.

Here is the call graph for this function:

◆ UGmodel() [3/3]

gum::UGmodel::UGmodel ( UGmodel && source)

move constructor

Definition at line 55 of file UGmodel.cpp.

55 :
56 DiscreteGraphicalModel(std::move(from)), graph_(std::move(from.graph_)) {
57 GUM_CONS_MOV(UGmodel);
58 }

References gum::DiscreteGraphicalModel::DiscreteGraphicalModel(), UGmodel(), and graph_.

Here is the call graph for this function:

Member Function Documentation

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

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

◆ edges()

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

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
finalvirtual

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
finalvirtual

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

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

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

◆ family() [1/2]

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

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
finalvirtual

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
nodiscard

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

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

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
finalvirtual

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

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
finalvirtual

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

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:

◆ 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

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

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
finalvirtual

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=() [1/2]

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

Private copy operator.

Definition at line 62 of file UGmodel.cpp.

62 {
63 if (this != &source) {
65 graph_ = source.graph_;
66 GUM_OP_CPY(UGmodel);
67 }
68
69 return *this;
70 }
DiscreteGraphicalModel & operator=(const DiscreteGraphicalModel &source)

References UGmodel(), graph_, and gum::DiscreteGraphicalModel::operator=().

Referenced by gum::IMarkovRandomField< GUM_SCALAR >::operator=().

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

◆ operator=() [2/2]

UGmodel & gum::UGmodel::operator= ( UGmodel && source)
protected

move assignment operator

Definition at line 72 of file UGmodel.cpp.

72 {
73 if (this != &source) {
74 DiscreteGraphicalModel::operator=(std::move(source));
75 graph_ = std::move(source.graph_);
76 GUM_OP_MOV(UGmodel);
77 }
78
79 return *this;
80 }

References UGmodel(), graph_, and gum::DiscreteGraphicalModel::operator=().

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(), and gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype().

Here is the caller graph for this function:

◆ size()

INLINE Size gum::UGmodel::size ( ) const
finalvirtual

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

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:

◆ 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

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