算法伪代码是论文的核心之一.
- 需要说明输入、输出;
- 方法 (函数) 名可写可不写, 如果被别的方法调用就必须写;
- 需要写出主要步骤的注释;
- 长度控制在 15-30 行;
- 可使用数学式子或对已有数学式子的引用;
- 不重要的步骤可以省略;
- 一般需要进行时间、空间复杂度分析, 并写出配套的 property 以及相应的表格, 以使其更标准.
- 在正文中分析伪代码的时候, 对多行引用应该用双连词符, 它会转成一个较长的连词符. 如: Lines 3–4 show. Tables 4–6 同理. 两个并行的词连接起来 (等价词的复合), 也应该用 Serial–parallel. 参考文献的页码也应该用双连词符 pp. 87–99. multi-label 这里有个从属关系, 就应该用单连词符.
例子:




以下是该算法的 tex 源码:
\begin{algorithm}[!htb]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\caption{Multi-label active learning through serial-parallel neural networks}
\label{algorithm: masp}
\begin{algorithmic}[1]
\REQUIRE
data matrix $\mathbf{X}$,
label matrix $\mathbf{Y}$ for query,
query budget $Q$,
cold-start query budget $P$,
number of representative instances $R$,
instance batch size $B_i$,
label batch size $B_l$
\ENSURE
queried instance-label pairs $\mathbf{Q}$, prediction network $\Theta$.
\STATE Initialize the serial-parallel prediction network;
\STATE $\mathbf{Q} = \emptyset$;\\
// Stage 1. Cold start.
\STATE Compute instance representativeness according to Eq. \eqref{equation: dp-representativeness};
\STATE Select the top-$R$ representative instances to reorganize the training set $\mathbf{X}$;
\STATE Update $\mathbf{Q}$ and $\mathbf{Y}'$ by querying $B_l$ labels for each of the top $\lfloor Q / B_l \rfloor$ representative instances;
\STATE Train the prediction network using $\mathbf{X}$ and $\mathbf{Y}'$;\\
// Stage 2. Main learning process.
\REPEAT
\STATE Compute $\hat{\mathbf{Y}}$ using the prediction network and Eq. \eqref{equation: label-prediction};
\STATE Compute label uncertainty according to Eq. \eqref{equation: label-uncertainty};
\STATE Query top-$B_i$ uncertain instance-label pairs to update $\mathbf{Q}$ and $\mathbf{Y}'$;
\STATE Update the prediction network using $\mathbf{X}$ and $\mathbf{Y}'$;\\
\UNTIL{($|\mathbf{Q}| \geq Q$)}
\end{algorithmic}
\end{algorithm}
再来一个:
\begin{algorithm}[tb!]\caption{Active learning through clustering selection (TACS)}\label{algorithm: TACS}
\textbf{Input}: A data matrix $\mathbf{X}$, cutoff distance ratio $rt$, the proportion of queried instances $qi$, the proportion of representative instances $qr$, small block threshold $ST$.\\
\textbf{Output}: Queried/predicted labels $\mathbf{L} = (l_1, \dots, l_n)$.\\
\begin{algorithmic}[1]
\STATE $\mathbf{B} = [1..n]$; // Initialized as the block containing all instances
\STATE $\mathbf{L} = (-1, \dots, -1)_n$; //Initialized as unknown
\STATE $N_q = \lfloor n \times qi \rfloor$; //Number of queries
\STATE $N_r = \lfloor N_q \times qr \rfloor$; //Number of representatives
// Step 1. Select representative instances to label
%\STATE Compute distance matrix $D = (d_{ij})_{n \times n}$;
\STATE Compute $\rho_i$ for $1 \leq i \leq n$ according to Eqs. \eqref{equation: density-gaussian} and \ref{equation: d-c};
\STATE Compute $\delta_i$ for $1 \leq i \leq n$ according to Eq. \eqref{equation: distance-to-master};
\STATE $\gamma \leftarrow (\gamma _1, \cdots, \gamma_N) \leftarrow \rho \cdot \delta$; //Hadamard product for representativeness
\STATE Query $N = N_r$ instances with the highest $\gamma_i$; // Current number of queries
//Step 2. Query informative instances and classify
\STATE $q$.enqueue($\mathbf{B}$); // The original queue with only one block
\WHILE {($q \neq \emptyset$ \&\& $N \leq N_q$)}
\STATE $\mathbf{B}$ = $q$.dequeue(); //Take a block from the head
\IF {($|\mathbf{B}| \leq ST$)}
\STATE continue; //Process small blocks later
\ENDIF
\STATE Query up to $\sqrt{|\mathbf{B}|}$ instances according to Eq. \eqref{equation: block-wise-representativeness} or \eqref{equation: distance-sum} and update $N$;
\IF {($\mathbf{B}$ is pure)}
\STATE For all $i \in \mathbf{B}$, $l_i$ = the label of queried instances in the block;
\STATE continue; //No need to split further
\ENDIF
\STATE Cluster $\mathbf{B}$ to $(\mathbf{B}_1, \mathbf{B}_2)$ using the current best algorithm;
\STATE $q$.enqueue($\mathbf{B}_1$);
\STATE $q$.enqueue($\mathbf{B}_2$);
\ENDWHILE
\IF {($N < N_q$)}
\STATE query $(N_q - N)$ unlabeled instances according to $\gamma_i$;
\ENDIF
\STATE Classify unlabeled instances using $k$NN;
\RETURN $\mathbf{L} \leftarrow [l_i]_{n \times 1}$;
\end{algorithmic}
\end{algorithm}
博客介绍了算法伪代码是论文核心之一,阐述其撰写规范,包括需说明输入输出、可按需写方法名、写主要步骤注释、控制长度、可引用数学式子、省略不重要步骤,还要进行复杂度分析等,同时说明了正文中伪代码引用及参考文献页码的连词符使用。

1万+

被折叠的 条评论
为什么被折叠?



