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; }
105 const double positionMax = 0.6,
106 const double positionGoal = 0.45,
107 const double velocityMin = -0.07,
108 const double velocityMax = 0.07,
109 const double power = 0.0015,
110 const double doneReward = 100,
111 const size_t maxSteps = 0) :
112 positionMin(positionMin),
113 positionMax(positionMax),
114 positionGoal(positionGoal),
115 velocityMin(velocityMin),
116 velocityMax(velocityMax),
118 doneReward(doneReward),
139 double force = std::min(std::max(action.
action[0], -1.0), 1.0);
145 std::max(nextState.
Velocity(), velocityMin), velocityMax);
148 std::max(nextState.
Position(), positionMin), positionMax);
156 if (done && maxSteps != 0 && stepsPerformed >= maxSteps)
161 return std::pow(action.
action[0], 2) * 0.1;
175 return Sample(state, action, nextState);
201 if (maxSteps != 0 && stepsPerformed >= maxSteps)
203 Log::Info <<
"Episode terminated due to the maximum number of steps" 207 else if (state.
Position() >= positionGoal)
209 Log::Info <<
"Episode terminated due to agent succeeding.";
249 size_t stepsPerformed;
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, const double doneReward=100, const size_t maxSteps=0)
Construct a Continuous Mountain Car instance using the given constant.
double Position() const
Get the position.
double Sample(const State &state, const Action &action)
Dynamics of Continuous Mountain Car.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Position()
Modify the position.
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.
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.
arma::colvec & Data()
Modify the internal representation of the state.
Implementation of action of Continuous Mountain Car.
State()
Construct a state instance.
size_t & MaxSteps()
Set the maximum number of steps allowed.
Implementation of Continuous Mountain Car task.
double Random()
Generates a uniform random number between 0 and 1.
size_t MaxSteps() const
Get the maximum number of steps allowed.
size_t StepsPerformed() const
Get the number of steps performed.
double & Velocity()
Modify the velocity.
State InitialSample()
Initial position is randomly generated within [-0.6, -0.4].
bool IsTerminal(const State &state) const
Whether given state is a terminal state.
double Sample(const State &state, const Action &action, State &nextState)
Dynamics of Continuous Mountain Car.