LaTeX:算法模板

LaTeX:算法模板

作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/

参考一documentclass{article} usepackage{algorithm}usepackage{algorithmic} enewcommand{algorithmicrequire}{ extbf{Input:}} %Use Input in the format of Algorithm enewcommand{algorithmicensure}{ extbf{Output:}} %UseOutput in the format of Algorithm% 参考:https://blog.csdn.net/jzwong/article/details/52399112egin{document}% 例1egin{algorithm}[htb] caption{ Framework of ensemble learning for our system.} label{alg:Framwork} egin{algorithmic}[1] %这个1 表示每一行都显示数字REQUIRE ~~\ %算法的输入参数:InputThe set of positive samples for current batch, $P_n$;\The set of unlabelled samples for current batch, $U_n$;\Ensemble of classifiers on former batches, $E_{n-1}$;ENSURE ~~\ %算法的输出:OutputEnsemble of classifiers on the current batch, $E_n$;STATE Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$; STATE Training ensemble of classifiers $E$ on $T_n cup P_n$, with help of data in former batches; STATE $E_n=E_{n-1}cup E$; STATE Classifying samples in $U_n-T_n$ by $E_n$; STATE Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$; RETURN $E_n$; %算法的返回值end{algorithmic}end{algorithm}% 例2egin{algorithm}caption{An example}label{alg:2}egin{algorithmic}STATE {set $r(t)=x(t)$} REPEAT STATE set $h(t)=r(t)$ REPEATSTATE set $h(t)=r(t)$ UNTIL{B} UNTIL{B}end{algorithmic}end{algorithm}% 例3egin{algorithm}caption{Calculate $y = x^n$} label{alg:3}egin{algorithmic}REQUIRE $n geq 0 vee x eq 0$ ENSURE $y = x^n$ STATE $y Leftarrow 1$ IF{$n < 0$} STATE $X Leftarrow 1 / x$ STATE $N Leftarrow -n$ ELSE STATE $X Leftarrow x$ STATE $N Leftarrow n$ENDIF WHILE{$N eq 0$} IF{$N$ is even} STATE $X Leftarrow X imes X$ STATE $N Leftarrow N / 2$ ELSE[$N$ is odd] STATE $y Leftarrow y imes X$ STATE $N Leftarrow N - 1$ ENDIF ENDWHILEend{algorithmic}end{algorithm}% 例4egin{algorithm}[h]caption{An example for format For & While Loop in Algorithm}label{alg:4}egin{algorithmic}[1]FOR{each $i in [1,9]$}STATE initialize a tree $T_{i}$ with only a leaf (the root);\STATE $T=T cup T_{i};$\ENDFORFORALL {$c$ such that $c in RecentMBatch(E_{n-1})$} STATE $T=T cup PosSample(c)$; ENDFORFOR{$i=1$; $i

比丘资源网 » LaTeX:算法模板

发表回复

提供最优质的资源集合

立即查看 了解详情