aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
SVED.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_SVED_H
49#define GUM_SVED_H
50
51#include <vector>
52
59
60namespace gum {
61 namespace prm {
62
71 template < typename GUM_SCALAR >
72 class SVED: public PRMInference< GUM_SCALAR > {
73 public:
74 // ========================================================================
76 // ========================================================================
78
81
83 ~SVED();
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
133
135
136 StructuredBayesBall< GUM_SCALAR > _bb_;
137
140 HashTable< const Set< NodeId >*, std::pair< Set< NodeId >*, Set< NodeId >* > > _req_set_;
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
159 BucketSet& pool,
160 BucketSet& trash,
161 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
162 Set< const PRMInstance< GUM_SCALAR >* >& ignore);
163
165 BucketSet& pool,
166 BucketSet& trash);
167
169 BucketSet& pool,
170 BucketSet& trash);
171
174 const PRMInstance< GUM_SCALAR >* second);
175
176 void _initElimOrder_();
177
179
180 std::vector< NodeId >& _getElimOrder_(const PRMClass< GUM_SCALAR >& c);
181
182 Tensor< GUM_SCALAR >* _getAggTensor_(const PRMInstance< GUM_SCALAR >* i,
183 const PRMAggregate< GUM_SCALAR >* agg);
184
186
188
190
192
194 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
195 List< const PRMInstance< GUM_SCALAR >* >& reduced_list,
196 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
197 BucketSet& pool,
198 BucketSet& trash);
199
200 std::string _trim_(const std::string& s);
202 };
203
204
205#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
206 extern template class SVED< double >;
207#endif
208
209
210 } /* namespace prm */
211} /* namespace gum */
212
214
215#endif /* GUM_SVED_H */
Inline implementation of SVED.
Headers of ClassBayesNet<GUM_SCALAR>.
Headers of ClassDependencyGraph<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 Value Elimination algorithm on PRM<GUM_SCALAR>.
Definition SVED.h:72
~SVED()
Destructor.
Definition SVED_tpl.h:55
std::string _trim_(const std::string &s)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:513
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
Definition SVED.h:125
virtual void evidenceAdded_(const Chain &chain)
See PRMInference::evidenceAdded_().
Definition SVED_tpl.h:538
Set< Tensor< GUM_SCALAR > * > BucketSet
Code alias.
Definition SVED.h:121
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)
See PRMInference::joint_().
Definition SVED_tpl.h:458
void _eliminateNodesUpward_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:199
std::vector< NodeId > & _getElimOrder_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:508
void _insertEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:500
virtual void evidenceRemoved_(const Chain &chain)
See PRMInference::evidenceRemoved_().
Definition SVED_tpl.h:544
virtual void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m)
See PRMInference::posterior_().
Definition SVED_tpl.h:408
void _initLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:309
void _reduceElimList_(const PRMInstance< GUM_SCALAR > *i, List< const PRMInstance< GUM_SCALAR > * > &elim_list, List< const PRMInstance< GUM_SCALAR > * > &reduced_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:570
HashTable< const Set< NodeId > *, BucketSet * > _lifted_pools_
The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances wi...
Definition SVED.h:132
Set< NodeId > & _getAttrSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:549
Sequence< std::string > * _class_elim_order_
Definition SVED.h:134
void _eliminateNodesWithEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:266
Tensor< GUM_SCALAR > * _getAggTensor_(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:531
void _initElimOrder_()
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:371
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition SVED_tpl.h:590
typename Set< Tensor< GUM_SCALAR > * >::iterator_safe BucketSetIterator
Definition SVED.h:122
typename Set< MultiDimArray< GUM_SCALAR > * >::iterator_safe ArraySetIterator
Definition SVED.h:123
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > * > > _req_set_
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition SVED.h:140
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition SVED_tpl.h:493
Set< NodeId > & _getSCSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:559
bool _checkElimOrder_(const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:520
void _insertLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:289
void _eliminateNodes_(const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:65
typename PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition SVED.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)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:131
StructuredBayesBall< GUM_SCALAR > _bb_
Definition SVED.h:136
void _initReqSets_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:463
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
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
Headers of StructuredBayesBall.
Implementation of a variable elimination algorithm for inference in Bayesian networks.