16 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP 17 #define MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP 89 Action::actions action;
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;
double Sample(const State &state, const Action &action)
Dynamics of Mountain Car.
Definition: mountain_car.hpp:175
Implementation of action of Mountain Car.
Definition: mountain_car.hpp:79
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Mountain Car.
Definition: mountain_car.hpp:133
double Velocity() const
Get the velocity.
Definition: mountain_car.hpp:56
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.
Definition: mountain_car.hpp:107
size_t & MaxSteps()
Set the maximum number of steps allowed.
Definition: mountain_car.hpp:224
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
size_t MaxSteps() const
Get the maximum number of steps allowed.
Definition: mountain_car.hpp:222
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::colvec & Data()
Modify the internal representation of the state.
Definition: mountain_car.hpp:53
Miscellaneous math clamping routines.
bool IsTerminal(const State &state) const
This function checks if the car has reached the terminal state.
Definition: mountain_car.hpp:202
double Position() const
Get the position.
Definition: mountain_car.hpp:61
size_t StepsPerformed() const
Get the number of steps performed.
Definition: mountain_car.hpp:219
State(const arma::colvec &data)
Construct a state based on the given data.
Definition: mountain_car.hpp:49
Implementation of state of Mountain Car.
Definition: mountain_car.hpp:35
const arma::colvec & Encode() const
Encode the state to a column vector.
Definition: mountain_car.hpp:66
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
Definition: log.hpp:84
double & Velocity()
Modify the velocity.
Definition: mountain_car.hpp:58
State InitialSample()
Initial position is randomly generated within [-0.6, -0.4].
Definition: mountain_car.hpp:187
Implementation of Mountain Car task.
Definition: mountain_car.hpp:28
static constexpr size_t dimension
Dimension of the encoded state.
Definition: mountain_car.hpp:69
State()
Construct a state instance.
Definition: mountain_car.hpp:41
double & Position()
Modify the position.
Definition: mountain_car.hpp:63
double ClampRange(double value, const double rangeMin, const double rangeMax)
Clamp a number between a particular range.
Definition: clamp.hpp:53