aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
fmdpLearner.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
48
49// =========================================================================
50#ifndef GUM_FMDP_LEARNER_H
51#define GUM_FMDP_LEARNER_H
52// =========================================================================
53// =========================================================================
57
58// =========================================================================
59// =========================================================================
60
61namespace gum {
62
72
73 template < TESTNAME VariableAttributeSelection,
74 TESTNAME RewardAttributeSelection,
75 LEARNERNAME LearnerSelection >
78 typename LearnerSelect< LearnerSelection,
81
82 using RewardLearnerType = typename LearnerSelect< LearnerSelection,
85
87
88 public:
89 // ==========================================================================
91 // ==========================================================================
93
94 // ###################################################################
96 // ###################################################################
97 FMDPLearner(double learningThreshold, bool actionReward, double similarityThreshold = 0.05);
98
99 // ###################################################################
101 // ###################################################################
102 ~FMDPLearner();
103
105
106 // ###################################################################
108 // ###################################################################
110
111 public:
112 // ==========================================================================
114 // ==========================================================================
115 void initialize(FMDP< double >* fmdp);
116
117 // ==========================================================================
119 // ==========================================================================
123
128
132
133 // ==========================================================================
135 // ==========================================================================
137 gum::VariableSet& mainVariables,
138 const DiscreteVariable* learnedVar) {
139 return _instantiateVarLearner_(target,
140 mainVariables,
141 learnedVar,
143 }
144
146 gum::VariableSet& mainVariables,
147 const DiscreteVariable* learnedVar,
149 return new VariableLearnerType(target,
152 mainVariables,
153 learnedVar);
154 }
155
157 gum::VariableSet& mainVariables,
158 const DiscreteVariable* learnedVar,
160 return new VariableLearnerType(target, _learningThreshold_, mainVariables, learnedVar);
161 }
162
163 // ==========================================================================
165 // ==========================================================================
170
179
185
187
188
189 // ###################################################################
191 // ###################################################################
193
194 public:
195 // ==========================================================================
203 // ==========================================================================
204 bool addObservation(Idx actionId, const Observation* obs);
205
206
207 // ==========================================================================
211 // ==========================================================================
212 void updateFMDP();
213
215
216
217 // ###################################################################
219 // ###################################################################
221
222 public:
223 // ==========================================================================
228 // ==========================================================================
229 Size size();
230
231 // ==========================================================================
233 // ==========================================================================
234 const IVisitableGraphLearner* varLearner(Idx actionId, const DiscreteVariable* var) const {
235 return _actionLearners_[actionId]->getWithDefault(var, nullptr);
236 }
237
238 virtual double rMax() const { return _rmax_; }
239
240 private:
241 double _rmax_;
242
243 public:
244 virtual double modaMax() const { return _modaMax_; }
245
246 private:
247 double _modaMax_;
248
250
251
252 private:
255
257
261
264 };
265
266
267} /* namespace gum */
268
270
271#endif // GUM_FMDP_LEARNER_H
Headers of the Learning Strategy interface.
Base class for discrete random variable.
Implementation of a Terminal Node Policy that maps nodeid directly to value.
VariableLearnerType * _instantiateVarLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables, const DiscreteVariable *learnedVar, Int2Type< ITILEARNER >)
Initializes the learner.
RewardLearnerType * _instantiateRewardLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables, Int2Type< ITILEARNER >)
Initializes the learner.
typename LearnerSelect< LearnerSelection, IMDDI< RewardAttributeSelection, true >, ITI< RewardAttributeSelection, true > >::type RewardLearnerType
Definition fmdpLearner.h:82
HashTable< Idx, RewardLearnerType * > _actionRewardLearners_
const double _similarityThreshold_
RewardLearnerType * _instantiateRewardLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables)
Initializes the learner.
~FMDPLearner()
Default destructor.
VariableLearnerType * _instantiateVarLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables, const DiscreteVariable *learnedVar, Int2Type< IMDDILEARNER >)
Initializes the learner.
virtual double rMax() const
learnerSize
MultiDimFunctionGraph< double > * _instantiateFunctionGraph_()
Initializes the learner.
virtual double modaMax() const
learnerSize
double _modaMax_
learnerSize
Size size()
learnerSize
MultiDimFunctionGraph< double > * _instantiateFunctionGraph_(Int2Type< ITILEARNER >)
Initializes the learner.
void updateFMDP()
Starts an update of datastructure in the associated FMDP.
FMDP< double > * _fmdp_
The FMDP to store the learned model.
double _rmax_
learnerSize
HashTable< const DiscreteVariable *, VariableLearnerType * > VarLearnerTable
Definition fmdpLearner.h:86
const IVisitableGraphLearner * varLearner(Idx actionId, const DiscreteVariable *var) const
extractCount
const double _learningThreshold_
RewardLearnerType * _rewardLearner_
FMDPLearner(double learningThreshold, bool actionReward, double similarityThreshold=0.05)
Default constructor.
void initialize(FMDP< double > *fmdp)
Initializes the learner.
HashTable< Idx, VarLearnerTable * > _actionLearners_
RewardLearnerType * _instantiateRewardLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables, Int2Type< IMDDILEARNER >)
Initializes the learner.
typename LearnerSelect< LearnerSelection, IMDDI< VariableAttributeSelection, false >, ITI< VariableAttributeSelection, false > >::type VariableLearnerType
Definition fmdpLearner.h:77
MultiDimFunctionGraph< double > * _instantiateFunctionGraph_(Int2Type< IMDDILEARNER >)
Initializes the learner.
VariableLearnerType * _instantiateVarLearner_(MultiDimFunctionGraph< double > *target, gum::VariableSet &mainVariables, const DiscreteVariable *learnedVar)
Initializes the learner.
bool addObservation(Idx actionId, const Observation *obs)
Gives to the learner a new transition.
The class for generic Hash Tables.
Definition hashTable.h:637
<agrum/FMDP/SDyna/ILearningStrategy.h>
Learn a graphical representation of a function as a decision tree.
Definition iti.h:79
<agrum/FMDP/SDyna/IVisitableGraphLearner.h>
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
Template Implementations of the FMDPLearner class.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Headers of the IMDDI class.
Headers of the ITI class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet