It is not completely clear to me which algorithm typesetting package are you using, since you did not include the document preamble, and your code is a strange jumble of several different syntaxes, mostly looking like the old algorithms
package syntax, but not quite. Your tags seem to indicate that you are using the algorithmicx
bundle, so I assume that you use the algpseudocode
package. You need to correct some syntax, for example algpseudocode
does noy capitalize command, only first letter, so you should have \If ... \Else ... \EndIf
etc.
Also, command \For
and \If
take an argument, so you need
\If{something something}
The \If
does not use \Then
, you should leave that out.
Every line must have a command, so you should either define your own commands for things like "Given:", or just use \State
.
The following will hopefully do what you expect it to do:
\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{Blah blah}
\begin{algorithmic}[1]
\State Given: User-Noun Matrix $X$
\For{$i = 1 \to n$}
\State Let $S_i$ = {$s{i,j}$ | $0\le j \le l_i$} be set of nodes which have links to $i$;
\If{$\left(l_i=0 \hbox{OR} l_i=1 \right)$}
\State $b_i=0$;
\Else
\State Compute the similarity score vectors $r_{s,1},r_{s,2},...,r_{s,l_i}$ for each $S_i=s_1,s_2,...s_{l_i}$; \\
\State Construct $l_i \times l_i$ matrix $R_i= \left[r_{s,1},r_{s,2},...,r_{s,l_i}\right]$;
\State Take the average of all non-diagonal elements in $R_i$ to obtain $\hat{r_s}$;
\State $b_i= 1/\hat{r_s}$;
\EndIf
\EndFor
\State \Return vector $b$ of bridging scores;
\end{algorithmic}
\end{algorithm}
\end{document}
The algorithmicx
bundle have pretty good documentation with a number of examples, I suggest you take a look at it.
The problem with your setup is that you're adding the \listofalgorithms
to mythesis.cls
. This means that \listofalgorithms
gets defined when you load your class
\documentclass[..]{mythesis}
Subsequently you load algorithm
which tries to create \listofalgorithms
via a \newcommand
, and this fails.
Instead, use
\def\textofLoAl#1{\gdef\@textofLoAl{#1}}
\textofLoAl{List of Algorithms}
\AtBeginDocument{%
\def\listofalgorithms{%
\chapter*{\@textofLoAl}
\@mkboth{}{}%
\thispagestyle{plain}
\addcontentsline{toc}{chapter}{\protect\@textofLoAl}%
{\let\footnotemark\relax % in case one is in the title
\@starttoc{loa}
}%
}}
which should delay your \def
inition until \begin{document}
.
Note that I've used \@starttoc{loa}
since the algorithm
package writes algorithm \caption
s to a .loa
file, not a .loal
file.
Ideally one shouldn't modify the .cls
directly. Instead, write modifications in a separate style file, or as part of your preamble (possibly wrapping it with a \makeatletter
... \makeatother
pair).
Best Answer
The
IEEEtran
's documentation suggests:So, as suggested, do not use the
algorithm
floating environment; you can wrap your algorithm inside afigure
(orfigure*
) environment (if a caption is required and the captions are to beIEEEtran
compliant) and use the algorithmicx package ; something like this:If no caption is required, then simply don't use the
figure
environment.