aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
UGmodel_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 UndiGraph& UGmodel::graph() const { return graph_; }
58
59 INLINE
60 Size UGmodel::size() const { return graph().size(); }
61
62 INLINE
63 Size UGmodel::sizeEdges() const { return graph_.sizeEdges(); }
64
65 INLINE const EdgeSet& UGmodel::edges() const { return graph_.edges(); }
66
67 INLINE bool UGmodel::existsEdge(const NodeId node1, const NodeId node2) const {
68 return graph_.existsEdge(node1, node2);
69 }
70
71 INLINE bool UGmodel::existsEdge(const std::string& name1, const std::string& name2) const {
72 return existsEdge(idFromName(name1), idFromName(name2));
73 }
74
75 INLINE const NodeSet& UGmodel::neighbours(const NodeId id) const { return graph_.neighbours(id); }
76
77 INLINE const NodeSet& UGmodel::neighbours(const std::string& name) const {
78 return neighbours(idFromName(name));
79 }
80
81 INLINE bool UGmodel::exists(NodeId node) const { return graph_.exists(node); }
82
83 INLINE bool UGmodel::exists(const std::string& name) const {
84 try {
85 return exists(idFromName(name));
86 } catch ([[maybe_unused]] gum::NotFound& e) { return false; }
87 }
88
89 INLINE const NodeGraphPart& UGmodel::nodes() const { return (NodeGraphPart&)graph_; }
90
91 INLINE bool UGmodel::isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const {
92 return !graph().hasUndirectedPath(X, Y, Z);
93 }
94
95 INLINE bool UGmodel::isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const {
96 return !graph().hasUndirectedPath(X, Y, Z);
97 }
98
99 INLINE NodeSet UGmodel::family(const NodeId id) const {
100 // family is the set of the note and its parent. So for a completely undirected model, it is
101 // just the node.
102 return gum::NodeSet{id};
103 }
104
105 INLINE NodeSet UGmodel::family(const std::string& name) const { return family(idFromName(name)); }
106} /* namespace gum */
Class representing probabilistic undirected model.
bool hasUndirectedPath(NodeId n1, NodeId n2) const
return true if n1 and n2 are connected (by an undirected path) in the graph.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
Class for node sets in graph.
Size size() const
alias for sizeNodes
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 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
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
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
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 ...
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46