aGrUM  0.16.0
inferenceEngine.h
Go to the documentation of this file.
1 
23 #ifndef __INFERENCE_ENGINE__H__
24 #define __INFERENCE_ENGINE__H__
25 
32 
35 #include <map>
36 
37 #include <agrum/CN/LrsWrapper.h>
38 #include <agrum/CN/varMod2BNsMap.h>
40 #include <agrum/core/exceptions.h>
41 #include <agrum/core/math/pow.h>
43 
44 namespace gum {
45  namespace credal {
46 
58  template < typename GUM_SCALAR >
60  private:
61  //@beforeMerging swapping from typedef to using
65 
66  using dynExpe =
68 
71 
72  protected:
75 
80 
85 
88 
95 
102 
105 
110 
125 
138 
148 
155 
158 
161  void _repetitiveInit();
162 
169  void _initExpectations();
170 
176  void _initMarginals();
177 
181  void _initMarginalSets();
182 
184 
187 
196  inline const GUM_SCALAR _computeEpsilon();
197 
206  inline void _updateExpectations(const NodeId& id,
207  const std::vector< GUM_SCALAR >& vertex);
208 
220  inline void _updateCredalSets(const NodeId& id,
221  const std::vector< GUM_SCALAR >& vertex,
222  const bool& elimRedund = false);
223 
225 
228 
231  void _dynamicExpectations();
233 
234  public:
237 
238  // InferenceEngine ();
248  virtual ~InferenceEngine();
249 
251 
254 
255  virtual void makeInference() = 0;
257 
260 
265 
271 
277 
283 
289  void setRepetitiveInd(const bool repetitive);
290 
294  void storeVertices(const bool value);
300  void storeBNOpt(const bool value);
301 
306  bool repetitiveInd() const;
312 
316  bool storeVertices() const;
322  bool storeBNOpt() const;
324 
327 
331  void insertModalsFile(const std::string& path);
332 
337  void insertModals(
338  const std::map< std::string, std::vector< GUM_SCALAR > >& modals);
339 
344  virtual void insertEvidenceFile(const std::string& path);
345 
350  void insertEvidence(
351  const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap);
352 
357  void
358  insertEvidence(const NodeProperty< std::vector< GUM_SCALAR > >& evidence);
359 
364  void insertQueryFile(const std::string& path);
365 
370  void insertQuery(const NodeProperty< std::vector< bool > >& query);
371 
373 
376 
383  virtual void eraseAllEvidence();
384 
390  const std::vector< GUM_SCALAR >& marginalMin(const NodeId id) const;
391 
397  const std::vector< GUM_SCALAR >& marginalMax(const NodeId id) const;
398 
404  const std::vector< GUM_SCALAR >&
405  marginalMin(const std::string& varName) const;
406 
412  const std::vector< GUM_SCALAR >&
413  marginalMax(const std::string& varName) const;
414 
420  const GUM_SCALAR& expectationMin(const NodeId id) const;
421 
427  const GUM_SCALAR& expectationMax(const NodeId id) const;
428 
434  const GUM_SCALAR& expectationMin(const std::string& varName) const;
435 
441  const GUM_SCALAR& expectationMax(const std::string& varName) const;
442 
454  const std::vector< GUM_SCALAR >&
455  dynamicExpMin(const std::string& varName) const;
456 
468  const std::vector< GUM_SCALAR >&
469  dynamicExpMax(const std::string& varName) const;
470 
476  const std::vector< std::vector< GUM_SCALAR > >&
477  vertices(const NodeId id) const;
478 
483  void saveMarginals(const std::string& path) const;
484 
489  void saveExpectations(const std::string& path) const;
490 
495  void saveVertices(const std::string& path) const;
496 
502  void dynamicExpectations(); // if someone forgets the protected call at
503  // the end
504  // of its own algorithm, the user can call it
505 
509  std::string toString() const;
510 
515  const std::string getApproximationSchemeMsg() {
516  return this->messageApproximationScheme();
517  }
518 
520  };
521 
522 
523 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
524  extern template class InferenceEngine< double >;
525 #endif
526  } // namespace credal
527 } // namespace gum
528 
530 
531 #endif
virtual ~InferenceEngine()
Destructor.
const NodeProperty< std::vector< NodeId > > & getT1Cluster() const
Get the _t1 cluster.
const std::vector< GUM_SCALAR > & marginalMax(const NodeId id) const
Get the upper marginals of a given node id.
const GUM_SCALAR & expectationMax(const NodeId id) const
Get the upper expectation of a given node id.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
margi _oldMarginalMin
Old lower marginals used to compute epsilon.
void insertModals(const std::map< std::string, std::vector< GUM_SCALAR > > &modals)
Insert variables modalities from map to compute expectations.
Approximation Scheme.
void insertModalsFile(const std::string &path)
Insert variables modalities from file to compute expectations.
bool _storeBNOpt
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.
void _dynamicExpectations()
Rearrange lower and upper expectations to suit dynamic networks.
dynExpe _dynamicExpMin
Lower dynamic expectations.
bool repetitiveInd() const
Get the current independence status.
credalSet _marginalSets
Credal sets vertices, if enabled.
const std::string getApproximationSchemeMsg()
Get approximation scheme state.
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.
const std::vector< GUM_SCALAR > & marginalMin(const NodeId id) const
Get the lower marginals of a given node id.
void insertQueryFile(const std::string &path)
Insert query variables states from file.
margi _marginalMin
Lower marginals.
bool storeVertices() const
Get the number of iterations without changes used to stop some algorithms.
int _timeSteps
The number of time steps of this network (only usefull for dynamic networks).
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::vector< std::vector< GUM_SCALAR > > & vertices(const NodeId id) const
Get the vertice of a given node id.
margi _oldMarginalMax
Old upper marginals used to compute epsilon.
VarMod2BNsMap< GUM_SCALAR > * getVarMod2BNsMap()
Get optimum IBayesNet.
const std::vector< GUM_SCALAR > & dynamicExpMax(const std::string &varName) const
Get the upper dynamic expectation of a given variable prefix (without the time step included...
void dynamicExpectations()
Compute dynamic expectations.
const GUM_SCALAR _computeEpsilon()
Compute approximation scheme epsilon using the old marginals and the new ones.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void saveVertices(const std::string &path) const
Saves vertices to file.
void saveMarginals(const std::string &path) const
Saves marginals to file.
void _repetitiveInit()
Initialize _t0 and _t1 clusters.
expe _expectationMax
Upper expectations, if some variables modalities were inserted.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
The class for generic Hash Tables.
Definition: hashTable.h:679
cluster _t0
Clusters of nodes used with dynamic networks.
std::string toString() const
Print all nodes marginals to standart output.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Class template representing a Credal Network.
Definition: credalNet.h:89
VarMod2BNsMap< GUM_SCALAR > _dbnOpt
Object used to efficiently store optimal bayes net during inference, for some algorithms.
virtual void makeInference()=0
To be redefined by each credal net algorithm.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const CredalNet< GUM_SCALAR > * _credalNet
A pointer to the Credal Net used.
dynExpe _dynamicExpMax
Upper dynamic expectations.
void _initMarginals()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
typename gum::HashTable< std::string, std::vector< GUM_SCALAR > > dynExpe
void insertQuery(const NodeProperty< std::vector< bool > > &query)
Insert query variables and states from Property.
query _query
Holds the query nodes states.
bool _repetitiveInd
True if using repetitive independence ( dynamic network only ), False otherwise.
dynExpe _modal
Variables modalities used to compute expectations.
void _updateCredalSets(const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
Given a node id and one of it&#39;s possible vertex, update it&#39;s credal set.
Abstract class template representing a CredalNet inference engine.
void _initMarginalSets()
Initialize credal set vertices with empty sets.
const CredalNet< GUM_SCALAR > & credalNet()
Get this creadal network.
margi _evidence
Holds observed variables states.
cluster _t1
Clusters of nodes used with dynamic networks.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
expe _expectationMin
Lower expectations, if some variables modalities were inserted.
const NodeProperty< std::vector< NodeId > > & getT0Cluster() const
Get the _t0 cluster.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool _storeVertices
True if credal sets vertices are stored, False otherwise.
void setRepetitiveInd(const bool repetitive)
const GUM_SCALAR & expectationMin(const NodeId id) const
Get the lower expectation of a given node id.
Class used to store optimum IBayesNet during some inference algorithms.
Definition: varMod2BNsMap.h:56
void _initExpectations()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
void saveExpectations(const std::string &path) const
Saves expectations to file.
void insertEvidence(const std::map< std::string, std::vector< GUM_SCALAR > > &eviMap)
Insert evidence from map.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void _updateExpectations(const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
Given a node id and one of it&#39;s possible vertex obtained during inference, update this node lower and...
margi _marginalMax
Upper marginals.
virtual void eraseAllEvidence()
Erase all inference related data to perform another one.
const std::vector< GUM_SCALAR > & dynamicExpMin(const std::string &varName) const
Get the lower dynamic expectation of a given variable prefix (without the time step included...