17 #ifndef MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP 18 #define MLPACK_METHODS_RL_ENVIRONMENT_CONTINUOUS_MOUNTAIN_CAR_HPP 50 State(
const arma::colvec& data): data(data)
54 arma::colvec&
Data() {
return data; }
67 const arma::colvec&
Encode()
const {
return data; }
106 const double positionMax = 0.6,
107 const double positionGoal = 0.45,
108 const double velocityMin = -0.07,
109 const double velocityMax = 0.07,
110 const double duration = 0.0015,
111 const double doneReward = 100,
112 const size_t maxSteps = 0) :
113 positionMin(positionMin),
114 positionMax(positionMax),
115 positionGoal(positionGoal),
116 velocityMin(velocityMin),
117 velocityMax(velocityMax),
119 doneReward(doneReward),
146 velocityMin, velocityMax);
149 positionMin, positionMax);
157 if (done && maxSteps != 0 && stepsPerformed >= maxSteps)
162 return std::pow(action.
action[0], 2) * 0.1;
176 return Sample(state, action, nextState);
202 if (maxSteps != 0 && stepsPerformed >= maxSteps)
204 Log::Info <<
"Episode terminated due to the maximum number of steps" 208 else if (state.
Position() >= positionGoal)
210 Log::Info <<
"Episode terminated due to agent succeeding.";
250 size_t stepsPerformed;
double Position() const
Get the position.
Linear algebra utility functions, generally performed on matrices or vectors.
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.
Miscellaneous math clamping routines.
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].
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 duration=0.0015, const double doneReward=100, const size_t maxSteps=0)
Construct a Continuous Mountain Car instance using the given constant.
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.
double ClampRange(double value, const double rangeMin, const double rangeMax)
Clamp a number between a particular range.