使用 algorithm2e 时出现“缺少 $ 插入”错误

使用 algorithm2e 时出现“缺少 $ 插入”错误

你好,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} 

相关内容