0%

LaTeX Commands for Algorithms

LaTeX codes for inserting algorithms.

package algorithm2e

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
\usepackage[ruled,linesnumbered]{algorithm2e}

\IncMargin{1.5em}
\begin{algorithm}[h]
\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\Input{$\bm{\mathcal{D}} = \{(\mathbf{x}_{n}, \mathbf{y}_{n})\}_{n=1}^{N}$ - the set of observations of two r.v.s;\\ $\lambda$ - parameter of independence}
\Output{The causal direction}
\BlankLine

Standardize observations of each r.v.\;
Initialize $\beta$ and kernel parameters\;
Optimize the objective in both directions, denote the the value of HSIC term by $\text{HSIC}_{X\to Y}$ and $\text{HSIC}_{Y\to X}$, respectively\;
\uIf{$\text{HSIC}_{X\to Y}$ < $\text{HSIC}_{Y\to X}$}{The casual direction is $X\to Y$\;}
\uElseIf{$\text{HSIC}_{X\to Y}$ > $\text{HSIC}_{Y\to X}$}{The casual direction is $Y\to X$\;}
\Else{No decision made.}

\caption{Causal Inference}\label{alg_cd}
\end{algorithm}
\DecMargin{1.5em}
matrix1

package algorithm and algorithmic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
\usepackage{algorithm}
\usepackage{algorithmic}

\begin{algorithm}[ht]
\caption{exmp alg}
\label{alg:exmp}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{algorithmic}[1]
\REQUIRE input of exmp alg
\ENSURE output of exmp alg
\STATE statement of exmp;
\STATE statement of exmp.
\IF{condition 1 here}
\STATE statement of condition 1;
\ELSIF{condition 2 here}
\STATE statement of condition 2;
\ELSE
\STATE statement of other cases.
\ENDIF
\end{algorithmic}
\end{algorithm}
algorithm 2