aGrUM  0.16.0
sdyna.h
Go to the documentation of this file.
1 
30 // =========================================================================
31 #ifndef GUM_SDYNA_H
32 #define GUM_SDYNA_H
33 // =========================================================================
34 #include <agrum/agrum.h>
36 // =========================================================================
38 // =========================================================================
46 #include <agrum/FMDP/fmdp.h>
52 // =========================================================================
53 
54 namespace gum {
55 
66  class SDYNA {
67  // ###################################################################
69  // ###################################################################
71  public:
72  // ==========================================================================
74  // ==========================================================================
75  static SDYNA* spitiInstance(double attributeSelectionThreshold = 0.99,
76  double discountFactor = 0.9,
77  double epsilon = 1,
78  Idx observationPhaseLenght = 100,
79  Idx nbValueIterationStep = 10) {
80  bool actionReward = false;
82  attributeSelectionThreshold, actionReward);
84  StructuredPlaner< double >::sviInstance(discountFactor, epsilon);
86  return new SDYNA(
87  ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
88  }
89 
90  // ==========================================================================
92  // ==========================================================================
93  static SDYNA* spimddiInstance(double attributeSelectionThreshold = 0.99,
94  double similarityThreshold = 0.3,
95  double discountFactor = 0.9,
96  double epsilon = 1,
97  Idx observationPhaseLenght = 100,
98  Idx nbValueIterationStep = 10) {
99  bool actionReward = false;
101  attributeSelectionThreshold, actionReward, similarityThreshold);
103  discountFactor, epsilon, false);
105  return new SDYNA(ls,
106  ps,
107  ds,
108  observationPhaseLenght,
109  nbValueIterationStep,
110  actionReward,
111  false);
112  }
113 
114  // ==========================================================================
116  // ==========================================================================
117  static SDYNA* RMaxMDDInstance(double attributeSelectionThreshold = 0.99,
118  double similarityThreshold = 0.3,
119  double discountFactor = 0.9,
120  double epsilon = 1,
121  Idx observationPhaseLenght = 100,
122  Idx nbValueIterationStep = 10) {
123  bool actionReward = true;
125  attributeSelectionThreshold, actionReward, similarityThreshold);
127  ls, discountFactor, epsilon);
129  IDecisionStrategy* ds = rm;
130  return new SDYNA(
131  ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
132  }
133 
134  // ==========================================================================
136  // ==========================================================================
137  static SDYNA* RMaxTreeInstance(double attributeSelectionThreshold = 0.99,
138  double discountFactor = 0.9,
139  double epsilon = 1,
140  Idx observationPhaseLenght = 100,
141  Idx nbValueIterationStep = 10) {
142  bool actionReward = true;
144  attributeSelectionThreshold, actionReward);
145  AdaptiveRMaxPlaner* rm =
146  AdaptiveRMaxPlaner::TreeInstance(ls, discountFactor, epsilon);
148  IDecisionStrategy* ds = rm;
149  return new SDYNA(
150  ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
151  }
152 
153  // ==========================================================================
155  // ==========================================================================
156  static SDYNA* RandomMDDInstance(double attributeSelectionThreshold = 0.99,
157  double similarityThreshold = 0.3,
158  double discountFactor = 0.9,
159  double epsilon = 1,
160  Idx observationPhaseLenght = 100,
161  Idx nbValueIterationStep = 10) {
162  bool actionReward = true;
164  attributeSelectionThreshold, actionReward, similarityThreshold);
166  StructuredPlaner< double >::spumddInstance(discountFactor, epsilon);
167  IDecisionStrategy* ds = new RandomDecider();
168  return new SDYNA(
169  ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
170  }
171 
172  // ==========================================================================
174  // ==========================================================================
175  static SDYNA* RandomTreeInstance(double attributeSelectionThreshold = 0.99,
176  double discountFactor = 0.9,
177  double epsilon = 1,
178  Idx observationPhaseLenght = 100,
179  Idx nbValueIterationStep = 10) {
180  bool actionReward = true;
182  attributeSelectionThreshold, actionReward);
184  StructuredPlaner< double >::sviInstance(discountFactor, epsilon);
185  IDecisionStrategy* ds = new RandomDecider();
186  return new SDYNA(
187  ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
188  }
189 
190 
192 
193  // ###################################################################
195  // ###################################################################
197 
198  // ==========================================================================
204  // ==========================================================================
205  private:
206  SDYNA(ILearningStrategy* learner,
208  IDecisionStrategy* decider,
209  Idx observationPhaseLenght,
210  Idx nbValueIterationStep,
211  bool actionReward,
212  bool verbose = true);
213 
214  // ==========================================================================
216  // ==========================================================================
217  public:
218  ~SDYNA();
219 
221 
222 
223  // ###################################################################
225  // ###################################################################
227  public:
228  // ==========================================================================
235  // ==========================================================================
236  void addAction(const Idx actionId, const std::string& actionName) {
237  _fmdp->addAction(actionId, actionName);
238  }
239 
240  // ==========================================================================
249  // ==========================================================================
250  void addVariable(const DiscreteVariable* var) { _fmdp->addVariable(var); }
251 
253 
254 
255  // ###################################################################
257  // ###################################################################
259  public:
260  // ==========================================================================
264  // ==========================================================================
265  void initialize();
266 
267  // ==========================================================================
273  // ==========================================================================
274  void initialize(const Instantiation& initialState);
275 
277 
278 
279  // ###################################################################
281  // ###################################################################
283  public:
284  // ==========================================================================
291  // ==========================================================================
292  void setCurrentState(const Instantiation& currentState) {
293  _lastState = currentState;
294  }
295 
296  // ==========================================================================
302  // ==========================================================================
303  Idx takeAction(const Instantiation& curState);
304 
305  // ==========================================================================
309  // ==========================================================================
310  Idx takeAction();
311 
312  // ==========================================================================
321  // ==========================================================================
322  void feedback(const Instantiation& originalState,
323  const Instantiation& reachedState,
324  Idx performedAction,
325  double obtainedReward);
326 
327  // ==========================================================================
337  // ==========================================================================
338  void feedback(const Instantiation& reachedState, double obtainedReward);
339 
340  // ==========================================================================
346  // ==========================================================================
347  void makePlanning(Idx nbStep);
348 
350 
351 
352  public:
353  // ==========================================================================
360  // ==========================================================================
361  std::string toString();
362 
364 
365 
366  // ###################################################################
370  // ###################################################################
372  public:
373  // ==========================================================================
378  // ==========================================================================
379  Size learnerSize() { return __learner->size(); }
380 
381  // ==========================================================================
386  // ==========================================================================
387  Size modelSize() { return _fmdp->size(); }
388 
389  // ==========================================================================
394  // ==========================================================================
396 
397  // ==========================================================================
402  // ==========================================================================
404 
406 
407 
408  protected:
411 
414 
415  private:
418 
421 
424 
425 
428 
431 
434 
437 
440 
442 
443  bool _verbose;
444  };
445 
446 
447 } /* namespace gum */
448 
449 
450 #endif // GUM_SDYNA_H
static StructuredPlaner< GUM_SCALAR > * sviInstance(GUM_SCALAR discountFactor=0.9, GUM_SCALAR epsilon=0.00001, bool verbose=true)
~SDYNA()
Destructor.
Definition: sdyna.cpp:79
virtual std::string optimalPolicy2String()=0
Returns a string describing the optimal policy in a dot format.
std::string optimalPolicy2String()
Definition: sdyna.h:363
std::string toString()
Returns.
Definition: sdyna.cpp:232
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Idx takeAction()
Definition: sdyna.cpp:218
<agrum/FMDP/SDyna/IDecisionStrategy.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Instantiation _lastState
The state in which the system is before we perform a new action.
Definition: sdyna.h:413
void setCurrentState(const Instantiation &currentState)
Sets last state visited to the given state.
Definition: sdyna.h:292
Idx __lastAction
The last performed action.
Definition: sdyna.h:436
SDYNA(ILearningStrategy *learner, IPlanningStrategy< double > *planer, IDecisionStrategy *decider, Idx observationPhaseLenght, Idx nbValueIterationStep, bool actionReward, bool verbose=true)
Constructor.
Definition: sdyna.cpp:57
static AdaptiveRMaxPlaner * ReducedAndOrderedInstance(const ILearningStrategy *learner, double discountFactor=0.9, double epsilon=0.00001, bool verbose=true)
bool _verbose
Definition: sdyna.h:443
static SDYNA * RMaxTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition: sdyna.h:137
void feedback(const Instantiation &originalState, const Instantiation &reachedState, Idx performedAction, double obtainedReward)
Performs a feedback on the last transition.
Definition: sdyna.cpp:130
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual Size optimalPolicySize()=0
Returns optimalPolicy computed so far current size.
Base class for discrete random variable.
IPlanningStrategy< double > * __planer
The planer used to plan an optimal strategy.
Definition: sdyna.h:420
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void addVariable(const DiscreteVariable *var)
Inserts a new variable in the SDyna instance.
Definition: sdyna.h:250
static SDYNA * RandomTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition: sdyna.h:175
ILearningStrategy * __learner
The learner used to learn the FMDP.
Definition: sdyna.h:417
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The general SDyna architecture abstract class.
Definition: sdyna.h:66
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void addVariable(const DiscreteVariable *var)
Adds a variable to FMDP description.
Definition: fmdp_tpl.h:124
Size learnerSize()
learnerSize
Definition: sdyna.h:379
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/FMDP/SDyna/ILearningStrategy.h>
<agrum/FMDP/decision/E_GreedyDecider.h>
Class to make decision randomlyDoes nothing more than the interface for DecisionStrategy does...
Definition: randomDecider.h:49
Size valueFunctionSize()
valueFunctionSize
Definition: sdyna.h:395
Size size() const
Returns the map binding main variables and prime variables.
Definition: fmdp_tpl.h:392
static AdaptiveRMaxPlaner * TreeInstance(const ILearningStrategy *learner, double discountFactor=0.9, double epsilon=0.00001, bool verbose=true)
Idx __observationPhaseLenght
The number of observation we make before using again the planer.
Definition: sdyna.h:427
void addAction(const Idx actionId, const std::string &actionName)
Inserts a new action in the SDyna instance.
Definition: sdyna.h:236
Idx __nbObservation
The total number of observation made so far.
Definition: sdyna.h:430
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.h:117
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static SDYNA * spitiInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition: sdyna.h:75
void makePlanning(Idx nbStep)
Starts a new planning.
Definition: sdyna.cpp:190
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void initialize()
Initializes the Sdyna instance.
Definition: sdyna.cpp:98
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
FMDP< double > * _fmdp
The learnt Markovian Decision Process.
Definition: sdyna.h:410
<agrum/FMDP/planning/adaptiveRMaxPlaner.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.h:93
virtual Size size()=0
learnerSize
Size optimalPolicySize()
optimalPolicySize
Definition: sdyna.h:403
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size Idx
Type for indexes.
Definition: types.h:53
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.h:156
virtual Size vFunctionSize()=0
Returns vFunction computed so far current size.
IDecisionStrategy * __decider
The decider.
Definition: sdyna.h:423
bool __actionReward
Definition: sdyna.h:441
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size modelSize()
modelSize
Definition: sdyna.h:387
Idx __nbValueIterationStep
The number of Value Iteration step we perform.
Definition: sdyna.h:433
Set< Observation *> __bin
Since SDYNA made these observation, it has to delete them on quitting.
Definition: sdyna.h:439
static StructuredPlaner< GUM_SCALAR > * spumddInstance(GUM_SCALAR discountFactor=0.9, GUM_SCALAR epsilon=0.00001, bool verbose=true)
void addAction(Idx actionId, const std::string &action)
Adds an action to FMDP description.
Definition: fmdp_tpl.h:153
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.