aGrUM  0.14.2
influenceDiagramInference.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 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  ***************************************************************************/
20 
27 #ifndef GUM_INFLUENCE_DIAGRAM_INFERENCE_H
28 #define GUM_INFLUENCE_DIAGRAM_INFERENCE_H
29 
30 #include <iostream>
31 #include <string>
32 #include <utility>
33 #include <vector>
34 
35 #include <agrum/agrum.h>
36 
37 #include <agrum/core/list.h>
38 
40 
43 
45 
46 namespace gum {
47 
48  template < typename GUM_SCALAR >
50 
61  template < typename GUM_SCALAR >
63  : public IInfluenceDiagramInference< GUM_SCALAR > {
64  public:
65  // ====================================================================
67  // ====================================================================
69 
75  const InfluenceDiagram< GUM_SCALAR >& infDiag);
76 
81 
83  // ====================================================================
85  // ====================================================================
87 
89  virtual void makeInference();
90 
92  GUM_SCALAR getMEU();
93 
96  Idx getBestDecisionChoice(NodeId decisionId);
97 
99  std::string displayResult();
100 
102  // ====================================================================
104  // ====================================================================
106 
108  virtual void
109  insertEvidence(const List< const Potential< GUM_SCALAR >* >& evidenceList);
110 
112  virtual void eraseEvidence(const Potential< GUM_SCALAR >* evidence);
113 
115  virtual void eraseAllEvidence();
116 
118  // ====================================================================
120  // ====================================================================
122 
125 
128  void displayStrongJunctionTree(std::ostream& stream = std::cout);
129 
130  private:
131  // ====================================================================
133  // ====================================================================
135 
138 
141 
144 
147 
150 
152  // ====================================================================
154  // ====================================================================
156 
159 
161 
163 
165 
167 
169  // ====================================================================
171  // ====================================================================
173 
175  const NodeSet& __getSeparator(NodeId clique_1, NodeId clique_2);
176 
178  NodeId __getClique(const std::vector< NodeId >& eliminationOrder, NodeId id);
179 
181  // ====================================================================
183  // ====================================================================
185 
190 
193 
195  void __cleanUp();
196 
198  void __collectChild(NodeId parent, NodeId child);
199 
201  void __absorbClique(NodeId absorbedCliqueId, NodeId absorbingCliqueId);
202 
204  void __reduceClique(CliqueProperties< GUM_SCALAR >* absorbedClique,
205  NodeSet& separator,
206  Potential< GUM_SCALAR >*& potentialMarginal,
207  Potential< GUM_SCALAR >*& utilityMarginal);
208 
215 
224 
226  bool __IsEliminatedAfter(NodeId observedNode, NodeId currentNode);
227 
229  };
230 
231 #ifndef DOXYGEN_SHOULD_SKIP_THIS
232  template < typename GUM_SCALAR >
236  class CliqueProperties {
237  public:
241 
243  ~CliqueProperties();
244 
247  void addVariable(const DiscreteVariable& v);
248 
251  void makeEliminationOrder(const std::vector< NodeId >& elim,
252  const InfluenceDiagram< GUM_SCALAR >& infDiag);
253 
259  void addPotential(const Potential< GUM_SCALAR >& cpt, bool removable = false);
260 
266  void addUtility(const Potential< GUM_SCALAR >& ut, bool removable = false);
267 
269  void cleanFromInference();
270 
278  void addEvidence(const Potential< GUM_SCALAR >& evidence);
279 
281  void removeEvidence(const DiscreteVariable& v);
282 
284  void removeAllEvidence();
285 
289  evidences() const;
290 
293  potentialBucket();
294 
297  utilityBucket();
298 
300  const Sequence< NodeId >& cliqueEliminationOrder();
301 
303  const Sequence< const DiscreteVariable* >& cliqueVariables();
304 
306  Instantiation& cliqueInstantiation();
307 
308  private:
311  __evidences;
312 
315 
318 
320  Sequence< NodeId > __eliminationOrder;
321 
323  Instantiation __allVarsInst;
324 
326  List< const DiscreteVariable* > __removableVarList;
327 
329  List< const Potential< GUM_SCALAR >* > __removablePotentialList;
330 
332  List< const Potential< GUM_SCALAR >* > __removableUtilityList;
333  };
334 
335 #endif // DOXYGEN_SHOULD_SKIP_THIS
336 
337 } /* namespace gum */
338 
340 
341 #endif /* GUM_INFLUENCE_DIAGRAM_INFERENCE_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
Potential< GUM_SCALAR > * __makeDummyPotential(NodeId cliqueId)
Returns a pointer over a "dummy" potential, which is a CPT filled with one MultiDimSparse filled with...
Set< Potential< GUM_SCALAR > *> __utilityDummies
The set of dummies sparse utilities matrix created.
Set< Potential< GUM_SCALAR > *> __potentialDummies
The set of dummies sparse potential matrix created.
<agrum/ID/inference/influenceDiagramInference.h>
bool __IsEliminatedAfter(NodeId observedNode, NodeId currentNode)
Returns true if observed node is eliminated after current node.
Idx getBestDecisionChoice(NodeId decisionId)
Implementations of the classes defined in InfluenceDiagram/inference/influenceDiagramInference.h.
Headers of MultiDimSparse.
NodeProperty< NodeId > __nodeToCliqueMap
Mapping of the nodes with the clique used to put their CPT.
Triangulation & getTriangulation()
Returns the Triangulation used by this class.
NodeId __getClique(const std::vector< NodeId > &eliminationOrder, NodeId id)
Potential< GUM_SCALAR > * __inferenceUtility
The resulting utility from inference.
Base class for discrete random variable.
Generic doubly linked lists.
Definition: list.h:369
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
Triangulation * __triangulation
The triangulation algorithm.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
void __cleanUp()
Cleans Up remaining stuff due to inference.
std::string displayResult()
displays the result of an inference
void __reduceClique(CliqueProperties< GUM_SCALAR > *absorbedClique, NodeSet &separator, Potential< GUM_SCALAR > *&potentialMarginal, Potential< GUM_SCALAR > *&utilityMarginal)
Reduces a clique down to her separator from another clique elements.
Generic class for manipulating lists.
void __makeCliquePropertiesMap()
Builds the cliques tables Uses __getCliquesTable to initialize the cliques table, and multiply the ta...
HashTable< Size, NodeId > __cliqueEliminationMap
Mapping of the nodes with the clique used to put their CPT.
void __collectChild(NodeId parent, NodeId child)
collect child clique for inferences
void __absorbClique(NodeId absorbedCliqueId, NodeId absorbingCliqueId)
Performs the operation of absorption of a clique by another.
InfluenceDiagramInference(const InfluenceDiagram< GUM_SCALAR > &infDiag)
Default constructor.
Potential< GUM_SCALAR > * __inferencePotential
The resulting potential from inference.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual ~InfluenceDiagramInference()
Destructor.
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
NodeProperty< CliqueProperties< GUM_SCALAR > *> __cliquePropertiesMap
Mapping of the nodes with the clique used to put their CPT.
bool __inferenceMade
Mapping of the nodes with the clique used to put their CPT.
Headers of the MultiDimBucket class.
Size Idx
Type for indexes.
Definition: types.h:50
<agrum/ID/inference/IInfluenceDiagramInference.h>
void displayStrongJunctionTree(std::ostream &stream=std::cout)
Displays on terminal the result of strong junction tree computation for test purpose only...
This file contains abstract class definitions influence diagrams inference classes.
virtual void insertEvidence(const List< const Potential< GUM_SCALAR > * > &evidenceList)
Interface for all the triangulation methods.
Definition: triangulation.h:44
HashTable< NodeId, Idx > __utakenDecisionMap
Mapping of the nodes with the clique used to put their CPT.
const NodeSet & __getSeparator(NodeId clique_1, NodeId clique_2)
virtual void eraseEvidence(const Potential< GUM_SCALAR > *evidence)
Potential< GUM_SCALAR > * __makeDummyUtility(NodeId cliqueId)
Returns a pointer over a "dummy" utility, which is a utility table filled with one MultiDimSparse fil...
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void __makeStrongJunctionTree()
Makes a strong junction tree that make easier elimination.
Class representing an Influence Diagram.