aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
graphicalModel.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49#ifndef GUM_GRAPHICALMODEL_H
50#define GUM_GRAPHICALMODEL_H
51#include <agrum/agrum.h>
52
56
57namespace gum {
65 public:
68
73
77 virtual ~GraphicalModel();
78
82 GraphicalModel(const GraphicalModel& source);
83
87 GraphicalModel(GraphicalModel&& source) noexcept;
88
92
97 const std::string& property(std::string_view name) const;
98
103 const std::string& propertyWithDefault(std::string_view name,
104 const std::string& byDefault) const;
105
109 void setProperty(std::string_view name, std::string_view value);
110
114 std::vector< std::string > properties() const;
115
119 bool existsProperty(std::string_view name) const;
120
125 void updateMetaData();
126
130
134 virtual const VariableNodeMap& variableNodeMap() const = 0;
135
139 virtual Size size() const = 0;
140
144 virtual bool empty() const;
145
149 virtual bool exists(NodeId node) const = 0;
150 virtual bool exists(std::string_view name) const = 0;
151
156 std::vector< std::string > names(const std::vector< NodeId >& ids) const;
157
162 std::vector< std::string > names(const NodeSet& ids) const;
163
168 std::vector< NodeId > ids(const std::vector< std::string >& names) const;
169
174 NodeSet nodeset(const std::vector< std::string >& names) const;
175
180 gum::VariableSet variables(const std::vector< std::string >& l) const;
181
187
188 virtual const NodeGraphPart& nodes() const = 0;
189
192
197 virtual const DiscreteVariable& variable(NodeId id) const = 0;
198
203 virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
204
207 virtual NodeId idFromName(std::string_view name) const = 0;
208
211 virtual const DiscreteVariable& variableFromName(std::string_view name) const = 0;
212
214
215 double log10DomainSize() const;
216
219 virtual bool isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const = 0;
220
223 virtual bool isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const = 0;
224
225
233 static std::string spaceCplxToString(double dSize, int dim, Size usedMem);
234
236
240 virtual NodeSet family(const NodeId id) const = 0;
241 virtual NodeSet family(std::string_view name) const = 0;
242
243 protected:
248
252 GraphicalModel& operator=(GraphicalModel&& source) noexcept;
253
258 void _nameNodes_(NodeGraphPart& g) const;
259
260 private:
263
266 };
267} // namespace gum
268
269#ifndef GUM_NO_INLINE
271#endif /* GUM_NO_INLINE */
272
273#endif /* GUM_GRAPHICALMODEL_H */
Base classes for directed acyclic graphs.
Base class for discrete random variable.
const HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model.
virtual ~GraphicalModel()
Destructor.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
const std::string & property(std::string_view name) const
Return the value of the property name of this GraphicalModel.
void _nameNodes_(NodeGraphPart &g) const
Names every node of g using variable(id).name() for each node id in g.
GraphicalModel & operator=(const GraphicalModel &source)
Private copy operator.
void setProperty(std::string_view name, std::string_view value)
Add or change a property of this GraphicalModel.
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual NodeSet family(const NodeId id) const =0
returns the family of a noe (parents or neighbours) of a node and the node
HashTable< std::string, std::string > _propertiesMap_
The properties of this Directed Graphical Model.
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
void updateMetaData()
update the meta data of this Graphical Model (version, creation date, last modification date) This me...
virtual const NodeGraphPart & nodes() const =0
Returns the number of variables in this Directed Graphical Model.
virtual const DiscreteVariable & variableFromName(std::string_view name) const =0
Getter by name.
std::vector< std::string > names(const std::vector< NodeId > &ids) const
transform a vector of NodeId in a vector of names
virtual bool exists(std::string_view name) const =0
Returns the number of variables in this Directed Graphical Model.
GraphicalModel()
Default constructor.
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
gum::VariableSet variables(const std::vector< std::string > &l) const
transform a vector of names into a VariableeSet
virtual bool isIndependent(const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const =0
check if nodes X and nodes Y are independent given nodes Z
virtual bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const =0
check if node X and node Y are independent given nodes Z
virtual NodeId idFromName(std::string_view name) const =0
Getter by name.
double log10DomainSize() const
std::vector< std::string > properties() const
List of all the names of property in the Graphical model.
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.
Instantiation completeInstantiation() const
Get an instantiation over all the variables of the model.
virtual bool empty() const
Return true if this graphical model is empty.
virtual NodeSet family(std::string_view name) const =0
bool existsProperty(std::string_view name) const
check wether a property exists in this GraphicalModel
static std::string spaceCplxToString(double dSize, int dim, Size usedMem)
send to the stream the space complexity with 3 parametrs
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.
Class for assigning/browsing values to tuples of discrete variables.
Class for node sets in graph.
Container used to map discrete variables with nodes.
Interface-like class encapsulating basic functionalities for both a IBayesNet and IMarkovRandomField.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Header files of gum::Instantiation.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Header of class VariableNodeMap.