Implementation of Cart Pole task. More...

Classes

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

 

Public Types

enum  Action
{
  backward
,
  forward
,
  size

}
 Implementation of action of Cart Pole. More...

 

Public Member Functions

 CartPole (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=0.0, const size_t maxSteps=0)
 Construct a Cart Pole instance using the given constants. 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 MaxSteps () const
 Get the maximum number of steps allowed. More...

 
size_t & MaxSteps ()
 Set the maximum number of steps allowed. 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...

 
size_t StepsPerformed () const
 Get the number of steps performed. More...

 

Detailed Description

Implementation of Cart Pole task.

Definition at line 26 of file cart_pole.hpp.

Member Enumeration Documentation

◆ Action

enum Action

Implementation of action of Cart Pole.

Enumerator
backward 
forward 
size 

Definition at line 87 of file cart_pole.hpp.

Constructor & Destructor Documentation

◆ CartPole()

CartPole ( 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 = 0.0,
const size_t  maxSteps = 0 
)
inline

Construct a Cart Pole instance using the given constants.

Parameters
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.
maxStepsThe number of steps after which the episode terminates. If the value is 0, there is no limit.

Definition at line 111 of file cart_pole.hpp.

Member Function Documentation

◆ InitialSample()

State InitialSample ( )
inline

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

Returns
Initial state for each episode.

Definition at line 203 of file cart_pole.hpp.

References CartPole::State::State().

◆ IsTerminal()

bool 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.

Definition at line 215 of file cart_pole.hpp.

References CartPole::State::Angle(), Log::Info, and CartPole::State::Position().

Referenced by CartPole::Sample().

◆ MaxSteps() [1/2]

size_t MaxSteps ( ) const
inline

Get the maximum number of steps allowed.

Definition at line 236 of file cart_pole.hpp.

◆ MaxSteps() [2/2]

size_t& MaxSteps ( )
inline

Set the maximum number of steps allowed.

Definition at line 238 of file cart_pole.hpp.

◆ Sample() [1/2]

double 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.

Definition at line 145 of file cart_pole.hpp.

References CartPole::State::Angle(), CartPole::State::AngularVelocity(), CartPole::IsTerminal(), CartPole::State::Position(), and CartPole::State::Velocity().

Referenced by CartPole::Sample().

◆ Sample() [2/2]

double 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.

Definition at line 192 of file cart_pole.hpp.

References CartPole::Sample().

◆ StepsPerformed()

size_t StepsPerformed ( ) const
inline

Get the number of steps performed.

Definition at line 233 of file cart_pole.hpp.


The documentation for this class was generated from the following file:
  • /home/jenkins-mlpack/mlpack.org/_src/mlpack-3.2.1/src/mlpack/methods/reinforcement_learning/environment/cart_pole.hpp