# "Missing $inserted " error while using algorithm2e Hello Latex Community, I'm writing an algorithm but the TEX maker is showing an error "missing$ inserted error in the last line of the algorithm (\end{algorithm})!!! Could you please help me !!

     \begin{algorithm}[hbt!]
\DontPrintSemicolon
\caption{Double $Q$-learning algorithm pseudo-code}\label{alg2}
\KwInput{ $\delta \in \left[ 0,1 \right]$ (discount factor), $\alpha \in \left ( 0,1 \right]$ (learning rate), $\epsilon \in \left [ 0,1 \right)$
(exploration rate),   $rand_{\epsilon}$, $rand_q$ (random numbers $\in \left[ 0,1 \right]$ generated every time step)}.  %\vspace{1mm}
\For{every state-action pair:}{
initialize $Q_A(s,a)$  and $Q_B(s,a)$ tables \; \Comment*[r]
{\footnotesize usually by zeros matrices}
}

\For{every learning episode:}{
\While{state $\neq$ final state}{
\For{each time step:}{
observe the current state $S_t$ \;

\eIf{$rand_{\epsilon}$ \textless  $\epsilon$}{
$A_t =\max \limits_{a} \left[Q_A(S_t,a)+Q_B(S_t,a)\right]$  \;   \Comment*[r]
{\footnotesize exploitation}
}{
$A_t= \text{a random action}$ \;        \Comment*[r]{\footnotesize
exploration}
}
perform action $A_t$, observe $S_{t+1}$ and $R_{t+1}$ \;

\eIf{$rand_q < 0.5$} {\Comment*[r]{\footnotesize with 0.5 probability}

\begin{matrix*}[l]
Q_A(S_t,A_t)  \gets (1-\alpha) Q_A(S_t,A_t)+ \\
\alpha\left[R_{t+1}+\delta \max \limits_{a}Q_B(S_{t+1},\max \limits_{a}Q_A(s,a))\right]
\end{matrix*}
}{
\begin{matrix*}[l]
Q_B(S_t,A_t)  \gets (1-\alpha) Q_B(S_t,A_t)+\\
\alpha\left[R_{t+1}+\delta \max \limits_{a}Q_A(S_{t+1},\max \limits_{a}Q_B(s,a))\right]
\end{matrix*}
}
\Comment*[r]{\footnotesize $Q$ tables updating}
$S_t \gets S_{t+1}$  \;              \Comment*

[r]{\footnotesize state updating}
}
}
}
\end{algorithm}

• Welcome to TeX.SE.
– Mico
May 11 at 13:43
• Please tell us which LaTeX packages must be loaded in order to get your code to compile.
– Mico
May 11 at 13:48
• Off-topic: Is there a reason for writing $rand_{\epsilon}$ \textless $\epsilon$ instead of $rand_{\epsilon}<\epsilon$?
– Mico
May 11 at 13:51
• \usepackage{mathtools} \usepackage[linesnumbered,ruled]{algorithm2e} \usepackage{amsfonts, amssymb, amsmath} May 11 at 15:02
• @Mico Thanks for your answer. There in no reason, but i think it is the same ! May 11 at 15:13