aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
sdyna.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
49
50// =========================================================================
51#ifndef GUM_SDYNA_H
52#define GUM_SDYNA_H
53// =========================================================================
54#include <agrum/agrum.h>
55// =========================================================================
56// =========================================================================
60
62
63// =========================================================================
64
65namespace gum {
66
77 class SDYNA {
78 // ###################################################################
80 // ###################################################################
82
83 public:
84 // ==========================================================================
86 // ==========================================================================
87 static SDYNA* spitiInstance(double attributeSelectionThreshold = 0.99,
88 double discountFactor = 0.9,
89 double epsilon = 1,
90 Idx observationPhaseLenght = 100,
91 Idx nbValueIterationStep = 10);
92
93 // ==========================================================================
95 // ==========================================================================
96 static SDYNA* spimddiInstance(double attributeSelectionThreshold = 0.99,
97 double similarityThreshold = 0.3,
98 double discountFactor = 0.9,
99 double epsilon = 1,
100 Idx observationPhaseLenght = 100,
101 Idx nbValueIterationStep = 10);
102
103 // ==========================================================================
105 // ==========================================================================
106 static SDYNA* RMaxMDDInstance(double attributeSelectionThreshold = 0.99,
107 double similarityThreshold = 0.3,
108 double discountFactor = 0.9,
109 double epsilon = 1,
110 Idx observationPhaseLenght = 100,
111 Idx nbValueIterationStep = 10);
112
113 // ==========================================================================
115 // ==========================================================================
116 static SDYNA* RMaxTreeInstance(double attributeSelectionThreshold = 0.99,
117 double discountFactor = 0.9,
118 double epsilon = 1,
119 Idx observationPhaseLenght = 100,
120 Idx nbValueIterationStep = 10);
121
122 // ==========================================================================
124 // ==========================================================================
125 static SDYNA* RandomMDDInstance(double attributeSelectionThreshold = 0.99,
126 double similarityThreshold = 0.3,
127 double discountFactor = 0.9,
128 double epsilon = 1,
129 Idx observationPhaseLenght = 100,
130 Idx nbValueIterationStep = 10);
131
132 // ==========================================================================
134 // ==========================================================================
135 static SDYNA* RandomTreeInstance(double attributeSelectionThreshold = 0.99,
136 double discountFactor = 0.9,
137 double epsilon = 1,
138 Idx observationPhaseLenght = 100,
139 Idx nbValueIterationStep = 10);
140
142
143 // ###################################################################
145 // ###################################################################
147
148 // ==========================================================================
154 // ==========================================================================
155
156 private:
157 SDYNA(ILearningStrategy* learner,
159 IDecisionStrategy* decider,
160 Idx observationPhaseLenght,
161 Idx nbValueIterationStep,
162 bool actionReward,
163 bool verbose = true);
164
165 // ==========================================================================
167 // ==========================================================================
168
169 public:
170 ~SDYNA();
171
173
174
175 // ###################################################################
177 // ###################################################################
179
180 public:
181 // ==========================================================================
188 // ==========================================================================
189 void addAction(const Idx actionId, std::string_view actionName);
190
191 // ==========================================================================
200 // ==========================================================================
201 void addVariable(const DiscreteVariable* var);
202
204
205
206 // ###################################################################
208 // ###################################################################
210
211 public:
212 // ==========================================================================
216 // ==========================================================================
217 void initialize();
218
219 // ==========================================================================
225 // ==========================================================================
226 void initialize(const Instantiation& initialState);
227
229
230
231 // ###################################################################
233 // ###################################################################
235
236 public:
237 // ==========================================================================
244 // ==========================================================================
245 void setCurrentState(const Instantiation& currentState);
246
247 // ==========================================================================
253 // ==========================================================================
254 Idx takeAction(const Instantiation& curState);
255
256 // ==========================================================================
260 // ==========================================================================
261 Idx takeAction();
262
263 // ==========================================================================
272 // ==========================================================================
273 void feedback(const Instantiation& originalState,
274 const Instantiation& reachedState,
275 Idx performedAction,
276 double obtainedReward);
277
278 // ==========================================================================
288 // ==========================================================================
289 void feedback(const Instantiation& reachedState, double obtainedReward);
290
291 // ==========================================================================
297 // ==========================================================================
298 void makePlanning(Idx nbStep);
299
301
302
303 public:
304 // ==========================================================================
311 // ==========================================================================
312 std::string toString();
313
314 std::string optimalPolicy2String();
315
316 // ###################################################################
320 // ###################################################################
322
323 public:
324 // ==========================================================================
329 // ==========================================================================
331
332 // ==========================================================================
337 // ==========================================================================
338 Size modelSize();
339
340 // ==========================================================================
345 // ==========================================================================
347
348 // ==========================================================================
353 // ==========================================================================
355
357
358
359 protected:
362
365
366 private:
369
372
375
376
379
382
385
388
391
393
395 };
396
397
398} /* namespace gum */
399
400#ifndef GUM_NO_INLINE
402#endif // GUM_NO_INLINE
403#endif // GUM_SDYNA_H
Headers of the epsilon-greedy decision maker class.
Headers of the RMax planer class.
Base class for discrete random variable.
<agrum/FMDP/SDyna/IDecisionStrategy.h>
<agrum/FMDP/SDyna/ILearningStrategy.h>
Class for assigning/browsing values to tuples of discrete variables.
void initialize()
Initializes the Sdyna instance.
Definition sdyna.cpp:121
ILearningStrategy * _learner_
The learner used to learn the FMDP.
Definition sdyna.h:368
Idx _lastAction_
The last performed action.
Definition sdyna.h:387
Idx _nbValueIterationStep_
The number of Value Iteration step we perform.
Definition sdyna.h:384
static SDYNA * spitiInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:48
Instantiation lastState_
The state in which the system is before we perform a new action.
Definition sdyna.h:364
void setCurrentState(const Instantiation &currentState)
Sets last state visited to the given state.
Definition sdyna_inl.h:150
Size valueFunctionSize()
valueFunctionSize
Definition sdyna_inl.h:160
~SDYNA()
Destructor.
Definition sdyna.cpp:102
Idx takeAction()
Definition sdyna.cpp:238
IPlanningStrategy< double > * _planer_
The planer used to plan an optimal strategy.
Definition sdyna.h:371
FMDP< double > * fmdp_
The learnt Markovian Decision Process.
Definition sdyna.h:361
Size optimalPolicySize()
optimalPolicySize
Definition sdyna_inl.h:162
void addAction(const Idx actionId, std::string_view actionName)
Inserts a new action in the SDyna instance.
Definition sdyna_inl.h:144
Set< Observation * > _bin_
Since SDYNA made these observation, it has to delete them on quitting.
Definition sdyna.h:390
Idx _nbObservation_
The total number of observation made so far.
Definition sdyna.h:381
bool _actionReward_
Definition sdyna.h:392
std::string optimalPolicy2String()
Definition sdyna_inl.h:154
static SDYNA * spimddiInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:63
IDecisionStrategy * _decider_
The decider.
Definition sdyna.h:374
static SDYNA * RMaxMDDInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:80
bool verbose_
Definition sdyna.h:394
Size learnerSize()
learnerSize
Definition sdyna_inl.h:156
static SDYNA * RandomTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:129
std::string toString()
Returns.
Definition sdyna.cpp:252
void feedback(const Instantiation &originalState, const Instantiation &reachedState, Idx performedAction, double obtainedReward)
Performs a feedback on the last transition.
Definition sdyna.cpp:153
Size modelSize()
modelSize
Definition sdyna_inl.h:158
void makePlanning(Idx nbStep)
Starts a new planning.
Definition sdyna.cpp:210
Idx _observationPhaseLenght_
The number of observation we make before using again the planer.
Definition sdyna.h:378
static SDYNA * RandomMDDInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:112
static SDYNA * RMaxTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:98
void addVariable(const DiscreteVariable *var)
Inserts a new variable in the SDyna instance.
Definition sdyna_inl.h:148
SDYNA(ILearningStrategy *learner, IPlanningStrategy< double > *planer, IDecisionStrategy *decider, Idx observationPhaseLenght, Idx nbValueIterationStep, bool actionReward, bool verbose=true)
Constructor.
Definition sdyna.cpp:81
Representation of a set.
Definition set.h:129
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
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Headers of the Random decision maker class.
Headers of the Statistical lazy decision maker class.