aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
imddi.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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, NodeId currentNodeId);
100 
101  public:
102  // ==========================================================================
103  /// Updates the tree after a new observation has been added
104  // ==========================================================================
105  void updateGraph();
106 
107  protected:
109  const DiscreteVariable* boundVar,
110  Set< const Observation* >* sonsMap);
111 
112  void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable* desiredVar);
113 
114  void removeNode_(NodeId removedNodeId);
115 
116  private:
117  void _addLeaf_(NodeId);
118  void _removeLeaf_(NodeId);
119 
120  /// @}
121 
122  private:
123  // ###################################################################
124  /// @name Updating private methods
125  // ###################################################################
126  /// @{
127 
128  // ==========================================================================
129  /// Computes the score of the given variables for the given node
130  // ==========================================================================
131  void _updateScore_(const DiscreteVariable*, NodeId, VariableSelector& vs);
132  void _downdateScore_(const DiscreteVariable*, NodeId, VariableSelector& vs);
133 
134  // ==========================================================================
135  /// For each node in the given set, this methods checks whether or not
136  /// we should installed the given variable as a test.
137  /// If so, the node is updated
138  // ==========================================================================
140 
141 
142  public:
143  // ==========================================================================
144  ///
145  // ==========================================================================
146  void updateFunctionGraph();
147 
148  private:
149  void _rebuildFunctionGraph_();
152 
153  /// @}
154  ///
155  public:
156  void insertSetOfVars(MultiDimFunctionGraph< double >* ret) const {
157  for (SequenceIteratorSafe< const DiscreteVariable* > varIter = _varOrder_.beginSafe();
158  varIter != _varOrder_.endSafe();
159  ++varIter)
160  ret->add(**varIter);
161  }
162 
163  private:
165 
167 
169 
170  /// The total number of observation added to this tree
172 
173  /// The threshold above which we consider variables to be dependant
175 
176  /// The threshold above which two leaves does not share the same probability
177  /// distribution
178  // double _pairSelectionThreshold_;
179  };
180 
181 
182 } /* namespace gum */
183 
184 #include <agrum/FMDP/learning/datastructure/imddi_tpl.h>
185 
186 #endif // GUM_IMDDI_H
void _updateScore_(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:168
NodeId _insertLeafInFunctionGraph_(AbstractLeaf *, Int2Type< false >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:392
void updateGraph()
Updates the tree after a new observation has been added.
Definition: imddi_tpl.h:118
void addObservation(const Observation *)
Adds a new observation to the structure.
Definition: imddi_tpl.h:99
LeafAggregator _lg_
Definition: imddi.h:166
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void updateFunctionGraph()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:308
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:282
void removeNode_(NodeId removedNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:272
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition: imddi.h:174
Sequence< const DiscreteVariable *> _varOrder_
Definition: imddi.h:164
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition: imddi.h:171
~IMDDI()
Default destructor.
Definition: imddi_tpl.h:85
NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *sonsMap)
Adds a new observation to the structure.
Definition: imddi_tpl.h:238
void insertSetOfVars(MultiDimFunctionGraph< double > *ret) const
Definition: imddi.h:156
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
void _downdateScore_(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:180
void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:105
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:198
void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Adds a new observation to the structure.
Definition: imddi_tpl.h:257
HashTable< NodeId, AbstractLeaf *> _leafMap_
Definition: imddi.h:168
void _removeLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:296
void _rebuildFunctionGraph_()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:320
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe)
Reward Learner constructor.
Definition: imddi_tpl.h:67