aGrUM 3.1.1
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-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
48
49#ifndef GUM_SVE_H
50#define GUM_SVE_H
51
52#include <vector>
53
59
60#include <string_view>
61
62namespace gum {
63 namespace prm {
64
73 template < GUM_Numeric GUM_SCALAR >
74 class SVE: public PRMInference< GUM_SCALAR > {
75 public:
76 // ========================================================================
78 // ========================================================================
80
82 SVE(const PRM< GUM_SCALAR >& prm, const PRMSystem< GUM_SCALAR >& system);
83
85 ~SVE() override;
86
88 // ========================================================================
90 // ========================================================================
92
94 std::string name() const override;
95
97
98 protected:
99 // ========================================================================
101 // ========================================================================
103
106
108 void evidenceAdded_(const Chain& chain) override;
109
111 void evidenceRemoved_(const Chain& chain) override;
112
114 void posterior_(const Chain& chain, Tensor< GUM_SCALAR >& m) override;
115
117 void joint_(const std::vector< Chain >& queries, Tensor< GUM_SCALAR >& j) override;
118
120
121 private:
124 using BucketSetIterator = typename Set< Tensor< GUM_SCALAR >* >::iterator_safe;
125 using ArraySetIterator = typename Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe;
126
128
130
132
134
141
143
145
147
149 NodeId id,
150 BucketSet& pool,
151 BucketSet& trash);
152
155 BucketSet& pool,
156 BucketSet& trash,
157 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
158 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
159 Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
160
162 BucketSet& pool,
163 BucketSet& trash,
164 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
165 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
166 Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
167
169 BucketSet& pool,
170 BucketSet& trash,
171 Set< NodeId >* delayedVars = 0);
172
174 BucketSet& pool,
175 BucketSet& trash);
176
178 BucketSet& pool,
179 BucketSet& trash);
180
182 BucketSet& pool,
183 BucketSet& trash,
184 Set< NodeId >* delayedVars = 0);
185
188 const PRMInstance< GUM_SCALAR >* second);
189
190 void _initElimOrder_();
191
193
202 NodeId id);
203
204 std::vector< NodeId >& _getElimOrder_(const PRMClass< GUM_SCALAR >& c);
205
206 Tensor< GUM_SCALAR >* _getAggTensor_(const PRMInstance< GUM_SCALAR >* i,
207 const PRMAggregate< GUM_SCALAR >* agg);
208
210 std::string _trim_(std::string_view s);
211
213 };
214
215
216#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
217 extern template class SVE< double >;
218#endif
219
220
221 } /* namespace prm */
222} /* namespace gum */
223
225
226#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:640
Generic doubly linked lists.
Definition list.h:378
Representation of a set.
Definition set.h:129
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:77
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:72
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:74
Sequence< std::string > * _class_elim_order_
Definition SVE.h:131
Set< Tensor< GUM_SCALAR > * > BucketSet
Code alias.
Definition SVE.h:123
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:396
typename Set< Tensor< GUM_SCALAR > * >::iterator_safe BucketSetIterator
Definition SVE.h:124
void _initLiftedNodes_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:498
void _insertLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:478
std::string _trim_(std::string_view s)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:640
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:305
~SVE() override
Destructor.
Definition SVE_tpl.h:128
BucketSet _lifted_trash_
Definition SVE.h:142
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
Definition SVE.h:127
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:147
std::string name() const override
Returns the name of the current inference algorithm.
Definition SVE_tpl.h:699
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:648
void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j) override
See PRMInference<GUM_SCALAR>::joint_().
Definition SVE_tpl.h:618
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:343
void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m) override
See PRMInference<GUM_SCALAR>::posterior_().
Definition SVE_tpl.h:586
void _initElimOrder_()
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:548
void evidenceRemoved_(const Chain &chain) override
See PRMInference<GUM_SCALAR>::evidenceRemoved_().
Definition SVE_tpl.h:669
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:140
void _insertEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:629
void evidenceAdded_(const Chain &chain) override
See PRMInference<GUM_SCALAR>::evidenceAdded_().
Definition SVE_tpl.h:664
typename PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition SVE.h:105
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:257
SVE(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default Constructor.
Definition SVE_tpl.h:623
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:658
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:674
HashTable< const PRMClass< GUM_SCALAR > *, BucketSet * > _lifted_pools_
Definition SVE.h:129
std::vector< NodeId > & _getElimOrder_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:635
HashTable< const PRMInstance< GUM_SCALAR > *, gum::VariableSet * > _delayedVariables_
Definition SVE.h:133
typename Set< MultiDimArray< GUM_SCALAR > * >::iterator_safe ArraySetIterator
Definition SVE.h:125
void _eliminateDelayedVariables_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVE_tpl.h:230
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.