Latex 算法 Algorithm 一些使用总结 (基本用法,步骤标号,某一句加颜色)。

基本用法

步骤1:导入需要的算法包。

\usepackage[ruled,vlined]{algorithm2e}

步骤2:具体算法。

\begin{algorithm}[t]
	\caption{Framework of Meta-GNN.}
	\label{alg:algorithm1}
	\KwIn{Distribution over mete-training tasks: $p(\mathcal{T})$; Meta-testing tasks: $\mathcal{T}_{mt}$; Task-learning rate: $\alpha_{1}$; Meta-learning rate: $\alpha_{2}$.}
	\KwOut{Labels of nodes in query set of $\mathcal{T}_{mt}$.}  
	\BlankLine
	Initialize $\bm{\theta}$ randomly;
	
	\While{\textnormal{not converged}}{
		Sample batch of meta-training tasks $\mathcal{T}_{i} \sim p(\mathcal{T})$;
		
		\ForEach{task in $\mathcal{T}_{i}$}{
			Evaluate $\mathcal{L}_{\mathcal{T}_{i}}\left(f_{\bm{\theta}}\right)$ using $\mathcal{S}_{i}$;
			
			Compute adapted parameters $\bm{{\theta}^{\prime}_{i}}$;
			
			Evaluate $\mathcal{L}_{\mathcal{T}_{i}}\left(f_{\bm{{\theta}_{i}^{\prime}}}\right)$ using $\mathcal{Q}_{i}$;
		}
		Update $\bm{\theta}$ by; 
	}
	
	Compute adapted parameters $\bm{{\theta}^{\prime}_{mt}}$ using support set of $\mathcal{T}_{mt}$; 
	
	Predict labels of nodes in query set of $\mathcal{T}_{mt}$ using model $f_{\bm{{\theta}_{mt}^{\prime}}}$.
	

\end{algorithm}

最后的效果图:
在这里插入图片描述

算法的标题

\caption{Framework of Meta-GNN.}

算法的标签,方便在文章中引用,例如

\label{alg:algorithm1}
Algorithm~\ref{alg:algorithm1}

算法的输入

\KwIn{Distribution over mete-training tasks: $p(\mathcal{T})$; Meta-testing tasks: $\mathcal{T}_{mt}$; Task-learning rate: $\alpha_{1}$; Meta-learning rate: $\alpha_{2}$.}

算法的输出。

\KwOut{Labels of nodes in query set of $\mathcal{T}_{mt}$.}  

备注:

(1).如果想要给算法的步骤加上序号:

这样引入包:

\usepackage[ruled,linesnumbered]{algorithm2e}

效果如下:
在这里插入图片描述

(2). 某些步骤加颜色:

首先引入包:

\usepackage{color}

然后修改其中一句

{\color{red}Evaluate $\mathcal{L}_{\mathcal{T}_{i}}\left(f_{\bm{{\theta}_{i}^{\prime}}}\right)$ using $\mathcal{Q}_{i}$;}

实际效果:
在这里插入图片描述

评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值