aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DAGmodel_inl.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#pragma once
41
42
50
52
54
55namespace gum {
56 INLINE
57 const DAG& DAGmodel::dag() const { return dag_; }
58
59 INLINE
60 Size DAGmodel::size() const { return dag().size(); }
61
62 INLINE
63 Size DAGmodel::sizeArcs() const { return dag_.sizeArcs(); }
64
65 INLINE const ArcSet& DAGmodel::arcs() const { return dag_.arcs(); }
66
67 INLINE bool DAGmodel::existsArc(const NodeId tail, const NodeId head) const {
68 return dag_.existsArc(tail, head);
69 }
70
71 INLINE bool DAGmodel::existsArc(const std::string& nametail, const std::string& namehead) const {
72 return existsArc(idFromName(nametail), idFromName(namehead));
73 }
74
75 INLINE const NodeSet& DAGmodel::parents(const NodeId id) const { return dag_.parents(id); }
76
77 INLINE const NodeSet& DAGmodel::parents(const std::string& name) const {
78 return parents(idFromName(name));
79 }
80
81 INLINE NodeSet DAGmodel::family(const NodeId id) const { return dag_.family(id); }
82
83 INLINE NodeSet DAGmodel::family(const std::string& name) const {
84 return dag_.family(idFromName(name));
85 }
86
87 INLINE const NodeSet& DAGmodel::children(const NodeId id) const { return dag_.children(id); }
88
89 INLINE const NodeSet& DAGmodel::children(const std::string& name) const {
90 return dag_.children(idFromName(name));
91 }
92
93 INLINE NodeSet DAGmodel::children(const NodeSet& ids) const { return dag_.children(ids); }
94
95 INLINE NodeSet DAGmodel::children(const std::vector< std::string >& names) const {
97 }
98
99 INLINE NodeSet DAGmodel::parents(const NodeSet& ids) const { return dag_.children(ids); }
100
101 INLINE NodeSet DAGmodel::parents(const std::vector< std::string >& names) const {
102 return parents(nodeset(names));
104
105 INLINE bool DAGmodel::exists(NodeId node) const { return dag_.exists(node); }
106
107 INLINE bool DAGmodel::exists(const std::string& name) const {
108 try {
109 return exists(idFromName(name));
110 } catch ([[maybe_unused]] gum::NotFound& e) { return false; }
111 }
112
113 INLINE const NodeGraphPart& DAGmodel::nodes() const { return (NodeGraphPart&)dag_; }
114
116
117 INLINE NodeSet DAGmodel::descendants(const NodeId id) const { return dag().descendants(id); }
118
119 INLINE NodeSet DAGmodel::descendants(const std::string& name) const {
120 return descendants(idFromName(name));
121 }
122
123 INLINE NodeSet DAGmodel::ancestors(const NodeId id) const { return dag().ancestors(id); }
125 INLINE NodeSet DAGmodel::ancestors(const std::string& name) const {
126 return ancestors(idFromName(name));
127 }
128
129 INLINE UndiGraph
130 DAGmodel::moralizedAncestralGraph(const std::vector< std::string >& nodenames) const {
131 return moralizedAncestralGraph(nodeset(nodenames));
132 }
138 INLINE bool DAGmodel::isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const {
139 return dag().dSeparation(X, Y, Z);
140 }
141
142 INLINE bool DAGmodel::isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const {
143 return dag().dSeparation(X, Y, Z);
144 }
146 INLINE NodeSet DAGmodel::minimalCondSet(NodeId target, const NodeSet& soids) const {
147 return dag_.minimalCondSet(target, soids);
148 }
149
150 INLINE NodeSet DAGmodel::minimalCondSet(const NodeSet& targets, const NodeSet& soids) const {
151 return dag_.minimalCondSet(targets, soids);
152 }
153
154 INLINE NodeSet DAGmodel::minimalCondSet(const std::string& target,
155 const std::vector< std::string >& soids) const {
156 return dag_.minimalCondSet(idFromName(target), nodeset(soids));
157 }
159 INLINE NodeSet DAGmodel::minimalCondSet(const std::vector< std::string >& targets,
160 const std::vector< std::string >& soids) const {
161 return dag_.minimalCondSet(nodeset(targets), nodeset(soids));
162 }
163
164
165} /* namespace gum */
Class representing probabilistic DAG model.
NodeSet descendants(NodeId id) const
returns the set of nodes with directed path outgoing from a given node
NodeSet ancestors(NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Base class for dag.
Definition DAG.h:121
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation)
Definition DAG.cpp:117
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition DAG.cpp:91
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
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
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
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
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
bool exists(const std::string &name) const final
Returns a constant reference to the dag of this Bayes Net.
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.
Definition diGraph.cpp:111
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
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.
Size size() const
alias for sizeNodes
Base class for undirected graphs.
Definition undiGraph.h:128
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 ...
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46