Created
December 28, 2018 21:25
-
-
Save violetguos/b8fe9f93a95c265678ff0a5e551af4bd to your computer and use it in GitHub Desktop.
good pseudo code template in latex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{algorithm} % algorithm | |
\usepackage[noend]{algpseudocode} % algorithm | |
\usepackage{bm} % bold in math | |
\usepackage{array} % thick column hline | |
\makeatletter | |
\def\BState{\State\hskip-\ALG@thistlm} | |
\makeatother | |
\floatname{algorithm}{Procedure} | |
\renewcommand{\algorithmicrequire}{\textbf{Input:}} | |
\renewcommand{\algorithmicensure}{\textbf{Output:}} | |
\newcolumntype{?}{!{\vrule width 3pt}} | |
\begin{document} | |
\begin{algorithm} | |
\caption{Routing algorithm.}\label{routingalg} | |
\begin{algorithmic}[1] | |
\Procedure{Routing}{$\bm{\hat{u}}_{j|i}$, $r$, $l$} | |
\State for all capsule $i$ in layer $l$ and capsule $j$ in layer $(l+1)$: $b_{ij} \gets 0$. | |
\For{$r$ iterations} | |
\State for all capsule $i$ in layer $l$: ${\bf c}_i \gets \texttt{softmax}({\bf b}_i)$ \Comment{\texttt{softmax} computes Eq.~\ref{softmax}} | |
\State for all capsule $j$ in layer $(l+1)$: ${\bf s}_j \gets \sum_i{c_{ij}{\bf \hat u}_{j|i}}$ | |
\State for all capsule $j$ in layer $(l+1)$: ${\bf v}_j \gets \texttt{squash}({\bf s}_j)$ \Comment{\texttt{squash} computes Eq.~\ref{squash}} | |
\State for all capsule $i$ in layer $l$ and capsule $j$ in layer $(l+1)$: $b_{ij} \gets b_{ij} + {\bf \hat{u}}_{j|i} . {\bf v}_j$ | |
\EndFor | |
\Return ${\bf v}_j$ | |
\EndProcedure | |
\end{algorithmic} | |
\end{algorithm} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment