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)
 Construct a Cart Pole instance using the given constants. More...

 
State InitialSample () const
 Initial state representation is randomly generated within [-0.05, 0.05]. More...

 
bool IsTerminal (const State &state) const
 Whether given state is a terminal state. More...

 
double Sample (const State &state, const Action &action, State &nextState) const
 Dynamics of Cart Pole instance. More...

 
double Sample (const State &state, const Action &action) const
 Dynamics of Cart Pole. 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 
)
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.

Definition at line 108 of file cart_pole.hpp.

Member Function Documentation

◆ InitialSample()

State InitialSample ( ) const
inline

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

Returns
Initial state for each episode.

Definition at line 192 of file cart_pole.hpp.

References CartPole::State::State().

◆ IsTerminal()

bool IsTerminal ( const State state) const
inline

Whether given state is a terminal state.

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

Definition at line 203 of file cart_pole.hpp.

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

Referenced by CartPole::Sample().

◆ Sample() [1/2]

double Sample ( const State state,
const Action action,
State nextState 
) const
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.

It is important to note that if the cartpole is falling down, it should be penalized.

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

Definition at line 139 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 
) const
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 181 of file cart_pole.hpp.

References CartPole::Sample().


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