\section{Cart\+Pole Class Reference}
\label{classmlpack_1_1rl_1_1CartPole}\index{Cart\+Pole@{Cart\+Pole}}


Implementation of Cart Pole task.  


\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
class \textbf{ State}
\begin{DoxyCompactList}\small\item\em Implementation of the state of Cart Pole. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Types}
\begin{DoxyCompactItemize}
\item 
enum \textbf{ Action} \{ \newline
\textbf{ backward}, 
\newline
\textbf{ forward}, 
\newline
\textbf{ size}
 \}\begin{DoxyCompactList}\small\item\em Implementation of action of Cart Pole. \end{DoxyCompactList}
\end{DoxyCompactItemize}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ Cart\+Pole} (const double gravity=9.\+8, const double mass\+Cart=1.\+0, const double mass\+Pole=0.\+1, const double length=0.\+5, const double force\+Mag=10.\+0, const double tau=0.\+02, const double theta\+Threshold\+Radians=12 $\ast$2 $\ast$3.\+1416/360, const double x\+Threshold=2.\+4, const double done\+Reward=0.\+0, const size\+\_\+t max\+Steps=0)
\begin{DoxyCompactList}\small\item\em Construct a Cart Pole instance using the given constants. \end{DoxyCompactList}\item 
\textbf{ State} \textbf{ Initial\+Sample} ()
\begin{DoxyCompactList}\small\item\em Initial state representation is randomly generated within [-\/0.\+05, 0.\+05]. \end{DoxyCompactList}\item 
bool \textbf{ Is\+Terminal} (const \textbf{ State} \&state) const
\begin{DoxyCompactList}\small\item\em This function checks if the cart has reached the terminal state. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Max\+Steps} () const
\begin{DoxyCompactList}\small\item\em Get the maximum number of steps allowed. \end{DoxyCompactList}\item 
size\+\_\+t \& \textbf{ Max\+Steps} ()
\begin{DoxyCompactList}\small\item\em Set the maximum number of steps allowed. \end{DoxyCompactList}\item 
double \textbf{ Sample} (const \textbf{ State} \&state, const \textbf{ Action} \&action, \textbf{ State} \&next\+State)
\begin{DoxyCompactList}\small\item\em Dynamics of Cart Pole instance. \end{DoxyCompactList}\item 
double \textbf{ Sample} (const \textbf{ State} \&state, const \textbf{ Action} \&action)
\begin{DoxyCompactList}\small\item\em Dynamics of Cart Pole. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Steps\+Performed} () const
\begin{DoxyCompactList}\small\item\em Get the number of steps performed. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Implementation of Cart Pole task. 

Definition at line 26 of file cart\+\_\+pole.\+hpp.



\subsection{Member Enumeration Documentation}
\mbox{\label{classmlpack_1_1rl_1_1CartPole_a8bb1ef53467e4f61410d12822d922498}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Action@{Action}}
\index{Action@{Action}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Action}
{\footnotesize\ttfamily enum \textbf{ Action}}



Implementation of action of Cart Pole. 

\begin{DoxyEnumFields}{Enumerator}
\raisebox{\heightof{T}}[0pt][0pt]{\index{backward@{backward}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!backward@{backward}}}\mbox{\label{classmlpack_1_1rl_1_1CartPole_a8bb1ef53467e4f61410d12822d922498ab3d7481243d86f5bf31d617c7ba70220}} 
backward&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{forward@{forward}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!forward@{forward}}}\mbox{\label{classmlpack_1_1rl_1_1CartPole_a8bb1ef53467e4f61410d12822d922498a726a0af5164861adac8c015a742dcf21}} 
forward&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{size@{size}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!size@{size}}}\mbox{\label{classmlpack_1_1rl_1_1CartPole_a8bb1ef53467e4f61410d12822d922498a052a2b4924452fb4a73f2cb52b6e9d41}} 
size&\\
\hline

\end{DoxyEnumFields}


Definition at line 87 of file cart\+\_\+pole.\+hpp.



\subsection{Constructor \& Destructor Documentation}
\mbox{\label{classmlpack_1_1rl_1_1CartPole_afaface5b8713f50a05c53ee2e2331808}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Cart\+Pole@{Cart\+Pole}}
\index{Cart\+Pole@{Cart\+Pole}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Cart\+Pole()}
{\footnotesize\ttfamily \textbf{ Cart\+Pole} (\begin{DoxyParamCaption}\item[{const double}]{gravity = {\ttfamily 9.8},  }\item[{const double}]{mass\+Cart = {\ttfamily 1.0},  }\item[{const double}]{mass\+Pole = {\ttfamily 0.1},  }\item[{const double}]{length = {\ttfamily 0.5},  }\item[{const double}]{force\+Mag = {\ttfamily 10.0},  }\item[{const double}]{tau = {\ttfamily 0.02},  }\item[{const double}]{theta\+Threshold\+Radians = {\ttfamily 12~$\ast$~2~$\ast$~3.1416~/~360},  }\item[{const double}]{x\+Threshold = {\ttfamily 2.4},  }\item[{const double}]{done\+Reward = {\ttfamily 0.0},  }\item[{const size\+\_\+t}]{max\+Steps = {\ttfamily 0} }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Construct a Cart Pole instance using the given constants. 


\begin{DoxyParams}{Parameters}
{\em gravity} & The gravity constant. \\
\hline
{\em mass\+Cart} & The mass of the cart. \\
\hline
{\em mass\+Pole} & The mass of the pole. \\
\hline
{\em length} & The length of the pole. \\
\hline
{\em force\+Mag} & The magnitude of the applied force. \\
\hline
{\em tau} & The time interval. \\
\hline
{\em theta\+Threshold\+Radians} & The maximum angle. \\
\hline
{\em x\+Threshold} & The maximum position. \\
\hline
{\em done\+Reward} & Reward recieved by agent on success. \\
\hline
{\em max\+Steps} & The number of steps after which the episode terminates. If the value is 0, there is no limit. \\
\hline
\end{DoxyParams}


Definition at line 111 of file cart\+\_\+pole.\+hpp.



\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1rl_1_1CartPole_aa9f537249fa0c1e62b38197996ab4c6a}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Initial\+Sample@{Initial\+Sample}}
\index{Initial\+Sample@{Initial\+Sample}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Initial\+Sample()}
{\footnotesize\ttfamily \textbf{ State} Initial\+Sample (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Initial state representation is randomly generated within [-\/0.\+05, 0.\+05]. 

\begin{DoxyReturn}{Returns}
Initial state for each episode. 
\end{DoxyReturn}


Definition at line 203 of file cart\+\_\+pole.\+hpp.



References Cart\+Pole\+::\+State\+::\+State().

\mbox{\label{classmlpack_1_1rl_1_1CartPole_a7fd056133dfd315e4bf45c408f99326f}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Is\+Terminal@{Is\+Terminal}}
\index{Is\+Terminal@{Is\+Terminal}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Is\+Terminal()}
{\footnotesize\ttfamily bool Is\+Terminal (\begin{DoxyParamCaption}\item[{const \textbf{ State} \&}]{state }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



This function checks if the cart has reached the terminal state. 


\begin{DoxyParams}{Parameters}
{\em state} & The desired state. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if state is a terminal state, otherwise false. 
\end{DoxyReturn}


Definition at line 215 of file cart\+\_\+pole.\+hpp.



References Cart\+Pole\+::\+State\+::\+Angle(), Log\+::\+Info, and Cart\+Pole\+::\+State\+::\+Position().



Referenced by Cart\+Pole\+::\+Sample().

\mbox{\label{classmlpack_1_1rl_1_1CartPole_ad8fd6d8f7581c82e73556491b79a8907}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Max\+Steps@{Max\+Steps}}
\index{Max\+Steps@{Max\+Steps}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Max\+Steps()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily size\+\_\+t Max\+Steps (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the maximum number of steps allowed. 



Definition at line 236 of file cart\+\_\+pole.\+hpp.

\mbox{\label{classmlpack_1_1rl_1_1CartPole_a64c84cebc489c6fdfd7f057e127b0aef}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Max\+Steps@{Max\+Steps}}
\index{Max\+Steps@{Max\+Steps}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Max\+Steps()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t\& Max\+Steps (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Set the maximum number of steps allowed. 



Definition at line 238 of file cart\+\_\+pole.\+hpp.

\mbox{\label{classmlpack_1_1rl_1_1CartPole_a311ac19edc537dee94f37b7cce93d908}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Sample@{Sample}}
\index{Sample@{Sample}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Sample()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily double Sample (\begin{DoxyParamCaption}\item[{const \textbf{ State} \&}]{state,  }\item[{const \textbf{ Action} \&}]{action,  }\item[{\textbf{ State} \&}]{next\+State }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Dynamics of Cart Pole instance. 

Get reward and next state based on current state and current action.


\begin{DoxyParams}{Parameters}
{\em state} & The current state. \\
\hline
{\em action} & The current action. \\
\hline
{\em next\+State} & The next state. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
reward, it\textquotesingle{}s always 1.\+0. 
\end{DoxyReturn}
When done is false, it means that the cartpole has fallen down. For this case the reward is 1.\+0.

Definition at line 145 of file cart\+\_\+pole.\+hpp.



References Cart\+Pole\+::\+State\+::\+Angle(), Cart\+Pole\+::\+State\+::\+Angular\+Velocity(), Cart\+Pole\+::\+Is\+Terminal(), Cart\+Pole\+::\+State\+::\+Position(), and Cart\+Pole\+::\+State\+::\+Velocity().



Referenced by Cart\+Pole\+::\+Sample().

\mbox{\label{classmlpack_1_1rl_1_1CartPole_af2bb860eaefeaa62a40f5cf940793704}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Sample@{Sample}}
\index{Sample@{Sample}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Sample()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily double Sample (\begin{DoxyParamCaption}\item[{const \textbf{ State} \&}]{state,  }\item[{const \textbf{ Action} \&}]{action }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Dynamics of Cart Pole. 

Get reward based on current state and current action.


\begin{DoxyParams}{Parameters}
{\em state} & The current state. \\
\hline
{\em action} & The current action. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
reward, it\textquotesingle{}s always 1.\+0. 
\end{DoxyReturn}


Definition at line 192 of file cart\+\_\+pole.\+hpp.



References Cart\+Pole\+::\+Sample().

\mbox{\label{classmlpack_1_1rl_1_1CartPole_a5fe06563064ebcee88c593e1673f03d4}} 
\index{mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}!Steps\+Performed@{Steps\+Performed}}
\index{Steps\+Performed@{Steps\+Performed}!mlpack\+::rl\+::\+Cart\+Pole@{mlpack\+::rl\+::\+Cart\+Pole}}
\subsubsection{Steps\+Performed()}
{\footnotesize\ttfamily size\+\_\+t Steps\+Performed (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the number of steps performed. 



Definition at line 233 of file cart\+\_\+pole.\+hpp.



The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/var/www/mlpack.\+ratml.\+org/mlpack.\+org/\+\_\+src/mlpack-\/3.\+3.\+0/src/mlpack/methods/reinforcement\+\_\+learning/environment/\textbf{ cart\+\_\+pole.\+hpp}\end{DoxyCompactItemize}
