aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multipleInferenceEngine.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
42#ifndef __MULTIPLE_INFERENCE_ENGINES__H__
43#define __MULTIPLE_INFERENCE_ENGINES__H__
44
50
53
56
57namespace gum {
58 namespace credal {
59
73 template < typename GUM_SCALAR, class BNInferenceEngine >
74 class MultipleInferenceEngine: public InferenceEngine< GUM_SCALAR > {
75 private:
78
83
85 using _margis_ = std::vector< _margi_ >;
86 using _expes_ = std::vector< _expe_ >;
87 using _credalSets_ = std::vector< _credalSet_ >;
88 using _clusters_ = std::vector< std::vector< _cluster_ > >;
89
90 using _modals_ = std::vector< HashTable< std::string, std::vector< GUM_SCALAR > > >;
91
106 inline void _updateThreadCredalSets_(Size this_thread,
107 const NodeId& id,
108 const std::vector< GUM_SCALAR >& vertex,
109 const bool& elimRedund);
110
111 protected:
128
129
131 typename std::vector< _bnet_* > workingSet_;
133 typename std::vector< List< const Tensor< GUM_SCALAR >* >* > workingSetE_;
134
136 typename std::vector< BNInferenceEngine* > l_inferenceEngine_;
138 std::vector< VarMod2BNsMap< GUM_SCALAR >* > l_optimalNet_;
139
141 std::vector< std::mt19937 > generators_;
142
144 // OptBN< GUM_SCALAR > threadFusion_; // we should use this OptBN if omp
145 // is
146 // disabled (avoid creating 2 objects when only one is necessary)
147 // it should also avoid calling thread fusion operations
148
151
162 void initThreadsData_(const Size& num_threads,
163 const bool _storeVertices_,
164 const bool _storeBNOpt_);
165
167
170
183 inline bool updateThread_(Size this_thread,
184 const NodeId& id,
185 const std::vector< GUM_SCALAR >& vertex,
186 const bool& elimRedund = false);
187
191 inline void updateMarginals_();
192
198 inline const GUM_SCALAR computeEpsilon_();
199
207 void updateOldMarginals_();
208
210
213
215 void optFusion_();
217 void expFusion_();
219 void verticesFusion_(); // called ?? not done yet
220
222
223 public:
226
232
234 virtual ~MultipleInferenceEngine();
235
237
240
247 virtual void eraseAllEvidence();
249
252
253 virtual void makeInference() = 0;
254
256 };
257
258
259#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
261
263#endif
264
265 } // namespace credal
266} // namespace gum
267
269
270#endif
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
Class template representing a Credal Network.
Definition credalNet.h:97
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this creadal network.
Class template representing a CredalNet inference engine using one or more IBayesNet inference engine...
void updateMarginals_()
Fusion of threads marginals.
virtual void makeInference()=0
To be redefined by each credal net algorithm.
_margis_ l_marginalMin_
Threads lower marginals, one per thread.
_expes_ l_expectationMax_
Threads upper expectations, one per thread.
_expes_ l_expectationMin_
Threads lower expectations, one per thread.
std::vector< _bnet_ * > workingSet_
Threads IBayesNet.
std::vector< BNInferenceEngine * > l_inferenceEngine_
Threads BNInferenceEngine.
_credalSets_ l_marginalSets_
Threads vertices.
std::vector< std::vector< _cluster_ > > _clusters_
NodeProperty< std::vector< GUM_SCALAR > > _margi_
void optFusion_()
Fusion of threads optimal IBayesNet.
NodeProperty< std::vector< NodeId > > _cluster_
InferenceEngine< GUM_SCALAR > _infE_
To easily access InferenceEngine< GUM_SCALAR > methods.
std::vector< VarMod2BNsMap< GUM_SCALAR > * > l_optimalNet_
Threads optimal IBayesNet.
void updateOldMarginals_()
Update old marginals (from current marginals).
_margis_ l_marginalMax_
Threads upper marginals, one per thread.
NodeProperty< std::vector< std::vector< GUM_SCALAR > > > _credalSet_
MultipleInferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Constructor.
void expFusion_()
Fusion of threads expectations.
void initThreadsData_(const Size &num_threads, const bool _storeVertices_, const bool _storeBNOpt_)
Initialize threads data.
const GUM_SCALAR computeEpsilon_()
Compute epsilon and update old marginals.
virtual void eraseAllEvidence()
Erase all inference related data to perform another one.
bool updateThread_(Size this_thread, const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
Update thread information (marginals, expectations, IBayesNet, vertices) for a given node id.
std::vector< List< const Tensor< GUM_SCALAR > * > * > workingSetE_
Threads evidence.
std::vector< std::mt19937 > generators_
the generators used for computing random values
std::vector< HashTable< std::string, std::vector< GUM_SCALAR > > > _modals_
void _updateThreadCredalSets_(Size this_thread, const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund)
Ask for redundancy elimination of a node credal set of a calling thread.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Abstract class representing CredalNet inference engines.
Implementation of a Shafer-Shenoy's-like version of lazy propagation for inference in Bayesian networ...
namespace for all credal networks entities
Definition agrum.h:61
gum is the global namespace for all aGrUM entities
Definition agrum.h:46