Skip to content

Instantly share code, notes, and snippets.

@violetguos
Created December 28, 2018 21:25
Show Gist options
  • Save violetguos/b8fe9f93a95c265678ff0a5e551af4bd to your computer and use it in GitHub Desktop.
Save violetguos/b8fe9f93a95c265678ff0a5e551af4bd to your computer and use it in GitHub Desktop.
good pseudo code template in latex
\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