AIToolbox
A library that offers tools for AI problem solving.
DoubleQLearning.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_MDP_DOUBLE_QLEARNING_HEADER_FILE
2 #define AI_TOOLBOX_MDP_DOUBLE_QLEARNING_HEADER_FILE
3 
4 #include <stddef.h>
5 
9 
10 namespace AIToolbox::MDP {
47  public:
59  DoubleQLearning(size_t S, size_t A, double discount = 1.0, double alpha = 0.1);
60 
75  template <IsGenerativeModel M>
76  DoubleQLearning(const M& model, double alpha = 0.1);
77 
101  void setLearningRate(double a);
102 
108  double getLearningRate() const;
109 
122  void setDiscount(double d);
123 
129  double getDiscount() const;
130 
143  void stepUpdateQ(size_t s, size_t a, size_t s1, double rew);
144 
150  size_t getS() const;
151 
157  size_t getA() const;
158 
172  const QFunction & getQFunction() const;
173 
183  const QFunction & getQFunctionA() const;
184 
192  QFunction getQFunctionB() const;
193 
208  void setQFunction(const QFunction & qfun);
209 
210  private:
211  size_t S, A;
212  double alpha_;
213  double discount_;
214 
215  mutable RandomEngine rand_;
216  std::bernoulli_distribution dist_;
217 
218  // First QFunction and "sum" QFunction
219  QFunction qa_, qc_;
220  };
221 
222  template <IsGenerativeModel M>
223  DoubleQLearning::DoubleQLearning(const M& model, const double alpha) :
224  DoubleQLearning(model.getS(), model.getA(), model.getDiscount(), alpha) {}
225 }
226 
227 #endif
AIToolbox::MDP::DoubleQLearning::getLearningRate
double getLearningRate() const
This function will return the current set learning rate parameter.
AIToolbox::MDP::DoubleQLearning::getQFunctionB
QFunction getQFunctionB() const
This function returns a copy to the second QFunction.
AIToolbox::MDP::DoubleQLearning::setQFunction
void setQFunction(const QFunction &qfun)
This function allows to directly set the internal QFunctions.
AIToolbox::MDP::DoubleQLearning::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::QFunction
Matrix2D QFunction
Definition: Types.hpp:52
AIToolbox::MDP::DoubleQLearning::getDiscount
double getDiscount() const
This function returns the currently set discount parameter.
AIToolbox::MDP::DoubleQLearning::setDiscount
void setDiscount(double d)
This function sets the new discount parameter.
AIToolbox::MDP::DoubleQLearning::getQFunction
const QFunction & getQFunction() const
This function returns a reference to the internal "sum" QFunction.
AIToolbox::MDP::DoubleQLearning
This class represents the double QLearning algorithm.
Definition: DoubleQLearning.hpp:46
AIToolbox::MDP::DoubleQLearning::getA
size_t getA() const
This function returns the number of actions on which DoubleQLearning is working.
AIToolbox::MDP
Definition: DoubleQLearning.hpp:10
Utils.hpp
AIToolbox::RandomEngine
std::mt19937 RandomEngine
Definition: Types.hpp:14
Types.hpp
TypeTraits.hpp
AIToolbox::MDP::DoubleQLearning::getS
size_t getS() const
This function returns the number of states on which DoubleQLearning is working.
AIToolbox::MDP::DoubleQLearning::DoubleQLearning
DoubleQLearning(size_t S, size_t A, double discount=1.0, double alpha=0.1)
Basic constructor.
AIToolbox::MDP::DoubleQLearning::getQFunctionA
const QFunction & getQFunctionA() const
This function returns a reference to the first internal QFunction.
AIToolbox::MDP::DoubleQLearning::setLearningRate
void setLearningRate(double a)
This function sets the learning rate parameter.