aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
imddi.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of the IMDDI class.
25  *
26  * @author Jean-Christophe MAGNAN
27  */
28 
29 // =========================================================================
30 #ifndef GUM_IMDDI_H
31 #define GUM_IMDDI_H
32 // =========================================================================
33 #include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
34 // =========================================================================
35 #include <agrum/FMDP/learning/datastructure/incrementalGraphLearner.h>
36 #include <agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
37 #include <agrum/FMDP/learning/datastructure/leaves/concreteLeaf.h>
38 #include <agrum/FMDP/learning/datastructure/leaves/leafAggregator.h>
39 #include <agrum/FMDP/learning/datastructure/variableselector.h>
40 // =========================================================================
41 #include <agrum/tools/variables/discreteVariable.h>
42 // =========================================================================
43 
44 namespace gum {
45 
46  /**
47  * @class IMDDI
48  * @headerfile imddi.h <agrum/FMDP/planning/FunctionGraph/imddi.h>
49  * @brief
50  * @ingroup fmdp_group
51  *
52  *
53  *
54  */
55 
56  template < TESTNAME AttributeSelection, bool isScalar = false >
58  public:
59  // ###################################################################
60  /// @name Constructor & destructor.
61  // ###################################################################
62  /// @{
63 
64  // ==========================================================================
65  /// Variable Learner constructor
66  // ==========================================================================
67  IMDDI(MultiDimFunctionGraph< double >* target,
68  double attributeSelectionThreshold,
69  double pairSelectionThreshold,
70  Set< const DiscreteVariable* > attributeListe,
71  const DiscreteVariable* learnedValue);
72 
73  // ==========================================================================
74  /// Reward Learner constructor
75  // ==========================================================================
76  IMDDI(MultiDimFunctionGraph< double >* target,
77  double attributeSelectionThreshold,
78  double pairSelectionThreshold,
79  Set< const DiscreteVariable* > attributeListe);
80 
81  // ==========================================================================
82  /// Default destructor
83  // ==========================================================================
84  ~IMDDI();
85 
86  /// @}
87 
88  // ###################################################################
89  /// @name Incrementals methods
90  // ###################################################################
91  /// @{
92 
93  // ==========================================================================
94  /// Adds a new observation to the structure
95  // ==========================================================================
96  void addObservation(const Observation*);
97 
98  protected:
99  void updateNodeWithObservation_(const Observation* newObs,
100  NodeId currentNodeId);
101 
102  public:
103  // ==========================================================================
104  /// Updates the tree after a new observation has been added
105  // ==========================================================================
106  void updateGraph();
107 
108  protected:
110  const DiscreteVariable* boundVar,
111  Set< const Observation* >* sonsMap);
112 
113  void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable* desiredVar);
114 
115  void removeNode_(NodeId removedNodeId);
116 
117  private:
118  void addLeaf__(NodeId);
119  void removeLeaf__(NodeId);
120 
121  /// @}
122 
123  private:
124  // ###################################################################
125  /// @name Updating private methods
126  // ###################################################################
127  /// @{
128 
129  // ==========================================================================
130  /// Computes the score of the given variables for the given node
131  // ==========================================================================
132  void updateScore__(const DiscreteVariable*, NodeId, VariableSelector& vs);
133  void downdateScore__(const DiscreteVariable*, NodeId, VariableSelector& vs);
134 
135  // ==========================================================================
136  /// For each node in the given set, this methods checks whether or not
137  /// we should installed the given variable as a test.
138  /// If so, the node is updated
139  // ==========================================================================
140  void
142 
143 
144  public:
145  // ==========================================================================
146  ///
147  // ==========================================================================
148  void updateFunctionGraph();
149 
150  private:
151  void rebuildFunctionGraph__();
154 
155  /// @}
156  ///
157  public:
158  void insertSetOfVars(MultiDimFunctionGraph< double >* ret) const {
159  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
160  = varOrder__.beginSafe();
161  varIter != varOrder__.endSafe();
162  ++varIter)
163  ret->add(**varIter);
164  }
165 
166  private:
168 
170 
172 
173  /// The total number of observation added to this tree
175 
176  /// The threshold above which we consider variables to be dependant
178 
179  /// The threshold above which two leaves does not share the same probability
180  /// distribution
181  // double pairSelectionThreshold__;
182  };
183 
184 
185 } /* namespace gum */
186 
187 #include <agrum/FMDP/learning/datastructure/imddi_tpl.h>
188 
189 #endif // GUM_IMDDI_H
Sequence< const DiscreteVariable *> varOrder__
Definition: imddi.h:167
void updateGraph()
Updates the tree after a new observation has been added.
Definition: imddi_tpl.h:126
void addObservation(const Observation *)
Adds a new observation to the structure.
Definition: imddi_tpl.h:104
double attributeSelectionThreshold__
The threshold above which we consider variables to be dependant.
Definition: imddi.h:177
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void updateFunctionGraph()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:328
void removeNode_(NodeId removedNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:290
void rebuildFunctionGraph__()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:340
NodeId insertLeafInFunctionGraph__(AbstractLeaf *, Int2Type< false >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:419
void updateNodeSet__(Set< NodeId > &, const DiscreteVariable *, VariableSelector &)
For each node in the given set, this methods checks whether or not we should installed the given vari...
Definition: imddi_tpl.h:209
~IMDDI()
Default destructor.
Definition: imddi_tpl.h:89
LeafAggregator lg__
Definition: imddi.h:169
void downdateScore__(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:189
void addLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:302
NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *sonsMap)
Adds a new observation to the structure.
Definition: imddi_tpl.h:252
void insertSetOfVars(MultiDimFunctionGraph< double > *ret) const
Definition: imddi.h:158
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
void removeLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:316
HashTable< NodeId, AbstractLeaf *> leafMap__
Definition: imddi.h:171
void updateScore__(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:176
void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:111
Idx nbTotalObservation__
The total number of observation added to this tree.
Definition: imddi.h:174
void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Adds a new observation to the structure.
Definition: imddi_tpl.h:272
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe)
Reward Learner constructor.
Definition: imddi_tpl.h:70