aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
loopyBeliefPropagation.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
47#ifndef GUM_LOOPYBELIEFPROPAGATION_H
48#define GUM_LOOPYBELIEFPROPAGATION_H
49
51
52namespace gum {
60 template < GUM_Numeric GUM_SCALAR >
61 class LoopyBeliefPropagation: public ApproximateInference< GUM_SCALAR > {
62 public:
67
72
73 protected:
74 void onStateChanged_() override;
75
76 void onEvidenceAdded_(const NodeId id, bool isHardEvidence) override;
77
78 void onEvidenceErased_(const NodeId id, bool isHardEvidence) override;
79
80 void onAllEvidenceErased_(bool contains_hard_evidence) override;
81
82 void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) override;
83
84 void onModelChanged_(const GraphicalModel* bn) override;
85
86 void updateOutdatedStructure_() override;
87
88 void updateOutdatedTensors_() override;
89
90 void onMarginalTargetAdded_(const NodeId id) override;
91
92 void onMarginalTargetErased_(const NodeId id) override;
93
95
97
99
100 const Tensor< GUM_SCALAR >& posterior_(NodeId id) override;
101
102 void makeInference_() override;
103
104 // will be used in both directions :
105 // for x->y, (x,y) and (y,x) will be in _messages_
108
110
112 Tensor< GUM_SCALAR > _computeProdPi_(NodeId X);
113 Tensor< GUM_SCALAR > _computeProdPi_(NodeId X, NodeId except);
114 Tensor< GUM_SCALAR > _computeProdLambda_(NodeId X);
115 Tensor< GUM_SCALAR > _computeProdLambda_(NodeId X, NodeId except);
116
117 // return the max differential BNdistance for this node
119 };
120
121#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
122# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
123 // extern template class LoopyBeliefPropagation<float>;
124# endif
125#endif
126#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
127# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
128 // extern template class LoopyBeliefPropagation<double>;
129# endif
130#endif
131} /* namespace gum */
132
134
135
136#endif // GUM_LOOPYBELIEFPROPAGATION_H
This file contains general methods for approximate inference.
ApproximateInference(const IBayesNet< GUM_SCALAR > *bn)
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
void onAllMarginalTargetsErased_() override
fired before a all marginal targets are removed
~LoopyBeliefPropagation() override
Destructor.
void updateOutdatedStructure_() override
prepares inference when the latter is in OutdatedStructure state
void makeInference_() override
called when the inference has to be performed effectively
ArcProperty< Tensor< GUM_SCALAR > > _messages_
void onAllEvidenceErased_(bool contains_hard_evidence) override
fired before all the evidence are erased
void onEvidenceErased_(const NodeId id, bool isHardEvidence) override
fired before an evidence is removed
void onMarginalTargetAdded_(const NodeId id) override
fired after a new marginal target is inserted
const Tensor< GUM_SCALAR > & posterior_(NodeId id) override
asks derived classes for the posterior of a given variable
GUM_SCALAR _updateNodeMessage_(NodeId X)
Tensor< GUM_SCALAR > _computeProdLambda_(NodeId X)
void onStateChanged_() override
fired when the stage is changed
Tensor< GUM_SCALAR > _computeProdLambda_(NodeId X, NodeId except)
void onEvidenceAdded_(const NodeId id, bool isHardEvidence) override
fired after a new evidence is inserted
NodeProperty< Tensor< GUM_SCALAR > > _posteriors_
Tensor< GUM_SCALAR > _computeProdPi_(NodeId X, NodeId except)
void onMarginalTargetErased_(const NodeId id) override
fired before a marginal target is removed
void updateOutdatedTensors_() override
prepares inference when the latter is in OutdatedTensors state
Tensor< GUM_SCALAR > _computeProdPi_(NodeId X)
LoopyBeliefPropagation(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) override
fired after an evidence is changed, in particular when its status (soft/hard) changes
void onModelChanged_(const GraphicalModel *bn) override
fired after a new Bayes net has been assigned to the engine
void onAllMarginalTargetsAdded_() override
fired after all the nodes of the BN are added as marginal targets
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Implementation of Loopy Belief Propagation in Bayesian networks.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46