以下算法有什么问题?
\documentclass[journal]{IEEEtran}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{overpic}
\usepackage{amsmath}
\usepackage{flushend}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{color, soul}
\usepackage[ruled]{algorithm2e}
\begin{algorithm}
\caption{Sample Mixup Algorithm}\label{al_sm}
\LinesNumbered
\KwIn{Training dataset $(X,Y)$, number of training epochs $m$, two parameters $p$ and $q$ satisfying (0 $\leq$ $p$ $<$ $q$ $\leq$ 1), Beta distribution parameter $\alpha$ for sample mixup.}
\For{$i = 1$ $to$ $m$}{
Draw a mini-batch ($x_b$, $y_b$).\\
\uIf(\tcc*[f]{First stage}){$i$ $\leq$ $pm$}{
($\Tilde{x_b}$, $\Tilde{y_b}$) = mixup($x_b$, $y_b$, $\alpha$)}
\uElseIf(\tcc*[f]{Second stage}){$i$ $\leq$ $qm$}{
$\epsilon = \frac{m-i}{m(1-q)}$\\
Randomly generate threshold $\theta\in \mathbb{$[0,1]$}$.\\
\uIf{$\theta < \epsilon$}{
($\Tilde{x_b}$, $\Tilde{y_b}$) = mixup($x_b$, $y_b$, $\alpha$)}
\Else{($\Tilde{x_b}$, $\Tilde{y_b}$) = ($x_b$, $y_b$)}}
\Else(\tcc*[f]{Third stage}){($\Tilde{x_b}$, $\Tilde{y_b}$) = ($x_b$, $y_b$)}
Train model with mini-batch ($\Tilde{x_b}$, $\Tilde{y_b}$).}
\end{algorithm}
答案1
改编
- 添加
document
环境 - 错误消息的原因(
! Extra }, or forgotten $
):更改\mathbb{$[0,1]$}
为[0,1]
(不要再在数学模式中使用数学模式) - 使用缩进以避免丢失代码(和花括号)
- 不要把每一个符号放在单独的数学环境中,例如,
0 $\leq$ $p$ $<$ $q$ $\leq$ 1
应该是$0 \leq p < q \leq 1$
- 为 MWE 提供折扣套餐
代码
\documentclass[journal]{IEEEtran}
\usepackage{amsmath}
\usepackage[ruled]{algorithm2e}
\begin{document}
\begin{algorithm}
\caption{Sample Mixup Algorithm}
\label{al_sm}
\LinesNumbered
\KwIn{Training dataset $(X,Y)$, number of training epochs $m$, two parameters $p$ and $q$ satisfying ($0 \leq p < q \leq 1$), Beta distribution parameter $\alpha$ for sample mixup.}
\For{$i = 1$ to $m$}{
Draw a mini-batch ($x_b$, $y_b$).\\
\uIf(\tcc*[f]{First stage}){$i \leq pm$}{
($\Tilde{x_b}$, $\Tilde{y_b}$) = mixup($x_b$, $y_b$, $\alpha$)
} \uElseIf(\tcc*[f]{Second stage}){$i$ $\leq$ $qm$}{
$\epsilon = \frac{m-i}{m(1-q)}$\\
Randomly generate threshold $\theta\in [0,1]$.\\
\uIf{$\theta < \epsilon$}{
($\Tilde{x_b}$, $\Tilde{y_b}$) = mixup($x_b$, $y_b$, $\alpha$)
} \Else{
($\Tilde{x_b}$, $\Tilde{y_b}$) = ($x_b$, $y_b$)
}
} \Else(\tcc*[f]{Third stage}){
($\Tilde{x_b}$, $\Tilde{y_b}$) = ($x_b$, $y_b$)
}
Train model with mini-batch ($\Tilde{x_b}$, $\Tilde{y_b}$).
}
\end{algorithm}
\end{document}