我试图模仿这个算法,但布局不起作用。我怎样才能得到相同的布局(或接近的布局)?请参阅图片下方的代码。
我正在使用 algo 软件包和可从其下载的 algo.sty 链接,我还添加了代码。如果您知道如何在没有此软件包或其他软件包的情况下制作类似的东西,非常欢迎!
与该包结合使用时,\usepackage{algorithm}
它不起作用。
\documentstyle{article}
%\usepackage{algorithm}% when I add this package it is not working, but i need this package for other code
\usepackage[named]{algo}
%You can download algo.sty from:
%https://www.win.tue.nl/~kbuchin/teaching/algo.sty
\begin{document}
\begin{algorithm}{SMOTE}[$T$,~$N$,~$k$] {
\qinput{Number of minority class samples $T$; Amount of SMOTE $N$\%; Number of nearest neighbors $k$}
\qoutput{($N/100$) * $T$ synthetic minority class samples}}
\qcom{{\it{If $N$ is less than 100\%, randomize the minority class samples as only a random percent
of them will be SMOTEd.}}} \\
\qif $N < 100$ \\
\qthen Randomize the $T$ minority class samples \\
$T = (N/100) * T$ \\
$N = 100$
\qfi \\
{\bf{endif}} \\
$ N = (int)(N/100) $ \qcom{{\it{The amount of SMOTE is assumed to be in integral multiples of 100.}}} \\
$k$ = Number of nearest neighbors \\
$numattrs$ = Number of attributes \\
$Sample[~][~]$: array for original minority class samples \\
$newindex$: keeps a count of number of synthetic samples generated, initialized to 0 \\
$Synthetic[~][~]$: array for synthetic samples \newline
\qcom{{\it{Compute $k$ nearest neighbors for each minority class sample only.}}}\\
\qfor $i \qlet 1$ \qto $T$ \\
Compute $k$ nearest neighbors for $i$, and save the indices in the $nnarray$ \\
Populate($N$, $i$, $nnarray$) \qrof \\
{\bf{endfor}} \newline
\qproc[N,~i,~nnarray]{Populate} \qcom{{\it{Function to generate the synthetic samples.}}} \\
\qwhile $N \neq 0$ \\
Choose a random number between $1$ and $k$, call it $nn$. This step chooses one of the $k$ nearest
neighbors of $i$. \\
\qfor $attr \qlet 1$ \qto $numattrs$ \\
Compute: $dif = Sample[nnarray[nn]][attr] - Sample[i][attr]$ \\
Compute: $gap$ = random number between 0 and 1 \\
$Synthetic[newindex][attr] = Sample[i][attr] + gap * dif$ \qrof \\
{\bf{endfor}} \\
$newindex$++ \\
$N = N - 1$ \qelihw \\
{\bf{endwhile}} \\
\qreturn \qcom{{\it{End of Populate.}}}\newline
End of Pseudo-Code.
\end{algorithm}
\end{document}
编辑: 感谢 Leandris 模仿它,我只需要按照建议删除空白行。