AIToolbox
A library that offers tools for AI problem solving.
PolicyInterface.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_POLICYINTERFACE_HEADER_FILE
2 #define AI_TOOLBOX_POLICYINTERFACE_HEADER_FILE
3 
4 #include <AIToolbox/Types.hpp>
5 #include <AIToolbox/Seeder.hpp>
6 
7 namespace AIToolbox {
30  template <typename State, typename Sampling, typename Action>
32  public:
40 
44  virtual ~PolicyInterface();
45 
53  virtual Action sampleAction(const Sampling & s) const = 0;
54 
63  virtual double getActionProbability(const Sampling & s, const Action & a) const = 0;
64 
70  const State & getS() const;
71 
77  const Action & getA() const;
78 
79  protected:
82 
83  // This is mutable because sampling doesn't really change the policy
85  };
86 
87  template <typename State, typename Sampling, typename Action>
89  S(std::move(s)), A(std::move(a)), rand_(Seeder::getSeed()) {}
90 
91  template <typename State, typename Sampling, typename Action>
93 
94  template <typename State, typename Sampling, typename Action>
96 
97  template <typename State, typename Sampling, typename Action>
99 
109  template <typename Action>
110  class PolicyInterface<void, void, Action> {
111  public:
118 
122  virtual ~PolicyInterface();
123 
129  virtual Action sampleAction() const = 0;
130 
138  virtual double getActionProbability(const Action & a) const = 0;
139 
145  const Action & getA() const;
146 
147  protected:
149 
150  // This is mutable because sampling doesn't really change the policy
152  };
153 
154  template <typename Action>
156  A(std::move(a)), rand_(Seeder::getSeed()) {}
157 
158  template <typename Action>
160 
161  template <typename Action>
163 }
164 
165 #endif
AIToolbox::PolicyInterface::getA
const Action & getA() const
This function returns the number of available actions to the agent.
Definition: PolicyInterface.hpp:98
AIToolbox::Seeder
This class is an internal class used to seed all random engines in the library.
Definition: Seeder.hpp:15
AIToolbox::POMDP::TigerProblemUtils::State
State
Definition: TigerProblem.hpp:15
AIToolbox::PolicyInterface
This class represents the base interface for policies.
Definition: PolicyInterface.hpp:31
AIToolbox::PolicyInterface< void, void, Action >::rand_
RandomEngine rand_
Definition: PolicyInterface.hpp:151
AIToolbox
Definition: Experience.hpp:6
AIToolbox::PolicyInterface< void, void, Action >::A
Action A
Definition: PolicyInterface.hpp:148
Seeder.hpp
AIToolbox::RandomEngine
std::mt19937 RandomEngine
Definition: Types.hpp:14
AIToolbox::PolicyInterface::sampleAction
virtual Action sampleAction(const Sampling &s) const =0
This function chooses a random action for state s, following the policy distribution.
Types.hpp
AIToolbox::PolicyInterface::getActionProbability
virtual double getActionProbability(const Sampling &s, const Action &a) const =0
This function returns the probability of taking the specified action in the specified state.
AIToolbox::PolicyInterface::PolicyInterface
PolicyInterface(State s, Action a)
Basic constructor.
Definition: PolicyInterface.hpp:88
AIToolbox::PolicyInterface::rand_
RandomEngine rand_
Definition: PolicyInterface.hpp:84
AIToolbox::POMDP::TigerProblemUtils::Action
Action
Definition: TigerProblem.hpp:9
AIToolbox::PolicyInterface::getS
const State & getS() const
This function returns the number of states of the world.
Definition: PolicyInterface.hpp:95
AIToolbox::PolicyInterface::~PolicyInterface
virtual ~PolicyInterface()
Basic virtual destructor.
Definition: PolicyInterface.hpp:92
AIToolbox::PolicyInterface::S
State S
Definition: PolicyInterface.hpp:80
AIToolbox::PolicyInterface::A
Action A
Definition: PolicyInterface.hpp:81