aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ShaferShenoyLIMIDInference.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
47
48#ifndef GUM_SHAFERSHENOY_LIMIDS_H
49#define GUM_SHAFERSHENOY_LIMIDS_H
50
51#include <iostream>
52#include <string>
53#include <utility>
54#include <vector>
55
56#include <agrum/agrum.h>
57
65
66namespace gum {
67
78 template < typename GUM_SCALAR >
83
84
85 public:
86 // ====================================================================
88 // ====================================================================
90
96
101
103
104 void clear() override;
105
108 void addNoForgettingAssumption(const std::vector< NodeId >& ids);
109 void addNoForgettingAssumption(const std::vector< std::string >& names);
111
113
114 DAG reducedGraph() const { return reduced_; };
115
116 std::vector< NodeSet > reversePartialOrder() const;
117
119
120 bool isSolvable() const;
121
122
124
125 gum::Tensor< GUM_SCALAR > optimalDecision(const std::string& decisionName) final {
126 return optimalDecision(this->influenceDiagram().idFromName(decisionName));
127 };
128
135 virtual const Tensor< GUM_SCALAR >& posterior(NodeId node) final;
136
137 const Tensor< GUM_SCALAR >& posterior(const std::string& name) final {
138 return posterior(this->influenceDiagram().idFromName(name));
139 };
140
147 virtual const Tensor< GUM_SCALAR >& posteriorUtility(NodeId node) final;
148
149 virtual const Tensor< GUM_SCALAR >& posteriorUtility(const std::string& name) final {
150 return posteriorUtility(this->influenceDiagram().idFromName(name));
151 };
152
159 virtual std::pair< GUM_SCALAR, GUM_SCALAR > meanVar(NodeId node) final;
160
161 std::pair< GUM_SCALAR, GUM_SCALAR > meanVar(const std::string& name) final {
162 return meanVar(this->influenceDiagram().idFromName(name));
163 };
164
170 std::pair< GUM_SCALAR, GUM_SCALAR > MEU() final;
171
172 protected:
173 void onStateChanged_() override;
174 void onEvidenceAdded_(NodeId id, bool isHardEvidence) override;
175 void onEvidenceErased_(NodeId id, bool isHardEvidence) override;
176 void onAllEvidenceErased_(bool contains_hard_evidence) override;
177 void onEvidenceChanged_(NodeId id, bool hasChangedSoftHard) override;
178 void onModelChanged_(const GraphicalModel* model) override;
180 void updateOutdatedTensors_() override;
181 void makeInference_() override;
182
185
193
198
199 private:
202 void _creatingPartialOrder_(const NodeSet& utilities);
203 void _checkingSolvability_(const NodeSet& utilities);
206
210 PsiArcProperty& psi,
211 NodeId fromClique,
212 NodeId toClique);
213 void deciding_(PhiNodeProperty& phi, PsiArcProperty& psi, NodeId decisionNode);
215 PsiArcProperty& psi,
216 NodeId fromClique,
217 NodeId toClique);
219 PsiArcProperty& psi,
220 NodeId fromClique,
221 NodeId toClique);
225 const PsiArcProperty& psi,
226 NodeId clique,
227 NodeId except) const;
228 DecisionTensor< double >
229 integrating_(const PhiNodeProperty& phi, const PsiArcProperty& psi, NodeId clique) const;
230 void binarizingMax_(const Tensor< GUM_SCALAR >& decision,
231 const Tensor< GUM_SCALAR >& proba) const;
232 };
233} /* namespace gum */
234
235#include <agrum/ID/inference/ShaferShenoyLIMIDInference_tpl.h>
236
237#endif /* GUM_SHAFERSHENOY_LIMIDS_H */
Basic graph of cliques.
Definition cliqueGraph.h:77
Base class for dag.
Definition DAG.h:121
<agrum/ID/inference/decisionTensor.h>
The default triangulation algorithm used by aGrUM.
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
Virtual base class for probabilistic graphical models.
InfluenceDiagramInference(const InfluenceDiagram< GUM_SCALAR > *infDiag)
Default constructor.
virtual const InfluenceDiagram< GUM_SCALAR > & influenceDiagram() const final
Returns a constant reference over the IBayesNet referenced by this class.
Class representing an Influence Diagram.
NodeSet nonRequisiteNodes_(NodeId d) const
Returns the set of non-requisite for node d.
NodeProperty< DecisionTensor< GUM_SCALAR > > posteriors_
void addNoForgettingAssumption(const std::vector< std::string > &names)
Default constructor.
void onEvidenceChanged_(NodeId id, bool hasChangedSoftHard) override
fired after an evidence is changed, in particular when its status (soft/hard) changes
void makeInference_() override
called when the inference has to be performed effectively
void collectingToFollowingRoot_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId fromClique, NodeId toClique)
void onEvidenceAdded_(NodeId id, bool isHardEvidence) override
fired after a new evidence is inserted
gum::Tensor< GUM_SCALAR > optimalDecision(const std::string &decisionName) final
void onAllEvidenceErased_(bool contains_hard_evidence) override
fired before all the evidence are erased
void onStateChanged_() override
fired when the stage is changed
void _creatingPartialOrder_(const NodeSet &utilities)
void _findingCliqueForEachNode_(DefaultTriangulation &triangulation)
void updateOutdatedStructure_() override
prepares inference when the latter is in OutdatedStructure state
void updateOutdatedTensors_() override
prepares inference when the latter is in OutdatedTensors state
void deciding_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId decisionNode)
void clear() override
Default constructor.
void addNoForgettingAssumption(const std::vector< NodeId > &ids)
No forgetting rule assumption.
virtual ~ShaferShenoyLIMIDInference()
Destructor.
const Tensor< GUM_SCALAR > & posterior(const std::string &name) final
NodeProperty< DecisionTensor< GUM_SCALAR > > PhiNodeProperty
std::pair< GUM_SCALAR, GUM_SCALAR > meanVar(const std::string &name) final
void collectingMessage_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId rootClique)
virtual const Tensor< GUM_SCALAR > & posteriorUtility(const std::string &name) final
void transmittingMessage_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId fromClique, NodeId toClique)
InfluenceDiagram< GUM_SCALAR > reducedLIMID() const
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node) final
Return the posterior probability of a node.
NodeProperty< DecisionTensor< GUM_SCALAR > > unconditionalDecisions_
void onModelChanged_(const GraphicalModel *model) override
fired after a new Bayes net has been assigned to the engine
void _checkingSolvability_(const NodeSet &utilities)
void distributingMessage_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId rootClique)
void onEvidenceErased_(NodeId id, bool isHardEvidence) override
fired before an evidence is removed
virtual std::pair< GUM_SCALAR, GUM_SCALAR > meanVar(NodeId node) final
Return the pair (mean,variance) for a node.
ArcProperty< DecisionTensor< GUM_SCALAR > > PsiArcProperty
gum::Tensor< GUM_SCALAR > optimalDecision(NodeId decisionId) final
virtual const Tensor< GUM_SCALAR > & posteriorUtility(NodeId node) final
Return the posterior utility of a node.
std::vector< NodeSet > reversePartialOrder() const
bool hasNoForgettingAssumption() const
Default constructor.
ShaferShenoyLIMIDInference(const InfluenceDiagram< GUM_SCALAR > *infDiag)
Default constructor.
void binarizingMax_(const Tensor< GUM_SCALAR > &decision, const Tensor< GUM_SCALAR > &proba) const
void initializingInference_(PhiNodeProperty &phi, PsiArcProperty &psi)
std::pair< GUM_SCALAR, GUM_SCALAR > MEU() final
Return the pair (mean,variance) for the total utility (MEU).
DecisionTensor< double > integrating_(const PhiNodeProperty &phi, const PsiArcProperty &psi, NodeId clique, NodeId except) const
void computingPosteriors_(const PhiNodeProperty &phi, const PsiArcProperty &psi)
void transmittingFinalMessage_(PhiNodeProperty &phi, PsiArcProperty &psi, NodeId fromClique, NodeId toClique)
const JunctionTree * junctionTree() const
Default constructor.
NodeProperty< Tensor< GUM_SCALAR > > strategies_
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Definition tensor.h:85
This file contains abstract class definitions influence diagrams inference classes.
Class for computing default triangulations of graphs.
aGrUM's exceptions
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
This file contains abstract class definitions influence diagrams inference classes.
Headers of the MultiDimBucket class.
Headers of MultiDimSparse.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
STL namespace.
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...