AIToolbox
A library that offers tools for AI problem solving.
ExpectedSARSA.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_MDP_EXPECTED_SARSA_HEADER_FILE
2 #define AI_TOOLBOX_MDP_EXPECTED_SARSA_HEADER_FILE
3 
4 #include <stddef.h>
5 
10 
11 namespace AIToolbox::MDP {
37  class ExpectedSARSA {
38  public:
61  ExpectedSARSA(QFunction & qfun, const PolicyInterface & policy, double discount = 0.0, double alpha = 0.1);
62 
89  template <IsGenerativeModel M>
90  ExpectedSARSA(QFunction & qfun, const PolicyInterface & policy, const M& model, double alpha = 0.1);
91 
115  void setLearningRate(double a);
116 
122  double getLearningRate() const;
123 
136  void setDiscount(double d);
137 
143  double getDiscount() const;
144 
162  void stepUpdateQ(size_t s, size_t a, size_t s1, double rew);
163 
169  size_t getS() const;
170 
176  size_t getA() const;
177 
186  const QFunction & getQFunction() const;
187 
193  const PolicyInterface & getPolicy() const;
194 
195  private:
196  const PolicyInterface & policy_;
197  size_t S, A;
198  double alpha_;
199  double discount_;
200 
201  QFunction & q_;
202  };
203 
204  template <IsGenerativeModel M>
205  ExpectedSARSA::ExpectedSARSA(QFunction & qfun, const PolicyInterface & policy, const M& model, const double alpha) :
206  ExpectedSARSA(qfun, policy, model.getDiscount(), alpha) {}
207 }
208 #endif
AIToolbox::MDP::ExpectedSARSA::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::ExpectedSARSA::ExpectedSARSA
ExpectedSARSA(QFunction &qfun, const PolicyInterface &policy, double discount=0.0, double alpha=0.1)
Basic constructor.
AIToolbox::MDP::ExpectedSARSA::setDiscount
void setDiscount(double d)
This function sets the new discount parameter.
PolicyInterface.hpp
AIToolbox::MDP::QFunction
Matrix2D QFunction
Definition: Types.hpp:52
AIToolbox::MDP::ExpectedSARSA::getQFunction
const QFunction & getQFunction() const
This function returns a reference to the internal QFunction.
AIToolbox::MDP::ExpectedSARSA::getLearningRate
double getLearningRate() const
This function will return the current set learning rate parameter.
AIToolbox::MDP::ExpectedSARSA
This class represents the ExpectedSARSA algorithm.
Definition: ExpectedSARSA.hpp:37
AIToolbox::MDP
Definition: DoubleQLearning.hpp:10
Utils.hpp
AIToolbox::MDP::ExpectedSARSA::setLearningRate
void setLearningRate(double a)
This function sets the learning rate parameter.
AIToolbox::MDP::ExpectedSARSA::getPolicy
const PolicyInterface & getPolicy() const
This function returns a reference to the policy used by ExpectedSARSA.
AIToolbox::MDP::ExpectedSARSA::getDiscount
double getDiscount() const
This function returns the currently set discount parameter.
Types.hpp
TypeTraits.hpp
AIToolbox::MDP::PolicyInterface
Simple typedef for most of MDP's policy needs.
Definition: PolicyInterface.hpp:11
AIToolbox::MDP::ExpectedSARSA::getS
size_t getS() const
This function returns the number of states on which QLearning is working.
AIToolbox::MDP::ExpectedSARSA::getA
size_t getA() const
This function returns the number of actions on which QLearning is working.