AIToolbox
A library that offers tools for AI problem solving.
|
This class provides an MDP Policy interface around a Matrix2D. More...
#include <AIToolbox/MDP/Policies/PolicyWrapper.hpp>
Public Types | |
using | PolicyMatrix = Matrix2D |
Public Types inherited from AIToolbox::MDP::PolicyInterface | |
using | Base = AIToolbox::PolicyInterface< size_t, size_t, size_t > |
Public Member Functions | |
PolicyWrapper (const PolicyMatrix &p) | |
Basic constructor. More... | |
virtual size_t | sampleAction (const size_t &s) const override |
This function chooses a random action for state s, following the policy distribution. More... | |
virtual double | getActionProbability (const size_t &s, const size_t &a) const override |
This function returns the probability of taking the specified action in the specified state. More... | |
const PolicyMatrix & | getPolicyMatrix () const |
This function enables inspection of the internal policy. More... | |
virtual Matrix2D | getPolicy () const override |
This function returns a matrix containing all probabilities of the policy. More... | |
Public Member Functions inherited from AIToolbox::PolicyInterface< size_t, size_t, size_t > | |
PolicyInterface (size_t s, size_t a) | |
Basic constructor. More... | |
virtual | ~PolicyInterface () |
Basic virtual destructor. More... | |
const size_t & | getS () const |
This function returns the number of states of the world. More... | |
const size_t & | getA () const |
This function returns the number of available actions to the agent. More... | |
Additional Inherited Members | |
Protected Attributes inherited from AIToolbox::PolicyInterface< size_t, size_t, size_t > | |
size_t | S |
size_t | A |
RandomEngine | rand_ |
This class provides an MDP Policy interface around a Matrix2D.
This class reads from the input reference to a Matrix2D in order to provide a simple interface to use a policy.
This class exists so that you can handle your own policy matrix efficiently. This class will NEVER check the consistency of the matrix, so that is up to you.
This class expects that the input matrix represents a valid probability, so each row should sum up to one, and no element should be negative or over one.
If you are looking for a self-contained version of this class that can more easily interact with the other classes in the library, look for Policy.
AIToolbox::MDP::PolicyWrapper::PolicyWrapper | ( | const PolicyMatrix & | p | ) |
Basic constructor.
The input is assumed to contain a valid policy matrix!
p | The policy matrix to wrap. |
|
overridevirtual |
This function returns the probability of taking the specified action in the specified state.
s | The selected state. |
a | The selected action. |
Implements AIToolbox::PolicyInterface< size_t, size_t, size_t >.
|
overridevirtual |
This function returns a matrix containing all probabilities of the policy.
This is simply a copy of the internal policy.
WARNING: If you just want a reference to the internal policy, use getPolicyMatrix().
Implements AIToolbox::MDP::PolicyInterface.
const PolicyMatrix& AIToolbox::MDP::PolicyWrapper::getPolicyMatrix | ( | ) | const |
This function enables inspection of the internal policy.
|
overridevirtual |
This function chooses a random action for state s, following the policy distribution.
s | The sampled state of the policy. |
Implements AIToolbox::PolicyInterface< size_t, size_t, size_t >.