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; }
97 const double positionMax = 0.5,
98 const double velocityMin = -0.07,
99 const double velocityMax = 0.07) :
100 positionMin(positionMin),
101 positionMax(positionMax),
102 velocityMin(velocityMin),
103 velocityMax(velocityMax)
117 State& nextState)
const 120 int direction = action - 1;
124 std::max(nextState.
Velocity(), velocityMin), velocityMax);
129 std::max(nextState.
Position(), positionMin), positionMax);
131 if (std::abs(nextState.
Position() - positionMin) <= 1e-5)
150 return Sample(state, action, nextState);
163 state.
Position() = arma::as_scalar(arma::randu(1)) * 0.2 - 0.6;
175 return std::abs(state.
Position() - positionMax) <= 1e-5;
double Sample(const State &state, const Action &action, State &nextState) const
Dynamics of Mountain Car.
bool IsTerminal(const State &state) const
Whether given state is a terminal state.
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.
State InitialSample() const
Initial position is randomly generated within [-0.6, -0.4].
State(const arma::colvec &data)
Construct a state based on the given data.
MountainCar(const double positionMin=-1.2, const double positionMax=0.5, const double velocityMin=-0.07, const double velocityMax=0.07)
Construct a Mountain Car instance using the given constant.
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.
double Sample(const State &state, const Action &action) const
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.