1

I'm not sure why I get two extra characters at the end of the for loop. Looking at other answers on StackExchange indicates I'm not suppose to use both algorithm and algorithmic and that its better to stick to one.

However, removing either does not produce the results I want.

Here is the code.

\usepackage{setspace}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{subcaption}
\usepackage{colortbl}
\usepackage{xparse}
\usepackage{caption}
\usepackage{fancyhdr}
\usepackage{algpseudocode}

\begin{center} \begin{minipage}{1\textwidth} \begin{algorithm}[H] \caption{Forward calculation for pair HMMs} \begin{algorithmic} \REQUIRE Set $f^{\mathrm{M}}(0,0)=1 f^{\mathrm{X}}(0,0)=f^{\mathrm{Y}}(0,0)= f^{}(i,-1) = f^{}(-1, j) = 0$ \FOR{$i=0, \ldots, n, j=0, \ldots, m \text { except }(0,0)$}

\begin{aligned} f^{\mathrm{M}}(i, j) & = p_{I_{i} O_{j}}\left[a_{MM} (f^{\mathrm{M}}(i-1, j-1))+\ & \quad \quad \left.a_{XM}\left(f^{\mathrm{X}}(i-1, j-1)\right)+a_{YM}(f^{\mathrm{Y}}(i-1, j-1)\right)\right] \ f^{\mathrm{X}}(i, j) & = q_{I_{i}}\left[a_{MX} f^{\mathrm{M}}(i-1, j)+a_{XX} f^{\mathrm{X}}(i-1, j)\right] \ f^{\mathrm{Y}}(i, j) & = q_{O_{j}}\left[a_{MY} f^{\mathrm{M}}(i, j-1)+a_{YY} f^{\mathrm{Y}}(i, j-1)\right]\ \end{aligned}

\ENDFOR \end{algorithmic} \end{algorithm} \end{minipage} \end{center}

Paul Gessler
  • 29,607
TriposG
  • 11

1 Answers1

1

You shouldn't load both algorithmic and algpseudocode. You're using the syntax pertaining to the former.

Here's a fixed version; please note the changes, in particular enclosing aligned in $...$ and adding \STATE.

I also removed all \left and \right, which did nothing except producing errors.

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}[H] \caption{Forward calculation for pair HMMs} \begin{algorithmic} \REQUIRE Set $f^{\mathrm{M}}(0,0)=1$, $f^{\mathrm{X}}(0,0)= f^{\mathrm{Y}}(0,0)= f^{}(i,-1) = f^{}(-1, j) = 0$ \FOR{$i=0, \dots, n$, $j=0, \dots, m$ except $(0,0)$} \STATE $\begin{aligned} f^{\mathrm{M}}(i, j) & = p_{I_{i} O_{j}}[a_{MM} (f^{\mathrm{M}}(i-1, j-1))+\ & \quad \quad a_{XM}f^{\mathrm{X}}(i-1, j-1))+a_{YM}(f^{\mathrm{Y}}(i-1, j-1))] \ f^{\mathrm{X}}(i, j) & = q_{I_{i}}[a_{MX} f^{\mathrm{M}}(i-1, j)+a_{XX} f^{\mathrm{X}}(i-1, j)] \ f^{\mathrm{Y}}(i, j) & = q_{O_{j}}[a_{MY} f^{\mathrm{M}}(i, j-1)+a_{YY} f^{\mathrm{Y}}(i, j-1)]\ \end{aligned}$ \ENDFOR \end{algorithmic} \end{algorithm}

\end{document}

enter image description here

egreg
  • 1,121,712