aGrUM  0.14.2
multipleInferenceEngine.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN and Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #ifndef __MULTIPLE_INFERENCE_ENGINES__H__
22 #define __MULTIPLE_INFERENCE_ENGINES__H__
23 
30 
35 
36 namespace gum {
37  namespace credal {
38 
52  template < typename GUM_SCALAR, class BNInferenceEngine >
53  class MultipleInferenceEngine : public InferenceEngine< GUM_SCALAR > {
54  private:
57 
62 
64  typedef std::vector< __margi > __margis;
65  typedef std::vector< __expe > __expes;
66  typedef std::vector< __credalSet > __credalSets;
67  typedef std::vector< std::vector< __cluster > > __clusters;
68 
69  typedef typename std::vector<
72 
86  inline void __updateThreadCredalSets(const NodeId& id,
87  const std::vector< GUM_SCALAR >& vertex,
88  const bool& elimRedund);
89 
90  protected:
92  __margis _l_marginalMin;
94  __margis _l_marginalMax;
102  __credalSets _l_marginalSets;
104  __margis _l_evidence;
106  __clusters _l_clusters;
107 
109  typename std::vector< __bnet* > _workingSet;
111  typename std::vector< List< const Potential< GUM_SCALAR >* >* > _workingSetE;
112 
114  typename std::vector< BNInferenceEngine* > _l_inferenceEngine;
116  std::vector< VarMod2BNsMap< GUM_SCALAR >* > _l_optimalNet;
118  // OptBN< GUM_SCALAR > _threadFusion; // we should use this OptBN if omp
119  // is
120  // disabled (avoid creating 2 objects when only one is necessary)
121  // it should also avoid calling thread fusion operations
122 
125 
136  void _initThreadsData(const Size& num_threads,
137  const bool __storeVertices,
138  const bool __storeBNOpt);
139 
141 
144 
156  inline bool _updateThread(const NodeId& id,
157  const std::vector< GUM_SCALAR >& vertex,
158  const bool& elimRedund = false);
159 
163  inline void _updateMarginals();
164 
170  inline const GUM_SCALAR _computeEpsilon();
171 
179  void _updateOldMarginals();
180 
182 
185 
187  void _optFusion();
189  void _expFusion();
191  void _verticesFusion(); // called ?? not done yet
192 
194 
195  public:
198 
204 
206  virtual ~MultipleInferenceEngine();
207 
209 
212 
219  virtual void eraseAllEvidence();
221 
224 
225  virtual void makeInference() = 0;
227  };
228 
229 
230 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
231  extern template class MultipleInferenceEngine<
232  double,
234 
235  extern template class MultipleInferenceEngine< float,
237 #endif
238 
239  } // namespace credal
240 } // namespace gum
241 
243 
244 #endif
std::vector< BNInferenceEngine *> _l_inferenceEngine
Threads BNInferenceEngine.
NodeProperty< std::vector< std::vector< GUM_SCALAR > > > __credalSet
void _initThreadsData(const Size &num_threads, const bool __storeVertices, const bool __storeBNOpt)
Initialize threads data.
__expes _l_expectationMin
Threads lower expectations, one per thread.
NodeProperty< std::vector< NodeId > > __cluster
virtual void makeInference()=0
To be redefined by each credal net algorithm.
void _optFusion()
Fusion of threads optimal IBayesNet.
__margis _l_marginalMin
Threads lower marginals, one per thread.
void _expFusion()
Fusion of threads expectations.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:59
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
std::vector< List< const Potential< GUM_SCALAR > *> *> _workingSetE
Threads evidence.
Abstract class representing CredalNet inference engines.
MultipleInferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Constructor.
virtual void eraseAllEvidence()
Erase all inference related data to perform another one.
The class for generic Hash Tables.
Definition: hashTable.h:676
std::vector< VarMod2BNsMap< GUM_SCALAR > *> _l_optimalNet
Threads optimal IBayesNet.
std::vector< __bnet *> _workingSet
Threads IBayesNet.
Class template representing a Credal Network.
Definition: credalNet.h:87
void _updateMarginals()
Fusion of threads marginals.
void _updateOldMarginals()
Update old marginals (from current marginals).
__expes _l_expectationMax
Threads upper expectations, one per thread.
__clusters _l_clusters
Threads clusters.
Abstract class template representing a CredalNet inference engine.
std::vector< std::vector< __cluster > > __clusters
const CredalNet< GUM_SCALAR > & credalNet()
Get this creadal network.
std::vector< HashTable< std::string, std::vector< GUM_SCALAR > > > __modals
bool _updateThread(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...
<agrum/BN/inference/lazyPropagation.h>
NodeProperty< std::vector< GUM_SCALAR > > __margi
Class template representing a CredalNet inference engine using one or more IBayesNet inference engine...
__margis _l_marginalMax
Threads upper marginals, one per thread.
Implementation of a Shafer-Shenoy&#39;s-like version of lazy propagation for inference in Bayesian Networ...
InferenceEngine< GUM_SCALAR > __infE
To easily access InferenceEngine< GUM_SCALAR > methods.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
__credalSets _l_marginalSets
Threads vertices.
void __updateThreadCredalSets(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.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
const GUM_SCALAR _computeEpsilon()
Compute epsilon and update old marginals.