aGrUM 3.1.1
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-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#pragma once
42
43
51
53
55
56namespace gum {
57 INLINE
58 const UndiGraph& UGmodel::internalGraph() const { return graph_; }
59
60 INLINE
62 UndiGraph g = graph_;
63 _nameNodes_(g);
64 return g;
65 }
66
67 INLINE
68 Size UGmodel::size() const { return graph_.size(); }
69
70 INLINE
71 Size UGmodel::sizeEdges() const { return graph_.sizeEdges(); }
72
73 INLINE const EdgeSet& UGmodel::edges() const { return graph_.edges(); }
74
75 INLINE bool UGmodel::existsEdge(const NodeId node1, const NodeId node2) const {
76 return graph_.existsEdge(node1, node2);
77 }
78
79 INLINE bool UGmodel::existsEdge(std::string_view name1, std::string_view name2) const {
80 return existsEdge(idFromName(name1), idFromName(name2));
81 }
82
83 INLINE const NodeSet& UGmodel::neighbours(const NodeId id) const { return graph_.neighbours(id); }
84
85 INLINE const NodeSet& UGmodel::neighbours(std::string_view name) const {
86 return neighbours(idFromName(name));
87 }
88
89 INLINE bool UGmodel::exists(NodeId node) const { return graph_.exists(node); }
90
91 INLINE bool UGmodel::exists(std::string_view name) const {
92 try {
93 return exists(idFromName(name));
94 } catch ([[maybe_unused]] gum::NotFound& e) { return false; }
95 }
96
97 INLINE const NodeGraphPart& UGmodel::nodes() const {
98 return static_cast< const NodeGraphPart& >(graph_);
99 }
100
101 INLINE bool UGmodel::isIndependent(NodeId X, NodeId Y, const NodeSet& Z) const {
102 return !graph_.hasUndirectedPath(X, Y, Z);
103 }
104
105 INLINE bool UGmodel::isIndependent(const NodeSet& X, const NodeSet& Y, const NodeSet& Z) const {
106 return !graph_.hasUndirectedPath(X, Y, Z);
107 }
108
110 return graph_.connectedComponents();
111 }
112
113 INLINE NodeSet UGmodel::family(const NodeId id) const {
114 // family is the set of the note and its parent. So for a completely undirected model, it is
115 // just the node.
116 return gum::NodeSet{id};
117 }
118
119 INLINE NodeSet UGmodel::family(std::string_view name) const { return family(idFromName(name)); }
120
121 INLINE bool UGmodel::isIndependent(std::string_view Xname,
122 std::string_view Yname,
123 const std::vector< std::string >& Znames) const {
124 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
125 }
126
127 INLINE bool UGmodel::isIndependent(const std::vector< std::string >& Xnames,
128 const std::vector< std::string >& Ynames,
129 const std::vector< std::string >& Znames) const {
130 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
131 }
132
133} /* namespace gum */
Class representing probabilistic undirected model.
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.
void _nameNodes_(NodeGraphPart &g) const
Names every node of g using variable(id).name() for each node id in g.
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
Class for node sets in graph.
NodeSet family(const NodeId id) const final
returns the node as a NodeSet (in mixed graph : family is the node and its parents
const NodeGraphPart & nodes() const final
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
Definition UGmodel_inl.h:97
bool existsEdge(const NodeId node1, const NodeId node2) const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:75
const UndiGraph & internalGraph() const
Returns a const reference to the internal (unnamed) graph. O(1), no copy. Use for stable references o...
Definition UGmodel_inl.h:58
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
Definition UGmodel_inl.h:89
UndiGraph graph_
The DAG of this Directed Graphical Model.
Definition UGmodel.h:195
const EdgeSet & edges() const
return true if the edge node1-node2 exists in the UGModel
Definition UGmodel_inl.h:73
UndiGraph graph() const
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
Definition UGmodel_inl.h:61
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if X and Y are independent given Z
const NodeSet & neighbours(const NodeId id) const
returns the neighbours of a node as set of nodes
Definition UGmodel_inl.h:83
NodeProperty< NodeId > connectedComponents() const
Returns the connected components of the underlying undirected graph. Each node maps to the id of its ...
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Definition UGmodel_inl.h:71
Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition UGmodel_inl.h:68
Base class for undirected graphs.
Definition undiGraph.h:130
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.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
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