16 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP 17 #define MLPACK_METHODS_RL_ENVIRONMENT_MOUNTAIN_CAR_HPP 48 State(
const arma::colvec& data): data(data)
52 arma::colvec&
Data() {
return data; }
65 const arma::colvec&
Encode()
const {
return data; }
101 const double positionMax = 0.6,
102 const double positionGoal = 0.5,
103 const double velocityMin = -0.07,
104 const double velocityMax = 0.07,
105 const double doneReward = 0,
106 const size_t maxSteps = 0) :
107 positionMin(positionMin),
108 positionMax(positionMax),
109 positionGoal(positionGoal),
110 velocityMin(velocityMin),
111 velocityMax(velocityMax),
112 doneReward(doneReward),
134 int direction = action - 1;
138 std::max(nextState.
Velocity(), velocityMin), velocityMax);
143 std::max(nextState.
Position(), positionMin), positionMax);
152 if (done && maxSteps != 0 && stepsPerformed >= maxSteps)
171 return Sample(state, action, nextState);
185 state.
Position() = arma::as_scalar(arma::randu(1)) * 0.2 - 0.6;
197 if (maxSteps != 0 && stepsPerformed >= maxSteps)
199 Log::Info <<
"Episode terminated due to the maximum number of steps" 203 else if (state.
Position() >= positionGoal)
205 Log::Info <<
"Episode terminated due to agent succeeding.";
242 size_t stepsPerformed;
bool IsTerminal(const State &state) const
This function checks if the car has reached the terminal state.
size_t MaxSteps() const
Get the maximum number of steps allowed.
State InitialSample()
Initial position is randomly generated within [-0.6, -0.4].
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::colvec & Encode() const
Encode the state to a column vector.
double & Position()
Modify the position.
double & Velocity()
Modify the velocity.
MountainCar(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, const size_t maxSteps=0)
Construct a Mountain Car instance using the given constant.
double Sample(const State &state, const Action &action)
Dynamics of Mountain Car.
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
State(const arma::colvec &data)
Construct a state based on the given data.
Track the size of the action space.
Action
Implementation of action of Mountain Car.
arma::colvec & Data()
Modify the internal representation of the state.
Implementation of state of Mountain Car.
State()
Construct a state instance.
Implementation of Mountain Car task.
size_t StepsPerformed() const
Get the number of steps performed.
size_t & MaxSteps()
Set the maximum number of steps allowed.
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Mountain Car.
double Position() const
Get the position.
static constexpr size_t dimension
Dimension of the encoded state.
double Velocity() const
Get the velocity.