aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
UGmodel.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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_UGMODEL_H
50#define GUM_UGMODEL_H
51
52#include <agrum/agrum.h>
53
55
56namespace gum {
57
64 class UGmodel: public GraphicalModel {
65 public:
68
72 UGmodel();
73
77 virtual ~UGmodel();
78
82 UGmodel(const UGmodel& source);
83
87
91
94 const UndiGraph& graph() const;
95
99 virtual Size size() const final;
100
104 Size sizeEdges() const;
105
106 const NodeGraphPart& nodes() const final;
107
111 bool exists(NodeId node) const final;
112 bool exists(const std::string& name) const final;
113
115
118 const EdgeSet& edges() const;
119
121
127 bool existsEdge(const NodeId node1, const NodeId node2) const;
128 bool existsEdge(const std::string& name1, const std::string& name2) const;
129
131
134 const NodeSet& neighbours(const NodeId id) const;
135 const NodeSet& neighbours(const std::string& name) const;
136
139 bool isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const final;
142 bool isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const final;
143
144 bool isIndependent(const std::string& Xname,
145 const std::string& Yname,
146 const std::vector< std::string >& Znames) const {
147 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
148 };
149
150 bool isIndependent(const std::vector< std::string >& Xnames,
151 const std::vector< std::string >& Ynames,
152 const std::vector< std::string >& Znames) const {
153 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
154 };
155
158 // virtual bool isIndependent(const NodeSet& X, const NodeSet& Y, const
159 // NodeSet& Z) const;
160
162
165 bool hasSameStructure(const UGmodel& other);
166
168
172 NodeSet family(const NodeId id) const final;
173 NodeSet family(const std::string& name) const final;
174
175 protected:
179 UGmodel& operator=(const UGmodel& source);
180
183 };
184} // namespace gum
185
186#ifndef GUM_NO_INLINE
188#endif /* GUM_NO_INLINE */
189
190#endif /* GUM_UGMODEL_H */
Interface-like class encapsulating basic functionalities for a IMarkovRandomFieldwork.
GraphicalModel()
Default constructor.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
Class for node sets in graph.
Virtual base class for PGMs using a undirected graph.
Definition UGmodel.h:64
virtual ~UGmodel()
Destructor.
Definition UGmodel.cpp:56
UGmodel()
Default constructor.
Definition UGmodel.cpp:49
NodeSet family(const NodeId id) const final
returns the the node as a NodeSet (in mixed graph : family is the node and its parents
Definition UGmodel_inl.h:99
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition UGmodel_inl.h:89
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
Definition UGmodel.h:150
UGmodel & operator=(const UGmodel &source)
Private copy operator.
Definition UGmodel.cpp:61
bool existsEdge(const NodeId node1, const NodeId node2) const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:67
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
Definition UGmodel_inl.h:81
UndiGraph graph_
The DAG of this Directed Graphical Model.
Definition UGmodel.h:182
bool hasSameStructure(const UGmodel &other)
check if nodes X and nodes Y are independent given nodes Z
Definition UGmodel.cpp:70
const EdgeSet & edges() const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:65
const UndiGraph & graph() const
Returns a constant reference to the dag of this Bayes Net.
Definition UGmodel_inl.h:57
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if X and Y are independent given Z
Definition UGmodel_inl.h:91
bool isIndependent(const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel.h:144
const NodeSet & neighbours(const NodeId id) const
returns the neighbours of a node as set of nodes
Definition UGmodel_inl.h:75
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Definition UGmodel_inl.h:63
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition UGmodel_inl.h:60
Base class for undirected graphs.
Definition undiGraph.h:128
Class representing probabilistic DAG model.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46