aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
simplicialSet.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
48#ifndef GUM_SIMPLICIAL_SET_H
49#define GUM_SIMPLICIAL_SET_H
50
51#include <iostream>
52#include <utility>
53
54#include <agrum/agrum.h>
55
58
59#define GUM_QUASI_RATIO 0.99
60#define GUM_WEIGHT_THRESHOLD 0.0
61
62namespace gum {
63
64 /* ===========================================================================
65 */
66 /* === CLASS FOR RETRIEVING SIMPLICIAL, ALMOST AND QUASI SIMPLICIAL NODES ===
67 */
68 /* ===========================================================================
69 */
77 /* ===========================================================================
78 */
80 public:
81 // ############################################################################
83 // ############################################################################
85
87
124 explicit SimplicialSet(UndiGraph* graph,
125 const NodeProperty< double >* log_domain_sizes,
126 NodeProperty< double >* log_weights,
127 double theRatio = GUM_QUASI_RATIO,
128 double theThreshold = GUM_WEIGHT_THRESHOLD);
129
131
169 SimplicialSet(const SimplicialSet& simplicial_from,
170 UndiGraph* graph,
171 const NodeProperty< double >* log_domain_sizes,
172 NodeProperty< double >* log_weights,
173 bool avoid_check = false);
174
177
180
182
183 // ############################################################################
185 // ############################################################################
187
190
191 void makeClique(const NodeId id);
192
194
199 void eraseClique(const NodeId id);
200
202
206 void eraseNode(const NodeId id);
207
209
212 void eraseEdge(const Edge& edge);
213
215
221 void addEdge(NodeId first, NodeId second);
222
224
227 bool isSimplicial(const NodeId id);
228
230
233
236
239
241
244
246
249
252
254
257
260
262
265
267
271 void setFillIns(bool on_off);
272
274 const EdgeSet& fillIns() const;
275
277
303 void setGraph(UndiGraph* graph,
304 const NodeProperty< double >* log_domain_sizes,
305 NodeProperty< double >* log_weights,
306 double theRatio = GUM_QUASI_RATIO,
307 double theThreshold = GUM_WEIGHT_THRESHOLD);
308
310
314 NodeProperty< double >* new_weights);
315
317
318
319 private:
322
325
328
331
334
337
342
346
349
351
359
364
368
371
375
378
379
382 void _updateList_(const NodeId id);
383
386
394
396
402
404
409 };
410
411} /* namespace gum */
412
413#ifndef GUM_NO_INLINE
415#endif /* GUM_NO_INLINE */
416
417#endif /* GUM_SIMPLICIAL_SET_H */
The base class for all undirected edges.
const PriorityQueue< NodeId, double > & allSimplicialNodes()
returns all the simplicial nodes
void addEdge(NodeId first, NodeId second)
adds a new edge to the graph and recomputes the simplicial set
void _updateList_(const NodeId id)
put node id in the correct simplicial/almost simplicial/quasi simplicial list
NodeId bestSimplicialNode()
returns the simplicial node with the lowest clique weight
NodeProperty< Size > _nb_adjacent_neighbours_
for each node, the number of pairs of adjacent neighbours
SimplicialSet(const SimplicialSet &)
prevent the default copy constructor
NodeProperty< _Belong_ > _containing_list_
bool hasSimplicialNode()
indicates whether there exists a simplicial node
void _updateAllNodes_()
put all the nodes in their appropriate list
bool hasAlmostSimplicialNode()
indicates whether there exists an almost simplicial node
SimplicialSet(const SimplicialSet &simplicial_from, UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, bool avoid_check=false)
copy constructor
SimplicialSet(UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
constructor. initializes the simplicial set w.r.t. a given graph
_Belong_
indicates for each node to which list (simplicial, almost simplicial, quasi simplicial) it belongs
bool isSimplicial(const NodeId id)
indicates whether a given node is a simplicial node
NodeId bestAlmostSimplicialNode()
gets the almost simplicial node with the lowest clique weight
SimplicialSet(SimplicialSet &&from)
move constructor
const PriorityQueue< NodeId, double > & allQuasiSimplicialNodes()
returns all the quasi simplicial nodes
const NodeProperty< double > * _log_domain_sizes_
the log of the modalities of the nodes
NodeId bestQuasiSimplicialNode()
gets a quasi simplicial node with the lowest clique weight
EdgeProperty< Size > _nb_triangles_
for each edge, keep track of the number of triangles passing through this egde
const PriorityQueue< NodeId, double > & allAlmostSimplicialNodes()
returns all the almost simplicial nodes
void makeClique(const NodeId id)
adds the necessary edges so that node 'id' and its neighbors form a clique
double _quasi_ratio_
for a given node, if the number of pairs of neighbors that are adjacent / the number of adjacent neig...
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method
void eraseNode(const NodeId id)
removes a node and its adjacent edges from the underlying graph
PriorityQueue< NodeId, double > _almost_simplicial_nodes_
a queue of the almost simplicial nodes ordered by increasing node weight
~SimplicialSet()
destructor
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques' log weights (with the same content)
double _log_threshold_
quasi and almost simplicial nodes may not be eliminated unless their weight is lower than (1 + thresh...
void eraseClique(const NodeId id)
removes a node and its adjacent edges from the underlying graph
PriorityQueue< NodeId, double > _quasi_simplicial_nodes_
a queue of the quasi simplicial nodes ordered by increasing node weight
NodeSet _changed_status_
the set of nodes that have tensorly changed of status
void _initialize_()
initialize: compute nb_triangles, nb_adjacent_neighbors, etc when a new graph is set
bool hasQuasiSimplicialNode()
indicates whether there exists a quasi simplicial node
UndiGraph * _graph_
the graph on which we perform the simplicial computations
void setGraph(UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
initialize the simplicial set w.r.t. a new graph
PriorityQueue< NodeId, double > _simplicial_nodes_
a queue of the simplicial nodes ordered by increasing node weight
EdgeSet _fill_ins_list_
fill-ins list
SimplicialSet & operator=(const SimplicialSet &)
prevent a copy operator to be used
double _log_tree_width_
the current (induced) tree width
NodeProperty< double > * _log_weights_
the weights of the nodes (i.e., weight of their clique)
const EdgeSet & fillIns() const
returns the set of all the fill-ins added to the graph so far
void eraseEdge(const Edge &edge)
removes an edge from the graph and recomputes the simplicial set
Base class for undirected graphs.
Definition undiGraph.h:128
Basic class for all graphs of cliques (join trees, etc).
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
priority queues (in which an element cannot appear more than once)
#define GUM_QUASI_RATIO
#define GUM_WEIGHT_THRESHOLD
inline implementations of simplicial set