17 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP 18 #define MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP 49 State(
const arma::colvec& data): data(data)
53 arma::colvec&
Data() {
return data; }
66 const arma::colvec&
Encode()
const {
return data; }
102 const double positionMax = 0.6,
103 const double positionGoal = 0.45,
104 const double velocityMin = -0.07,
105 const double velocityMax = 0.07,
106 const double power = 0.0015) :
107 positionMin(positionMin),
108 positionMax(positionMax),
109 positionGoal(positionGoal),
110 velocityMin(velocityMin),
111 velocityMax(velocityMax),
126 State& nextState)
const 129 double force = std::min(std::max(action.
action[0], -1.0), 1.0);
135 std::max(nextState.
Velocity(), velocityMin), velocityMax);
138 std::max(nextState.
Position(), positionMin), positionMax);
147 reward -= std::pow(action.
action[0], 2) * 0.1;
162 return Sample(state, action, nextState);
187 return bool(state.
Position() >= positionGoal);
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.
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.
ContinuousMountainCar(const double positionMin=-1.2, const double positionMax=0.6, const double positionGoal=0.45, const double velocityMin=-0.07, const double velocityMax=0.07, const double power=0.0015)
Construct a Continuous Mountain Car instance using the given constant.