aGrUM  0.14.2
loopyBeliefPropagation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2017 by Pierre-Henri WUILLEMIN et 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  ***************************************************************************/
25 #ifndef GUM_LOOPYBELIEFPROPAGATION_H
26 #define GUM_LOOPYBELIEFPROPAGATION_H
27 
29 
30 namespace gum {
38  template < typename GUM_SCALAR >
39  class LoopyBeliefPropagation : public ApproximateInference< GUM_SCALAR > {
40  public:
45 
49  virtual ~LoopyBeliefPropagation();
50 
51  protected:
52  virtual void _onStateChanged(){};
53 
54  virtual void _onEvidenceAdded(const NodeId id, bool isHardEvidence){};
55 
56  virtual void _onEvidenceErased(const NodeId id, bool isHardEvidence){};
57 
58  virtual void _onAllEvidenceErased(bool contains_hard_evidence){};
59 
60  virtual void _onEvidenceChanged(const NodeId id, bool hasChangedSoftHard){};
61 
62  virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn){};
63 
64  virtual void _updateOutdatedBNStructure();
65 
66  virtual void _updateOutdatedBNPotentials(){};
67 
68  virtual void _onMarginalTargetAdded(const NodeId id){};
69 
70  virtual void _onMarginalTargetErased(const NodeId id){};
71 
72  virtual void _onAllMarginalTargetsAdded(){};
73 
74  virtual void _onAllMarginalTargetsErased(){};
75 
77 
78  virtual const Potential< GUM_SCALAR >& _posterior(NodeId id);
79 
80  virtual void _makeInference();
81 
82  // will be used in both directions :
83  // for x->y, (x,y) and (y,x) will be in __messages
86 
87  void __initStats();
88 
89  void __init_messages();
94 
95  // return the max differential BNdistance for this node
96  GUM_SCALAR __updateNodeMessage(NodeId X);
97  };
98 
99 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
100 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
101  // extern template class LoopyBeliefPropagation<float>;
102 # endif
103 #endif
104 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
105 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
106  // extern template class LoopyBeliefPropagation<double>;
107 # endif
108 #endif
109 } /* namespace gum */
110 
112 
113 
114 #endif // GUM_LOOPYBELIEFPROPAGATION_H
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
virtual void _onStateChanged()
fired when the stage is changed
This file contains general methods for approximate inference.
virtual void _onAllEvidenceErased(bool contains_hard_evidence)
fired before all the evidence are erased
virtual void _onEvidenceAdded(const NodeId id, bool isHardEvidence)
fired after a new evidence is inserted
virtual void _onMarginalTargetErased(const NodeId id)
fired before a marginal target is removed
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
Potential< GUM_SCALAR > __computeProdLambda(NodeId X)
The class for generic Hash Tables.
Definition: hashTable.h:676
virtual ~LoopyBeliefPropagation()
Destructor.
virtual void _onMarginalTargetAdded(const NodeId id)
fired after a new marginal target is inserted
virtual void _onEvidenceChanged(const NodeId id, bool hasChangedSoftHard)
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
GUM_SCALAR __updateNodeMessage(NodeId X)
<agrum/BN/inference/loopyBeliefPropagation.h>
LoopyBeliefPropagation(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
virtual void _onAllMarginalTargetsAdded()
fired after all the nodes of the BN are added as marginal targets
ArcProperty< Potential< GUM_SCALAR > > __messages
virtual const Potential< GUM_SCALAR > & _posterior(NodeId id)
asks derived classes for the posterior of a given variable
virtual void _onEvidenceErased(const NodeId id, bool isHardEvidence)
fired before an evidence is removed
virtual void _onAllMarginalTargetsErased()
fired before a all marginal targets are removed
NodeProperty< Potential< GUM_SCALAR > > __posteriors
virtual void _makeInference()
called when the inference has to be performed effectively
Potential< GUM_SCALAR > __computeProdPi(NodeId X)
Implementation of Loopy Belief Propagation in Bayesian Networks.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual void _updateOutdatedBNStructure()
prepares inference when the latter is in OutdatedBNStructure state
virtual void _updateOutdatedBNPotentials()
prepares inference when the latter is in OutdatedBNPotentials state