AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::MDP::PolicyWrapper Class Reference

This class provides an MDP Policy interface around a Matrix2D. More...

#include <AIToolbox/MDP/Policies/PolicyWrapper.hpp>

Inheritance diagram for AIToolbox::MDP::PolicyWrapper:
AIToolbox::MDP::PolicyInterface AIToolbox::PolicyInterface< size_t, size_t, size_t > AIToolbox::MDP::Policy

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 PolicyMatrixgetPolicyMatrix () 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_
 

Detailed Description

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.

Member Typedef Documentation

◆ PolicyMatrix

Constructor & Destructor Documentation

◆ PolicyWrapper()

AIToolbox::MDP::PolicyWrapper::PolicyWrapper ( const PolicyMatrix p)

Basic constructor.

The input is assumed to contain a valid policy matrix!

Parameters
pThe policy matrix to wrap.

Member Function Documentation

◆ getActionProbability()

virtual double AIToolbox::MDP::PolicyWrapper::getActionProbability ( const size_t &  s,
const size_t &  a 
) const
overridevirtual

This function returns the probability of taking the specified action in the specified state.

Parameters
sThe selected state.
aThe selected action.
Returns
The probability of taking the selected action in the specified state.

Implements AIToolbox::PolicyInterface< size_t, size_t, size_t >.

◆ getPolicy()

virtual Matrix2D AIToolbox::MDP::PolicyWrapper::getPolicy ( ) const
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.

◆ getPolicyMatrix()

const PolicyMatrix& AIToolbox::MDP::PolicyWrapper::getPolicyMatrix ( ) const

This function enables inspection of the internal policy.

Returns
A constant reference to the internal policy.

◆ sampleAction()

virtual size_t AIToolbox::MDP::PolicyWrapper::sampleAction ( const size_t &  s) const
overridevirtual

This function chooses a random action for state s, following the policy distribution.

Parameters
sThe sampled state of the policy.
Returns
The chosen action.

Implements AIToolbox::PolicyInterface< size_t, size_t, size_t >.


The documentation for this class was generated from the following file: