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

Implementation of Pendulum task. More...

#include <pendulum.hpp>

Classes

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

Public Member Functions

 Pendulum (const size_t maxSteps=200, const double maxAngularVelocity=8, const double maxTorque=2.0, const double dt=0.05, const double doneReward=0.0)
 Construct a Pendulum instance using the given values. 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...
 
State InitialSample ()
 Initial theta is randomly generated within [-pi, pi]. More...
 
double AngleNormalize (double theta) const
 This function calculates the normalized angle for a particular theta. More...
 
bool IsTerminal (const State &) const
 This function checks if the pendulum has reaches a 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 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

Constructor & Destructor Documentation

◆ Pendulum()

mlpack::rl::Pendulum::Pendulum ( const size_t  maxSteps = 200,
const double  maxAngularVelocity = 8,
const double  maxTorque = 2.0,
const double  dt = 0.05,
const double  doneReward = 0.0 
)
inline

Construct a Pendulum instance using the given values.

Parameters
maxStepsThe number of steps after which the episode terminates. If the value is 0, there is no limit (Default: 200 steps).
maxAngularVelocityMaximum angular velocity.
maxTorqueMaximum torque.
dtThe differential value.
doneRewardThe reward recieved by the agent on success.

Member Function Documentation

◆ AngleNormalize()

double mlpack::rl::Pendulum::AngleNormalize ( double  theta) const
inline

This function calculates the normalized angle for a particular theta.

Parameters
thetaThe un-normalized angle.

◆ InitialSample()

State mlpack::rl::Pendulum::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.

◆ IsTerminal()

bool mlpack::rl::Pendulum::IsTerminal ( const State ) const
inline

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

Parameters
*(state) desired state.
Returns
true if state is a terminal state, otherwise false.

◆ Sample() [1/2]

double mlpack::rl::Pendulum::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.

◆ Sample() [2/2]

double mlpack::rl::Pendulum::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.

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