Go to the documentation of this file.
17 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP
18 #define MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP
50 State(
const arma::colvec& data): data(data)
54 arma::colvec&
Data() {
return data; }
67 const arma::colvec&
Encode()
const {
return data; }
106 const double positionMax = 0.6,
107 const double positionGoal = 0.45,
108 const double velocityMin = -0.07,
109 const double velocityMax = 0.07,
110 const double duration = 0.0015,
111 const double doneReward = 100,
112 const size_t maxSteps = 0) :
113 positionMin(positionMin),
114 positionMax(positionMax),
115 positionGoal(positionGoal),
116 velocityMin(velocityMin),
117 velocityMax(velocityMax),
119 doneReward(doneReward),
146 velocityMin, velocityMax);
149 positionMin, positionMax);
157 if (done && maxSteps != 0 && stepsPerformed >= maxSteps)
162 return std::pow(action.
action[0], 2) * 0.1;
176 return Sample(state, action, nextState);
202 if (maxSteps != 0 && stepsPerformed >= maxSteps)
204 Log::Info <<
"Episode terminated due to the maximum number of steps"
208 else if (state.
Position() >= positionGoal)
210 Log::Info <<
"Episode terminated due to agent succeeding.";
250 size_t stepsPerformed;
static constexpr size_t dimension
Dimension of the encoded state.
double Velocity() const
Get the velocity.
Implementation of action of Continuous Mountain Car.
Implementation of state of Continuous Mountain Car.
The core includes that mlpack expects; standard C++ includes and Armadillo.
ContinuousMountainCar(const double positionMin=-1.2, const double positionMax=0.6, const double positionGoal=0.45, const double velocityMin=-0.07, const double velocityMax=0.07, const double duration=0.0015, const double doneReward=100, const size_t maxSteps=0)
Construct a Continuous Mountain Car instance using the given constant.
double ClampRange(double value, const double rangeMin, const double rangeMax)
Clamp a number between a particular range.
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Continuous Mountain Car.
size_t MaxSteps() const
Get the maximum number of steps allowed.
arma::colvec & Data()
Modify the internal representation of the state.
State()
Construct a state instance.
bool IsTerminal(const State &state) const
Whether given state is a terminal state.
double Sample(const State &state, const Action &action)
Dynamics of Continuous Mountain Car.
Linear algebra utility functions, generally performed on matrices or vectors.
double & Velocity()
Modify the velocity.
double Random()
Generates a uniform random number between 0 and 1.
const arma::colvec & Encode() const
Encode the state to a column vector.
State(const arma::colvec &data)
Construct a state based on the given data.
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.
Implementation of Continuous Mountain Car task.
double Position() const
Get the position.
size_t & MaxSteps()
Set the maximum number of steps allowed.
Miscellaneous math clamping routines.
double & Position()
Modify the position.
State InitialSample()
Initial position is randomly generated within [-0.6, -0.4].