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.
Here's an option that provides feasible output. I've removed the physical numbering in the caption:

\documentclass[10pt,twocolumn]{article}
\usepackage{algorithm,algpseudocode}% http://ctan.org/pkg/{algorithms,algorithmx}
\algnewcommand{\Inputs}[1]{%
\State \textbf{Inputs:}
\Statex \hspace*{\algorithmicindent}\parbox[t]{.8\linewidth}{\raggedright #1}
}
\algnewcommand{\Initialize}[1]{%
\State \textbf{Initialize:}
\Statex \hspace*{\algorithmicindent}\parbox[t]{.8\linewidth}{\raggedright #1}
}
\begin{document}
\begin{algorithm}
\caption{Boosted $K$ Nearest Neighbour}
\begin{algorithmic}[1]
\Inputs{$S={s_i}=\left(x_i,y_i\right)$}
\Initialize{\strut$w_i^0 \gets 0$, $i=1,\ldots,n$ \\ $S_0 \gets S$}
\For{t = 1 to T}
\State $S_t \gets S_{t-1}$
\For{$s_q \in S_t$}
\State $N_q \gets$ k nearest neighbors
\State of $s_q$ using $D(s_q,s_i)$
\State label($s_q$)$=argmax\sum_{s_i \in N_q}D(s_q,s_i)$;
\If{label($s_q$)$\ne y_q$}
\For{$s_i \in N_i$}
\If{$y_i \ne y_q$}
\State $w_{i}^{t} \gets w_{i}^{t} - \lambda/d(x_q,x_i)$;
\Else
\State $w_{i}^{t} \gets w_{i}^{t} + \lambda/d(x_q,x_i)$;
\EndIf
\EndFor
\EndIf
\EndFor
\If{label($s_q$)$=y_q \forall_{s_q}$}
\State break
\EndIf
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}
A newly-defined \Inputs
and (equivalent) \Initialize
takes one argument that sets its contents in a \Statex
with an indent of \algorithmicindent
- the default - to align with the other algorithm elements. The contents is stored in a t
op-aligned \parbox
that fits across 80% of the line. I'm sure you won't need more, but in case you do, that can also be fixed to not cause overfull boxes.
Best Answer
You have to use
\State
instead of\\
to indent your lines inside the\For
statement.MWE
Result: