AIToolbox
A library that offers tools for AI problem solving.
QLearning.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_MDP_QLEARNING_HEADER_FILE
2 #define AI_TOOLBOX_MDP_QLEARNING_HEADER_FILE
3 
4 #include <stddef.h>
5 
9 
10 namespace AIToolbox::MDP {
44  class QLearning {
45  public:
57  QLearning(size_t S, size_t A, double discount = 1.0, double alpha = 0.1);
58 
73  template <IsGenerativeModel M>
74  QLearning(const M& model, double alpha = 0.1);
75 
99  void setLearningRate(double a);
100 
106  double getLearningRate() const;
107 
118  void setDiscount(double d);
119 
125  double getDiscount() const;
126 
139  void stepUpdateQ(size_t s, size_t a, size_t s1, double rew);
140 
146  size_t getS() const;
147 
153  size_t getA() const;
154 
163  const QFunction & getQFunction() const;
164 
176  void setQFunction(const QFunction & qfun);
177 
178  private:
179  size_t S, A;
180  double alpha_;
181  double discount_;
182 
183  QFunction q_;
184  };
185 
186  template <IsGenerativeModel M>
187  QLearning::QLearning(const M& model, const double alpha) :
188  QLearning(model.getS(), model.getA(), model.getDiscount(), alpha) {}
189 }
190 #endif
AIToolbox::MDP::QFunction
Matrix2D QFunction
Definition: Types.hpp:52
AIToolbox::MDP::QLearning::getA
size_t getA() const
This function returns the number of actions on which QLearning is working.
AIToolbox::MDP::QLearning
This class represents the QLearning algorithm.
Definition: QLearning.hpp:44
AIToolbox::MDP::QLearning::QLearning
QLearning(size_t S, size_t A, double discount=1.0, double alpha=0.1)
Basic constructor.
AIToolbox::MDP::QLearning::getDiscount
double getDiscount() const
This function returns the currently set discount parameter.
AIToolbox::MDP::QLearning::getQFunction
const QFunction & getQFunction() const
This function returns a reference to the internal QFunction.
AIToolbox::MDP::QLearning::stepUpdateQ
void stepUpdateQ(size_t s, size_t a, size_t s1, double rew)
This function updates the internal QFunction using the discount set during construction.
AIToolbox::MDP::QLearning::setQFunction
void setQFunction(const QFunction &qfun)
This function allows to directly set the internal QFunction.
AIToolbox::MDP::QLearning::setDiscount
void setDiscount(double d)
This function sets the new discount parameter.
AIToolbox::MDP
Definition: DoubleQLearning.hpp:10
Utils.hpp
Types.hpp
TypeTraits.hpp
AIToolbox::MDP::QLearning::getLearningRate
double getLearningRate() const
This function will return the current set learning rate parameter.
AIToolbox::MDP::QLearning::setLearningRate
void setLearningRate(double a)
This function sets the learning rate parameter.
AIToolbox::MDP::QLearning::getS
size_t getS() const
This function returns the number of states on which QLearning is working.