![使用 algorithm2e 时出现“缺少 $ 插入”错误](https://linux22.com/image/449879/%E4%BD%BF%E7%94%A8%20algorithm2e%20%E6%97%B6%E5%87%BA%E7%8E%B0%E2%80%9C%E7%BC%BA%E5%B0%91%20%24%20%E6%8F%92%E5%85%A5%E2%80%9D%E9%94%99%E8%AF%AF.png)
你好,Latex 社区,
我正在编写一个算法,但是 TEX 生成器显示错误“在算法的最后一行 (\end{algorithm}) 中缺少 $ 插入错误!!!你能帮帮我吗!!
\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}