一般在论文的写作中,需要有算法流程图,现讲述两种伪代码算法流程图的实现:algorithm,algorithme2

第一个:algorithm

%导包
\usepackage{algorithm}
\usepackage{algorithmic}

完整代码:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}\begin{document}\begin{algorithm}\renewcommand{\algorithmicrequire}{\textbf{Input:}}\renewcommand{\algorithmicensure}{\textbf{Output:}}\caption{Bayesian Personalized Ranking Based Latent Feature Embedding Model}\label{alg:1}\begin{algorithmic}[1]\REQUIRE latent dimension $K$, $G$, target predicate $p$\ENSURE $U^{p}$, $V^{p}$, $b^{p}$\STATE Given target predicate $p$ and entire knowledge graph $G$, construct its bipartite subgraph, $G_{p}$ \STATE $m$ = number of subject entities in $G_{p}$\STATE $n$ = number of object entities in $G_{p}$ \STATE Generate a set of training samples $D_{p} = \{(s_p, o^{+}_{p}, o^{-}_{p})\}$ using uniform sampling technique\STATE Initialize $U^{p}$ as size $m \times K$ matrix with $0$ mean and standard deviation $0.1$\STATE Initialize $V^{p}$ as size $n \times K$ matrix with $0$ mean and stardard deviation $0.1$\STATE Initialize $b^{p}$ as size $n \times 1$ column vector with $0$ mean and stardard deviation $0.1$\FORALL{$(s_p, o^{+}_{p}, o^{-}_{p}) \in D_{p}$}\STATE Update $U_{s}^{p}$ based on Equation~\ref{eq:sgd1}\STATE Update $V_{o^{+}}^{p}$ based on Equation~\ref{eq:sgd2}\STATE Update $V_{o^{-}}^{p}$ based on Equation~\ref{eq:sgd3}\STATE Update $b_{o^{+}}^{p}$ based on Equation~\ref{eq:sgd4}\STATE Update $b_{o^{-}}^{p}$ based on Equation~\ref{eq:sgd5}\ENDFOR\STATE \textbf{return} $U^{p}$, $V^{p}$, $b^{p}$\end{algorithmic}
\end{algorithm}\end{document}

结果如下

第二个:algorith2me

%导包
\usepackage[ruled]{algorithm2e}

完整代码

\documentclass{article}
\usepackage[ruled]{algorithm2e}\begin{document}\begin{algorithm}[h]\caption{The process of location change of fish}  \label{alg:1}\KwIn{$\rho(x,y,0),\beta,v_{max},u_{min},u_{max}$}\KwOut{$\rho(x,y,50)$}  \For{t=1 to 50}{The random distractor $\epsilon_t$ can be get in the process of identification of variance \newlineThe dispersed $u(x, y, t)$ can be predicted based on the model ARIMA(1,1,0) and the $u(x, y, t 1)$ \newlineThe continuous $u(x, y, t)$ can be get based on the linear interposition of value of the dispersed $u(x, y, t)$\newlineThe continuous $\nabla u$ can be identified based on the equation (11) \newlineThe continuous $v(x, y, t)$ can be calculated based on the equation (12) \newlineThe location change of each fish can be calculated based on equation (7) \newlineThe $\rho_t(x, y)$ of each fish can be refreshed based on the equation (8) \newline}
\end{algorithm}  \end{document}

结果如下

关于 algorithm2e的补充

\usepackage[ruled,linesnumbered]{algorithm2e}
  • ruled 让标题显示在上方,否则将显示在下方
  • linesnumbered 在算法流程图内显示行号
  • 可添加 boxed,让算法排版时插入在一个盒子里

展示效果如下:

另外补充:

代码 含义
\; 在行末添加分号,并自动换行
\caption{} 插入标题
\KwIn{输入消息} 效果为:“input:输入消息”
KwOut{输出消息} 效果为:“Out:输出消息”
KwData{输入消息} 效果为:“Data:输入消息”
KwResult{输出消息} 效果为:“Result:输出消息”
\For{条件}{循环语句} for 条件 do 循环语句 end
\If{条件}{肯定语句} if 条件 then 肯定语句 end
While{条件}{循环语句} while 条件 then 循环语句 end
\tcc{注释} /*注释*/
\tcp{注释} //注释
\elf{条件}{肯定语句}{否定语句} if 条件 then 肯定语句 else 否定语句 end

