aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DAGmodel.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_DAGMODEL_H
50#define GUM_DAGMODEL_H
51
52#include <agrum/agrum.h>
53
55
56namespace gum {
57
64 class DAGmodel: public GraphicalModel {
65 public:
68
72 DAGmodel();
73
77 virtual ~DAGmodel();
78
82 DAGmodel(const DAGmodel& source);
83
85
88
91 const DAG& dag() const;
92
96 virtual Size size() const final;
97
101 Size sizeArcs() const;
102
103 const NodeGraphPart& nodes() const final;
104
108 bool exists(NodeId node) const final;
109 bool exists(const std::string& name) const final;
110
112
115 const ArcSet& arcs() const;
116
118
124 bool existsArc(const NodeId tail, const NodeId head) const;
125 bool existsArc(const std::string& nametail, const std::string& namehead) const;
126
128
133 const NodeSet& parents(const NodeId id) const;
134 const NodeSet& parents(const std::string& name) const;
135
137 NodeSet parents(const NodeSet& ids) const;
138 NodeSet parents(const std::vector< std::string >& names) const;
139
141
145 NodeSet family(const NodeId id) const final;
146 NodeSet family(const std::string& name) const final;
147
149
154 const NodeSet& children(const NodeId id) const;
155 const NodeSet& children(const std::string& name) const;
156
158 NodeSet children(const NodeSet& ids) const;
159 NodeSet children(const std::vector< std::string >& names) const;
160
162
168 NodeSet descendants(const NodeId id) const;
169 NodeSet descendants(const std::string& name) const;
170
172
178 NodeSet ancestors(const NodeId id) const;
179 NodeSet ancestors(const std::string& name) const;
181
184
192 UndiGraph moralizedAncestralGraph(const std::vector< std::string >& nodenames) const;
193
196 bool isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const final;
197
200 bool isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const final;
201
202 bool isIndependent(const std::string& Xname,
203 const std::string& Yname,
204 const std::vector< std::string >& Znames) const {
205 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
206 };
207
208 bool isIndependent(const std::vector< std::string >& Xnames,
209 const std::vector< std::string >& Ynames,
210 const std::vector< std::string >& Znames) const {
211 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
212 };
213
217 UndiGraph moralGraph() const;
218
226
229 bool hasSameStructure(const DAGmodel& other);
230
231 /***
232 * @return the minimal subset of soids that conditions the target
233 *
234 * i.e. P(target| soids)=P(target|@return)
235 */
236 NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
237
238
239 /***
240 * @return the minimal subset of soids that conditions the targets
241 *
242 * i.e. P(targets| soids)=P(targets|@return)
243 */
244 NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
245
246
247 /***
248 * @return the minimal subset of soids that conditions the target
249 *
250 * i.e. P(target| soids)=P(target|@return)
251 */
252 NodeSet minimalCondSet(const std::string& target,
253 const std::vector< std::string >& soids) const;
254
255
256 /***
257 * @return the minimal subset of soids that conditions the targets
258 *
259 * i.e. P(targets| soids)=P(targets|@return)
260 */
261 NodeSet minimalCondSet(const std::vector< std::string >& targets,
262 const std::vector< std::string >& soids) const;
263
264
265 protected:
269 DAGmodel& operator=(const DAGmodel& source);
270
273 };
274} // namespace gum
275
276#ifndef GUM_NO_INLINE
278#endif /* GUM_NO_INLINE */
279
280#endif /* GUM_DAGMODEL_H */
Interface-like class encapsulating basic functionalities for a DAGModel.
Base class for dag.
Definition DAG.h:121
Virtual base class for PGMs using a DAG.
Definition DAGmodel.h:64
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
NodeSet family(const NodeId id) const final
returns the parents of a node and the node
DAG dag_
The DAG of this Directed Graphical Model.
Definition DAGmodel.h:272
DAGmodel()
Default constructor.
Definition DAGmodel.cpp:49
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Sequence< NodeId > topologicalOrder() const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel
bool hasSameStructure(const DAGmodel &other)
Definition DAGmodel.cpp:66
bool isIndependent(const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition DAGmodel.h:208
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition DAGmodel.cpp:55
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
UndiGraph moralGraph() const
The node's id are coherent with the variables and nodes of the topology.
Definition DAGmodel.cpp:64
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z
NodeSet descendants(const NodeId id) const
returns the set of nodes with directed path outgoing from a given node
virtual ~DAGmodel()
Destructor.
Definition DAGmodel.cpp:53
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
bool isIndependent(const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition DAGmodel.h:202
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
std::vector< std::string > names(const std::vector< NodeId > &ids) const
transform a vector of NodeId in a vector of names
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.
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
Size NodeId
Type for node ids.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46