我是 tex 新手。我正在用 tex 编写算法,我需要一些帮助来排除错误。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{algpseudocode}
\usepackage[linesnumbered]{algorithm2e}
\title{Apriori Algorithm}
\author{Mohan}
\begin{document}
\maketitle
\section{Algorithm}
\IncMargin{1em}
\begin{algorithm}[H]
\Indp
$k$ = 1\;
$F_{k}\ =\ \{\ i\ |\ i\ \in\ I \land \sigma\{i\}\ \geq\ N\ \ast \ minsup \}$\;
\Repeat{
$k$ = $k$ + 1\;
$C_k\ =\ apriori-gen(F_{k-1}).$\ \ \ \{Generate Candidate itemsets\}\;
\For{$each\ transaction\ t\ \in\ T \ \do$}{
$C_{t}\ =\ subset(C_{k},t).$\ \ \{Identify all candidates that belong to t\}\;
\For{$each\ candidate\ itemset\ c \in C_{t} \do$}{
$\sigma(c)=\sigma(c)\ +\ 1$\ \ \ \{Increment support count\}\;
}
}
$F_{k}=\{ c|c\in C_{k}\land\sigma(c) \geq N\ \ast\ minsup\}$\{Extract the frequent k-itemsets\}\;
}
\Until{$F_{k}=\emptyset$}
Result = $F_{k}$\;
\caption{Frequent itemset generation of the Apriori algorithm}
\end{algorithm}
\DecMargin{1em}
\end{document}
谢谢
答案1
\Repeat
定义的命令没有algorithm2e
附带补充\Until
命令,它内置了中止条件:语法是
\Repeat{<untilcond>}{<loop body>}
在你的例子中
\Repeat{$F_{k}=\emptyset$}{
$k = k + 1$\;
}