16 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_PENDULUM_HPP 17 #define MLPACK_METHODS_RL_ENVIRONMENT_PENDULUM_HPP 52 State(
const arma::colvec& data): data(data)
56 arma::colvec&
Data() {
return data; }
59 double Theta()
const {
return data[0]; }
61 double&
Theta() {
return data[0]; }
69 const arma::colvec&
Encode()
const {
return data; }
102 const double maxTorque = 2.0,
103 const double dt = 0.05,
104 const double doneReward = 0.0,
105 const size_t maxSteps = 200) :
106 maxAngularVelocity(maxAngularVelocity),
107 maxTorque(maxTorque),
109 doneReward(doneReward),
131 double theta = state.
Theta();
135 const double gravity = 10.0;
136 const double mass = 1.0;
137 const double length = 1.0;
144 std::pow(angularVelocity, 2) + 0.001 * std::pow(torque, 2);
147 double newAngularVelocity = angularVelocity + (-3.0 * gravity / (2 *
148 length) * std::sin(theta +
M_PI) + 3.0 / (mass * std::pow(length, 2)) *
150 nextState.
Theta() = theta + newAngularVelocity * dt;
152 -maxAngularVelocity, maxAngularVelocity);
169 return Sample(state, action, nextState);
195 double x = fmod(theta +
M_PI, 2 *
M_PI);
209 if (maxSteps != 0 && stepsPerformed >= maxSteps)
211 Log::Info <<
"Episode terminated due to the maximum number of steps" 228 double maxAngularVelocity;
243 size_t stepsPerformed;
double Theta() const
Get the theta.
double & Theta()
Modify the value of theta.
Implementation of Pendulum task.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t MaxSteps() const
Get the maximum number of steps allowed.
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Pendulum.
Pendulum(const double maxAngularVelocity=8, const double maxTorque=2.0, const double dt=0.05, const double doneReward=0.0, const size_t maxSteps=200)
Construct a Pendulum instance using the given values.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Implementation of action of Pendulum.
arma::colvec & Data()
Modify the internal representation of the state.
State(const arma::colvec &data)
Construct a state based on the given data.
double AngleNormalize(double theta) const
This function calculates the normalized angle for a particular theta.
bool IsTerminal(const State &state) const
This function checks if the pendulum has reaches a terminal state.
double AngularVelocity() const
Get the angular velocity.
Miscellaneous math clamping routines.
State()
Construct a state instance.
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
size_t StepsPerformed() const
Get the number of steps performed.
double & AngularVelocity()
Modify the value of angular velocity.
static constexpr size_t dimension
Dimension of the encoded state.
size_t & MaxSteps()
Set the maximum number of steps allowed.
Implementation of state of Pendulum.
double Sample(const State &state, const Action &action)
Dynamics of Pendulum.
double Random()
Generates a uniform random number between 0 and 1.
State InitialSample()
Initial theta is randomly generated within [-pi, pi].
const arma::colvec & Encode() const
Encode the state to a column vector.
double ClampRange(double value, const double rangeMin, const double rangeMax)
Clamp a number between a particular range.