16 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP 17 #define MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_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; }
99 const double positionMax = 0.5,
100 const double velocityMin = -0.07,
101 const double velocityMax = 0.07) :
102 positionMin(positionMin),
103 positionMax(positionMax),
104 velocityMin(velocityMin),
105 velocityMax(velocityMax)
119 State& nextState)
const 122 double force = std::min(std::max(action.
action[0], -1.0), 1.0);
126 std::max(nextState.
Velocity(), velocityMin), velocityMax);
131 std::max(nextState.
Position(), positionMin), positionMax);
140 return -pow(action.
action[0], 2)*0.1;
154 return Sample(state, action, nextState);
179 return bool(state.
Position() == positionMax);
double Position() const
Get the position.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Position()
Modify the position.
double Sample(const State &state, const Action &action) const
Dynamics of Continuous Mountain Car.
Implementation of state of Continuous Mountain Car.
const arma::colvec & Encode() const
Encode the state to a column vector.
double Velocity() const
Get the velocity.
static constexpr size_t dimension
Dimension of the encoded state.
ContinuousMountainCar(const double positionMin=-1.2, const double positionMax=0.5, const double velocityMin=-0.07, const double velocityMax=0.07)
Construct a Continuous Mountain Car instance using the given constant.
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.
arma::colvec & Data()
Modify the internal representation of the state.
Implementation of action of Continuous Mountain Car.
State()
Construct a state instance.
Implementation of Continuous Mountain Car task.
double Random()
Generates a uniform random number between 0 and 1.
double & Velocity()
Modify the velocity.
bool IsTerminal(const State &state) const
Whether given state is a terminal state.
double Sample(const State &state, const Action &action, State &nextState) const
Dynamics of Continuous Mountain Car.