aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
SVE.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
49#ifndef GUM_SVE_H
50#define GUM_SVE_H
51
52#include <vector>
53
59
60namespace gum {
61 namespace prm {
62
71 template < typename GUM_SCALAR >
72 class SVE: public PRMInference< GUM_SCALAR > {
73 public:
74 // ========================================================================
76 // ========================================================================
78
80 SVE(const PRM< GUM_SCALAR >& prm, const PRMSystem< GUM_SCALAR >& system);
81
83 ~SVE();
84
86 // ========================================================================
88 // ========================================================================
90
92 virtual std::string name() const;
93
95
96 protected:
97 // ========================================================================
99 // ========================================================================
101
104
106 virtual void evidenceAdded_(const Chain& chain);
107
109 virtual void evidenceRemoved_(const Chain& chain);
110
112 virtual void posterior_(const Chain& chain, Tensor< GUM_SCALAR >& m);
113
115 virtual void joint_(const std::vector< Chain >& queries, Tensor< GUM_SCALAR >& j);
116
118
119 private:
122 using BucketSetIterator = typename Set< Tensor< GUM_SCALAR >* >::iterator_safe;
123 using ArraySetIterator = typename Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe;
124
126
128
130
132
139
141
143
145
147 NodeId id,
148 BucketSet& pool,
149 BucketSet& trash);
150
153 BucketSet& pool,
154 BucketSet& trash,
155 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
156 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
157 Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
158
160 BucketSet& pool,
161 BucketSet& trash,
162 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
163 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
164 Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
165
167 BucketSet& pool,
168 BucketSet& trash,
169 Set< NodeId >* delayedVars = 0);
170
172 BucketSet& pool,
173 BucketSet& trash);
174
176 BucketSet& pool,
177 BucketSet& trash);
178
180 BucketSet& pool,
181 BucketSet& trash,
182 Set< NodeId >* delayedVars = 0);
183
186 const PRMInstance< GUM_SCALAR >* second);
187
188 void _initElimOrder_();
189
191
200 NodeId id);
201
202 std::vector< NodeId >& _getElimOrder_(const PRMClass< GUM_SCALAR >& c);
203
204 Tensor< GUM_SCALAR >* _getAggTensor_(const PRMInstance< GUM_SCALAR >* i,
205 const PRMAggregate< GUM_SCALAR >* agg);
206
208 std::string _trim_(const std::string& s);
209
211 };
212
213
214#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
215 extern template class SVE< double >;
216#endif
217
218
219 } /* namespace prm */
220} /* namespace gum */
221
223
224#endif /* GUM_SVE_H */
Headers of PRMInference.
Inline implementation of SVE.
Headers of ClassBayesNet<GUM_SCALAR>.
The class for generic Hash Tables.
Definition hashTable.h:637
Generic doubly linked lists.
Definition list.h:379
Representation of a set.
Definition set.h:131
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:75
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition PRM.h:74
This class is an implementation of the Structured Variable Elimination algorithm on PRM<GUM_SCALAR>.
Definition SVE.h:72
Sequence< std::string > * _class_elim_order_
Definition SVE.h:129
Set< Tensor< GUM_SCALAR > * > BucketSet
Code alias.
Definition SVE.h:121
void _eliminateNodesWithEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, Set< NodeId > *delayedVars=0)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:397
virtual void evidenceAdded_(const Chain &chain)
See PRMInference<GUM_SCALAR>::evidenceAdded_().
Definition SVE_tpl.h:669
typename Set< Tensor< GUM_SCALAR > * >::iterator_safe BucketSetIterator
Definition SVE.h:122
void _initLiftedNodes_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:501
void _insertLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:481
void _variableElimination_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, Set< NodeId > *delayedVars=0)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:304
BucketSet _lifted_trash_
Definition SVE.h:140
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
Definition SVE.h:125
void _eliminateNodes_(const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:146
~SVE()
Destructor.
Definition SVE_tpl.h:127
void _addDelayedVariable_(const PRMInstance< GUM_SCALAR > *i, const PRMInstance< GUM_SCALAR > *j, NodeId id)
When there is a loop in the references some variable elimination must be delayed, this methods add su...
Definition SVE_tpl.h:679
std::string _trim_(const std::string &s)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:645
void _eliminateNodesUpward_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, Set< const PRMInstance< GUM_SCALAR > * > &eliminated)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:344
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)
See PRMInference<GUM_SCALAR>::joint_().
Definition SVE_tpl.h:620
void _initElimOrder_()
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:551
HashTable< std::string, Size > _delayedVariablesCounters_
Some variable must be delayed for more than one PRMInstance<GUM_SCALAR>, when the delayed variable co...
Definition SVE.h:138
void _insertEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:632
typename PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition SVE.h:103
void _eliminateNodesDownward_(const PRMInstance< GUM_SCALAR > *from, const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, Set< const PRMInstance< GUM_SCALAR > * > &eliminated)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:256
bool _checkElimOrder_(const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:652
SVE(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default Constructor.
Definition SVE_tpl.h:625
HashTable< const PRMClass< GUM_SCALAR > *, BucketSet * > _lifted_pools_
Definition SVE.h:127
Tensor< GUM_SCALAR > * _getAggTensor_(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:663
virtual void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m)
See PRMInference<GUM_SCALAR>::posterior_().
Definition SVE_tpl.h:588
HashTable< const PRMInstance< GUM_SCALAR > *, gum::VariableSet * > _delayedVariables_
Definition SVE.h:131
typename Set< MultiDimArray< GUM_SCALAR > * >::iterator_safe ArraySetIterator
Definition SVE.h:123
void _eliminateDelayedVariables_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:229
virtual void evidenceRemoved_(const Chain &chain)
See PRMInference<GUM_SCALAR>::evidenceRemoved_().
Definition SVE_tpl.h:674
std::vector< NodeId > & _getElimOrder_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:640
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition SVE_tpl.h:701
Size NodeId
Type for node ids.
Headers of InstanceBayesNet.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
Implementation of a variable elimination algorithm for inference in Bayesian networks.