mlpack
Classes | Public Member Functions | List of all members
mlpack::rl::CartPole Class Reference

Implementation of Cart Pole task. More...

#include <cart_pole.hpp>

Classes

class  Action
 Implementation of action of Cart Pole. More...
 
class  State
 Implementation of the state of Cart Pole. More...
 

Public Member Functions

 CartPole (const size_t maxSteps=200, const double gravity=9.8, const double massCart=1.0, const double massPole=0.1, const double length=0.5, const double forceMag=10.0, const double tau=0.02, const double thetaThresholdRadians=12 *2 *3.1416/360, const double xThreshold=2.4, const double doneReward=1.0)
 Construct a Cart Pole instance using the given constants. More...
 
double Sample (const State &state, const Action &action, State &nextState)
 Dynamics of Cart Pole instance. More...
 
double Sample (const State &state, const Action &action)
 Dynamics of Cart Pole. More...
 
State InitialSample ()
 Initial state representation is randomly generated within [-0.05, 0.05]. More...
 
bool IsTerminal (const State &state) const
 This function checks if the cart has reached the terminal state. More...
 
size_t StepsPerformed () const
 Get the number of steps performed.
 
size_t MaxSteps () const
 Get the maximum number of steps allowed.
 
size_t & MaxSteps ()
 Set the maximum number of steps allowed.
 

Detailed Description

Implementation of Cart Pole task.

Constructor & Destructor Documentation

◆ CartPole()

mlpack::rl::CartPole::CartPole ( const size_t  maxSteps = 200,
const double  gravity = 9.8,
const double  massCart = 1.0,
const double  massPole = 0.1,
const double  length = 0.5,
const double  forceMag = 10.0,
const double  tau = 0.02,
const double  thetaThresholdRadians = 12 * 2 * 3.1416 / 360,
const double  xThreshold = 2.4,
const double  doneReward = 1.0 
)
inline

Construct a Cart Pole instance using the given constants.

Parameters
maxStepsThe number of steps after which the episode terminates. If the value is 0, there is no limit.
gravityThe gravity constant.
massCartThe mass of the cart.
massPoleThe mass of the pole.
lengthThe length of the pole.
forceMagThe magnitude of the applied force.
tauThe time interval.
thetaThresholdRadiansThe maximum angle.
xThresholdThe maximum position.
doneRewardReward recieved by agent on success.

Member Function Documentation

◆ InitialSample()

State mlpack::rl::CartPole::InitialSample ( )
inline

Initial state representation is randomly generated within [-0.05, 0.05].

Returns
Initial state for each episode.

◆ IsTerminal()

bool mlpack::rl::CartPole::IsTerminal ( const State state) const
inline

This function checks if the cart has reached the terminal state.

Parameters
stateThe desired state.
Returns
true if state is a terminal state, otherwise false.

◆ Sample() [1/2]

double mlpack::rl::CartPole::Sample ( const State state,
const Action action,
State nextState 
)
inline

Dynamics of Cart Pole instance.

Get reward and next state based on current state and current action.

Parameters
stateThe current state.
actionThe current action.
nextStateThe next state.
Returns
reward, it's always 1.0.

When done is false, it means that the cartpole has fallen down. For this case the reward is 1.0.

◆ Sample() [2/2]

double mlpack::rl::CartPole::Sample ( const State state,
const Action action 
)
inline

Dynamics of Cart Pole.

Get reward based on current state and current action.

Parameters
stateThe current state.
actionThe current action.
Returns
reward, it's always 1.0.

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