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 const double doneReward = 0) :
101 positionMin(positionMin),
102 positionMax(positionMax),
103 velocityMin(velocityMin),
104 velocityMax(velocityMax),
105 doneReward(doneReward)
119 State& nextState)
const 122 int direction = action - 1;
126 std::max(nextState.
Velocity(), velocityMin), velocityMax);
131 std::max(nextState.
Position(), positionMin), positionMax);
133 if (std::abs(nextState.
Position() - positionMin) <= 1e-5)
161 return Sample(state, action, nextState);
174 state.
Position() = arma::as_scalar(arma::randu(1)) * 0.2 - 0.6;
186 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.
MountainCar(const double positionMin=-1.2, const double positionMax=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.
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.
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.