在写论文的时候经常要用到伪代码,有时候要对一些算法进行注释更加美观,例如:
对算法加了注释能够使审稿人更明白你的算法内容,那这样的注释应该怎么加?
其实就是一个\Comment{} 命令,在开始之前需要导入算法包,这儿就不提示了,我就直接放核心代码
\begin{algorithm}[htb]
\caption{ Sparse-attention for Each Window}
% \label{alg:Framwork}
\begin{algorithmic}[1]
\Require
Labeled samples ($X$, $Y$) and unlabeled sample $(\bar{X}, \bar{Y})$.
\State self-attention feature map S;
\State randomly select U dot-product pairs from K as $\bar{K}$; \textcolor{blue}{\Comment{this is a comment}}
\State set the sample score $\bar{S}=Q\bar{K}$;
\State compute the similarity $M = $Max($\bar{S})$ - Mean($\bar{S}$) by rows;
\State set top-$u$ queries under $M$ as $\bar{Q}$;
\State set $ S $ = \{ softmax($\bar{Q}K^{T}/\sqrt{d}$)$\cdot V$, Mean($V$) \} by rows;
\end{algorithmic}
\end{algorithm}
展示的结果图: