Go to the documentation of this file.
16 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP
17 #define MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP
49 State(
const arma::colvec& data): data(data)
53 arma::colvec&
Data() {
return data; }
66 const arma::colvec&
Encode()
const {
return data; }
92 static const size_t size = 3;
108 const double positionMin = -1.2,
109 const double positionMax = 0.6,
110 const double positionGoal = 0.5,
111 const double velocityMin = -0.07,
112 const double velocityMax = 0.07,
113 const double doneReward = 0) :
115 positionMin(positionMin),
116 positionMax(positionMax),
117 positionGoal(positionGoal),
118 velocityMin(velocityMin),
119 velocityMax(velocityMax),
120 doneReward(doneReward),
141 int direction = action.
action - 1;
145 velocityMin, velocityMax);
150 positionMin, positionMax);
159 if (done && maxSteps != 0 && stepsPerformed >= maxSteps)
178 return Sample(state, action, nextState);
192 state.
Position() = arma::as_scalar(arma::randu(1)) * 0.2 - 0.6;
204 if (maxSteps != 0 && stepsPerformed >= maxSteps)
206 Log::Info <<
"Episode terminated due to the maximum number of steps"
210 else if (state.
Position() >= positionGoal)
212 Log::Info <<
"Episode terminated due to agent succeeding.";
249 size_t stepsPerformed;
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t MaxSteps() const
Get the maximum number of steps allowed.
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Mountain Car.
State InitialSample()
Initial position is randomly generated within [-0.6, -0.4].
double ClampRange(double value, const double rangeMin, const double rangeMax)
Clamp a number between a particular range.
double Velocity() const
Get the velocity.
Implementation of action of Mountain Car.
double Position() const
Get the position.
Linear algebra utility functions, generally performed on matrices or vectors.
Implementation of Mountain Car task.
size_t & MaxSteps()
Set the maximum number of steps allowed.
MountainCar(const size_t maxSteps=200, const double positionMin=-1.2, const double positionMax=0.6, const double positionGoal=0.5, const double velocityMin=-0.07, const double velocityMax=0.07, const double doneReward=0)
Construct a Mountain Car instance using the given constant.
double & Velocity()
Modify the velocity.
bool IsTerminal(const State &state) const
This function checks if the car has reached the terminal state.
static constexpr size_t dimension
Dimension of the encoded state.
size_t StepsPerformed() const
Get the number of steps performed.
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
double Sample(const State &state, const Action &action)
Dynamics of Mountain Car.
Miscellaneous math clamping routines.
const arma::colvec & Encode() const
Encode the state to a column vector.
Implementation of state of Mountain Car.
arma::colvec & Data()
Modify the internal representation of the state.
State(const arma::colvec &data)
Construct a state based on the given data.
State()
Construct a state instance.
double & Position()
Modify the position.