latex_算法模板

LaTex有三个算法包,分别为algorithm, algorithmic, algorithm2e

在latex文件中顶端加入相应的package:

1
2
usepackage{algorithm}
usepackage{algorithmic}

第一种

在文件头添加:

1
usepackage[ruled, vlined, linesnumbered]{algorithm2e}

算法源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
begin{algorithm}[h]
begin{algorithmic}[1]
caption{An Optimization Algorithm of our framework}
REQUIRE the observed user-movie rating data $textbf{R}$, learning rate $gamma$, regularization $lambda_1$,$lambda_2$, component weight $alpha$, $P_{v_j}$ for $v_j in P$
ENSURE the full rating matrix of user-movie\
STATE Initialize VGG16 by using pretrained weights on ImageNet
STATE Initialize $U,V,W$ with Normal distribution $N(0, 0.01)$
REPEAT
{
STATE
Update $U$ as $U leftarrow U + frac{partial F}{partial U}$
STATE
Update $V$ as $V leftarrow V + frac{partial F}{partial V}$
STATE
Update $W$ as $W leftarrow W + frac{partial F}{partial W}$
STATE
fine-tune $CNN$ using back propagation
}
UNTIL{convergence;}
RETURN the top-k movie list of each user based on $textbf{U}^Ttextbf{V}$
end{algorithmic}
end{algorithm}

效果图:
first

第二种

算法源码同上,更改包名

1
usepackage[boxed, linesnumbered]{algorithm2e}

效果图:
second