Pendulum Class Reference

Implementation of Pendulum task. More...

Classes

struct  Action
 Implementation of action of Pendulum. More...

 
class  State
 Implementation of state of Pendulum. More...

 

Public Member Functions

 Pendulum (const double maxAngularVelocity=8, const double maxTorque=2.0, const double dt=0.05, const double angleThreshold=M_PI/12, const double doneReward=0.0, const size_t maxSteps=0)
 Construct a Pendulum instance using the given values. More...

 
double AngleNormalize (double theta) const
 This function calculates the normalized angle for a particular theta. More...

 
State InitialSample ()
 Initial theta is randomly generated within [-pi, pi]. More...

 
bool IsTerminal (const State &state) const
 This function checks if the pendulum has reaches a 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 Pendulum. More...

 
double Sample (const State &state, const Action &action)
 Dynamics of Pendulum. More...

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

 

Detailed Description

Implementation of Pendulum task.

The inverted pendulum swingup problem is a classic problem in the control literature. In this version of the problem, the pendulum starts in a random position, and the goal is to swing it up so it stays upright

Definition at line 30 of file pendulum.hpp.

Constructor & Destructor Documentation

◆ Pendulum()

Pendulum ( const double  maxAngularVelocity = 8,
const double  maxTorque = 2.0,
const double  dt = 0.05,
const double  angleThreshold = M_PI / 12,
const double  doneReward = 0.0,
const size_t  maxSteps = 0 
)
inline

Construct a Pendulum instance using the given values.

Parameters
maxAngularVelocityMaximum angular velocity.
maxTorqueMaximum torque.
dtThe differential value.
angleThresholdThe region about the upright position where the state is considered terminal.
doneRewardThe reward recieved by the agent on success.
maxStepsThe number of steps after which the episode terminates. If the value is 0, there is no limit.

Definition at line 102 of file pendulum.hpp.

Member Function Documentation

◆ AngleNormalize()

double AngleNormalize ( double  theta) const
inline

This function calculates the normalized angle for a particular theta.

Parameters
thetaThe un-normalized angle.

Definition at line 205 of file pendulum.hpp.

References M_PI.

Referenced by Pendulum::Sample().

◆ InitialSample()

State InitialSample ( )
inline

Initial theta is randomly generated within [-pi, pi].

Initial angular velocity is randomly generated within [-1, 1].

Returns
Initial state for each episode.

Definition at line 191 of file pendulum.hpp.

References Pendulum::State::AngularVelocity(), M_PI, mlpack::math::Random(), and Pendulum::State::Theta().

◆ IsTerminal()

bool IsTerminal ( const State state) const
inline

This function checks if the pendulum has reaches a terminal state.

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

Definition at line 217 of file pendulum.hpp.

References Log::Info, M_PI, and Pendulum::State::Theta().

Referenced by Pendulum::Sample().

◆ MaxSteps() [1/2]

size_t MaxSteps ( ) const
inline

Get the maximum number of steps allowed.

Definition at line 238 of file pendulum.hpp.

◆ MaxSteps() [2/2]

size_t& MaxSteps ( )
inline

Set the maximum number of steps allowed.

Definition at line 240 of file pendulum.hpp.

◆ Sample() [1/2]

double Sample ( const State state,
const Action action,
State nextState 
)
inline

Dynamics of Pendulum.

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

Parameters
stateThe current state.
actionThe current action.
nextStateThe next state.
Returns
reward, The reward for taking the action taken for current state.

Definition at line 126 of file pendulum.hpp.

References Pendulum::Action::action, Pendulum::AngleNormalize(), Pendulum::State::AngularVelocity(), Pendulum::IsTerminal(), M_PI, and Pendulum::State::Theta().

Referenced by Pendulum::Sample().

◆ Sample() [2/2]

double Sample ( const State state,
const Action action 
)
inline

Dynamics of Pendulum.

Get reward based on current state and current action

Parameters
stateThe current state.
actionThe current action.
Returns
reward, The reward.

Definition at line 179 of file pendulum.hpp.

References Pendulum::Sample().

◆ StepsPerformed()

size_t StepsPerformed ( ) const
inline

Get the number of steps performed.

Definition at line 235 of file pendulum.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/pendulum.hpp