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

This class implements a greedy policy through a QFunction. More...

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

Inheritance diagram for AIToolbox::MDP::QGreedyPolicy:
AIToolbox::MDP::QPolicyInterface AIToolbox::MDP::PolicyInterface AIToolbox::PolicyInterface< size_t, size_t, size_t >

Public Member Functions

 QGreedyPolicy (const QFunction &q)
 Basic constructor. More...
 
virtual size_t sampleAction (const size_t &s) const override
 This function chooses the greediest action for state s. 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...
 
virtual Matrix2D getPolicy () const override
 This function returns a matrix containing all probabilities of the policy. More...
 
- Public Member Functions inherited from AIToolbox::MDP::QPolicyInterface
 QPolicyInterface (const QFunction &q)
 Basic constructor. More...
 
const QFunctiongetQFunction () const
 This function returns the underlying QFunction reference. 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

- Public Types inherited from AIToolbox::MDP::PolicyInterface
using Base = AIToolbox::PolicyInterface< size_t, size_t, size_t >
 
- Protected Attributes inherited from AIToolbox::MDP::QPolicyInterface
const QFunctionq_
 
- Protected Attributes inherited from AIToolbox::PolicyInterface< size_t, size_t, size_t >
size_t S
 
size_t A
 
RandomEngine rand_
 

Detailed Description

This class implements a greedy policy through a QFunction.

This class allows you to select effortlessly the best greedy actions from a given QFunction.

Constructor & Destructor Documentation

◆ QGreedyPolicy()

AIToolbox::MDP::QGreedyPolicy::QGreedyPolicy ( const QFunction q)

Basic constructor.

Parameters
qThe QFunction this policy is linked with.

Member Function Documentation

◆ getActionProbability()

virtual double AIToolbox::MDP::QGreedyPolicy::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.

If multiple greedy actions exist, this function returns the correct probability of picking each one, since we return a random one with sampleAction().

Parameters
sThe selected state.
aThe selected action.
Returns
This function returns 0 if the action is not greedy, and 1/the number of greedy actions otherwise.

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

◆ getPolicy()

virtual Matrix2D AIToolbox::MDP::QGreedyPolicy::getPolicy ( ) const
overridevirtual

This function returns a matrix containing all probabilities of the policy.

Computing this function is approximately a bit more efficient than calling repeatedly the getActionProbability() function over and over, since it does not need to find out the maxima of the underlying QFunction over and over.

Ideally this function can be called only when there is a repeated need to access the same policy values in an efficient manner.

Implements AIToolbox::MDP::PolicyInterface.

◆ sampleAction()

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

This function chooses the greediest action for state s.

If multiple actions would be equally as greedy, a random one is returned.

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: