【笔记】伪代码编写

编程知识 更新时间:2023-04-05 15:47:03

在线LaTeX编写工具overleaf极大的方便了暂时需要为论文编写伪代码的需要:
Overleaf, Online LaTeX Editor

该工具只需要简单注册就可以使用。

首先进入overleaf主页,然后完成注册和登录:

接着,需要创建用于储存LaTeX的文件夹:

接着,进入到文件夹,创建.tex文件开始编写伪代码:

然后,就可以在左侧代码框内编写LaTeX语言,在右侧框可以实时展示生成的伪代码。

本示例中的LaTex代码

\def\SetClass{article}
\documentclass{\SetClass}
\usepackage[lined,boxed,commentsnumbered,mfirstuc]{algorithm2e}
% \documentclass[1000pt]{article}
\begin{document}
\IncMargin{1em}
\begin{algorithm}
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}
    % 设置输入
    \Input{}
    % $$括起来表示这是一个数学表达式,会使用英文斜体表示. \\表示换行
    $X = n \times gene$, expression matrix for $n$ sample with $g$ genes \\
    % _表示下缀
    $X_i$ = expression matrix of sample_i \\
    % \delta是latex输入希腊字母δ的方式
    $\delta$: probability \\
    $f_{mlp}$: the model \\
    \BlankLine
    % 定义函数内容
    \SetKwFunction{MyFuns} {MyFuns}
    \SetKwProg{Fn}{Function}{:}{}
    \Fn{\MyFuns{$X$, $X_i$, $X_{func}$, $\delta$}} {
        setVariables($X$, $Score$) \\
        % 添加注释
        \tcp{\emph{This is an annotation}}\label{cmt} \\
        Train a network, $f_{\theta,0}$, using the samples from $D_L$  \\
        % for循环
        \For{$i$ in $1 : MaxIterations$}{
        Pseudo-label $D_U$ using $f_{\theta, i-1}$ \\
        $D_{selected} \leftarrow $ Select pseudo-labels using UPS \\
        $\tilde{D} \leftarrow D_L \bigcup D_{selected}$ \\
        Initiallize new network $f_{\theta, i}$ \\
        Train $f_{\theta, i}$ using the samples from $\tilde{D}$. \\
        $f_{\theta} \leftarrow f_{\theta, i}$ \\
        }
        \KwRet $f_{\theta}$
    }
    % 定义emphemph
    \BlankLine
    \BlankLine
\end{algorithm}
\DecMargin{1em}
\end{document}

 对应生成的伪代码:

 
 

更多推荐

【笔记】伪代码编写

本文发布于:2023-04-05 15:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/e740dcc6530106783d671033130a04a9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   笔记

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 46733文章数
  • 14阅读数
  • 0评论数