AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::EpsilonPolicyInterface< void, void, Action > Class Template Referenceabstract

This class represents the base interface for epsilon policies in games and bandits. More...

#include <AIToolbox/EpsilonPolicyInterface.hpp>

Inheritance diagram for AIToolbox::EpsilonPolicyInterface< void, void, Action >:
AIToolbox::PolicyInterface< void, void, Action > AIToolbox::Factored::Bandit::EpsilonPolicy

Public Types

using Base = PolicyInterface< void, void, Action >
 

Public Member Functions

 EpsilonPolicyInterface (const Base &p, double epsilon=0.1)
 Basic constructor. More...
 
virtual Action sampleAction () const override
 This function chooses an action, following the policy distribution and epsilon. More...
 
virtual double getActionProbability (const Action &a) const override
 This function returns the probability of taking the specified action. More...
 
void setEpsilon (double e)
 This function sets the epsilon parameter. More...
 
double getEpsilon () const
 This function will return the currently set epsilon parameter. More...
 
- Public Member Functions inherited from AIToolbox::PolicyInterface< void, void, Action >
 PolicyInterface (Action a)
 Basic constructor. More...
 
virtual ~PolicyInterface ()
 Basic virtual destructor. More...
 
const Action & getA () const
 This function returns the number of available actions to the agent. More...
 

Protected Member Functions

virtual Action sampleRandomAction () const =0
 This function returns a random action in the Action space. More...
 
virtual double getRandomActionProbability () const =0
 This function returns the probability of picking a random action. More...
 

Protected Attributes

const Basepolicy_
 
double epsilon_
 
- Protected Attributes inherited from AIToolbox::PolicyInterface< void, void, Action >
Action A
 
RandomEngine rand_
 

Detailed Description

template<typename Action>
class AIToolbox::EpsilonPolicyInterface< void, void, Action >

This class represents the base interface for epsilon policies in games and bandits.

This specialization simply removes the states from the EpsilonPolicyInterface, since in normal games and bandits there is no state, and we can simplify the interface. The rest is the same.

Template Parameters
ActionThis defines the type that is used to handle actions.

Member Typedef Documentation

◆ Base

template<typename Action >
using AIToolbox::EpsilonPolicyInterface< void, void, Action >::Base = PolicyInterface<void, void, Action>

Constructor & Destructor Documentation

◆ EpsilonPolicyInterface()

template<typename Action >
AIToolbox::EpsilonPolicyInterface< void, void, Action >::EpsilonPolicyInterface ( const Base p,
double  epsilon = 0.1 
)

Basic constructor.

This constructor saves the input policy and the epsilon parameter for later use.

The epsilon parameter must be >= 0.0 and <= 1.0, otherwise the constructor will throw an std::invalid_argument.

Parameters
pThe policy that is being extended.
epsilonThe parameter that controls the amount of exploration.

Member Function Documentation

◆ getActionProbability()

template<typename Action >
double AIToolbox::EpsilonPolicyInterface< void, void, Action >::getActionProbability ( const Action &  a) const
overridevirtual

This function returns the probability of taking the specified action.

This function takes into account parameter epsilon while computing the final probability.

Parameters
aThe selected action.
Returns
The probability of taking the selected action.

Implements AIToolbox::PolicyInterface< void, void, Action >.

◆ getEpsilon()

template<typename Action >
double AIToolbox::EpsilonPolicyInterface< void, void, Action >::getEpsilon

This function will return the currently set epsilon parameter.

Returns
The currently set epsilon parameter.

◆ getRandomActionProbability()

template<typename Action >
virtual double AIToolbox::EpsilonPolicyInterface< void, void, Action >::getRandomActionProbability ( ) const
protectedpure virtual

This function returns the probability of picking a random action.

This is simply one over the action space, but since the action space may not be a single number we leave to implementation to decide how to best compute this.

Returns
The probability of picking an an action at random.

Implemented in AIToolbox::Factored::Bandit::EpsilonPolicy.

◆ sampleAction()

template<typename Action >
Action AIToolbox::EpsilonPolicyInterface< void, void, Action >::sampleAction
overridevirtual

This function chooses an action, following the policy distribution and epsilon.

This function has a probability of epsilon of selecting a random action. Otherwise, it selects an action according to the distribution specified by the wrapped policy.

Returns
The chosen action.

Implements AIToolbox::PolicyInterface< void, void, Action >.

◆ sampleRandomAction()

template<typename Action >
virtual Action AIToolbox::EpsilonPolicyInterface< void, void, Action >::sampleRandomAction ( ) const
protectedpure virtual

This function returns a random action in the Action space.

Returns
A valid random action.

Implemented in AIToolbox::Factored::Bandit::EpsilonPolicy.

◆ setEpsilon()

template<typename Action >
void AIToolbox::EpsilonPolicyInterface< void, void, Action >::setEpsilon ( double  e)

This function sets the epsilon parameter.

The epsilon parameter determines the amount of exploration this policy will enforce when selecting actions. In particular actions are going to selected randomly with probability epsilon, and are going to be selected following the underlying policy with probability 1-epsilon.

The epsilon parameter must be >= 0.0 and <= 1.0, otherwise the function will do throw std::invalid_argument.

Parameters
eThe new epsilon parameter.

Member Data Documentation

◆ epsilon_

template<typename Action >
double AIToolbox::EpsilonPolicyInterface< void, void, Action >::epsilon_
protected

◆ policy_

template<typename Action >
const Base& AIToolbox::EpsilonPolicyInterface< void, void, Action >::policy_
protected

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