serhii.net

In the middle of the desert you can say anything you want

16 Jan 2024

Latex algorithms bits

Require/ensure

Require/Ensure is basically Input/Output and can be renamed thus1:

\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

Sample algpseudocode algorithm float

\usepackage{algorithm}
\usepackage{algpseudocode}

% ...

\begin{algorithm}
\caption{Drop Rare Species per Country}
\label{alg:drop}
\begin{algorithmic}
\Require $D_0$: initial set of occurrences
\Ensure $D_1$: Set of occurrences after filtering rare species
\State $D_1 \gets$ \emptyset
\For{each $c$ in Countries}
    \For{each $s$ in Species}
        \If {$|O_{c,s} \in D_0| \geq 10$} % if observations of species in country in D_0 have more than 10 entries; || is set cardinality
            \State{$D_1 \gets D_1 \cup O_{c,s}$} 
        \EndIf
    \EndFor
\EndFor
\end{algorithmic}
\end{algorithm}
Nel mezzo del deserto posso dire tutto quello che voglio.