如果有问题,欢迎给我留言

Latex——伪代码算法相关推荐

  1. 【LaTeX】算法伪代码 ——代码实例、字体大小设置、显示问题

    1. 算法伪代码 \documentclass[AMA,STIX1COL]{WileyNJD-v2} \usepackage{moreverb}\begin{algorithm}[p] \small ...

  2. Latex 编写算法伪代码,基于algorithmicx包的使用说明(人工翻译自CTAN)

    目录 摘要 其他布局的package 简介 算法块 简单的一行 注释 标签和引用 分解较长的算法 同一文档中使用多布局 结构化语法 for语句块 while循环 repeat语句 if语句块 proc ...

  3. 【Latex】算法排版规律(中文排版)

    参考资料: <algorithm, algorithmic算法包到底什么区别?> <Latex写算法的伪代码排版> <Latex 编写算法伪代码,基于algorithmi ...

  4. WPS插入LaTeX伪代码

    更新: 原文已经搬运至网站:https://www.link2sea.com/archives/305,后续也将在该网站进行更新. 查看博主更多文章请前往:https://www.link2sea.c ...

  5. latex 伪代码简单教程

    首先,在latex 导入需要用到的包 % OCT 26 新添加包 用於流程圖算法 \usepackage{algorithm} \usepackage{algorithmic} \usepackage ...

  6. latex中算法命令_比较Java 8中的命令式和功能性算法

    latex中算法命令 Mario Fusco受欢迎的推文令人印象深刻,显示了类似算法的命令性和功能性方法之间的主要区别实际上是: 势在必行–功能分离pic.twitter.com/G2cC6iBkDJ ...

  7. latex 论文算法编辑

    论文算法编辑 在使用latex书写算法流程时,建议使用包algorithm2e. 源码如下 \documentclass{ctexart}%\usepackage[noend]{algpseudoco ...

  8. Latex 伪代码、三线表与多线表

    Latex 伪代码.三线表与多线表 伪代码 先导入宏包 \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{amsmath} \ ...

  9. 取消latex伪代码的行号

    取消latex伪代码的行号: 将\begin{algorithmic}[1] 改成\begin{algorithmic}[0]

最新文章

  1. 【教程】Linux下MySQL 8.0安装配置
  2. click F5 refresh button on detail page - how to get the usable OData model
  3. 针对C++和Delphi的LiveBindings一瞥
  4. mysql getcolumnname_jdbc-mysql基础 ResultSetMetaData getColumnName getColumnLabel 得到列的名字和别名...
  5. .NET下使用socket.io随笔记录
  6. pkill mysql_每天一个linux命令:kill命令
  7. bootstrap-table 行合并和列合并,以及固定列宽度等问题
  8. 外设驱动库开发笔记24:FM24xxx系列FRAM存储器驱动
  9. 去掉chrome、safari input或textarea在得到焦点时出现黄色边框的方法
  10. bzoj1925: [Sdoi2010]地精部落 [dp]
  11. EasyBCD误删win10启动项后的修复方法
  12. 不知道怎么把英文文档翻译成中文?手把手教你怎么操作
  13. 下钻图生成 highcharts-column-drilldown
  14. 计算机应用技术Word文档题目,计算机应用技术复习题(word版)
  15. XTTS V4.3 跨平台迁移12.1.2 HPUX ->Oracle Linux
  16. 马云向约旦王后基金会捐助300万美元,帮助阿拉伯难民儿童获得教育机会
  17. 安恒西湖论剑周周练Reverse刮开有奖WP
  18. Android与PC通过USB连接通信(一)
  19. fastreport在delphi中的使用
  20. 手机用python画太阳花的代码_利用python绘制太阳花(蓝桥杯试题)

热门文章

  1. 正则式获取特定标识的字符串并替换
  2. Asp.net 表单打印时的样式设置【原】
  3. 《Effective Java》阅读笔记
  4. 怎样在spyder中暂停程序的运行
  5. 在Macbook M1上安装Parallels Desktop 17虚拟机和Originlab 2021
  6. SDN第四次上机作业
  7. 那些不能遗忘的知识点回顾——操作系统系列(笔试面试高频题)
  8. mysql 添加添加事务处理
  9. WinForm如何输出中文星期几?
  10. mobile兼容性调整,根据rem,字体大小,视窗宽度