\Header{SOM}{Self-Organizing Maps: Online Algorithm}
\keyword{classif}{SOM}
\begin{Description}\relax
Kohonen's Self-Organizing Maps are a crude form of multidimensional scaling.
\end{Description}
\begin{Usage}
\begin{verbatim}
SOM(data, grid = somgrid(), rlen = 10000, alpha, radii, init)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{data}] a matrix or data frame of observations, scaled so that Euclidean
distance is appropriate.

\item[\code{grid}] A grid for the representatives: see \code{\Link{somgrid}}.

\item[\code{rlen}] the number of updates: used only in the defaults for \code{alpha} and \code{radii}.

\item[\code{alpha}] the amount of change: one update is done for each element of \code{alpha}.
Default is to decline linearly from 0.05 to 0 over \code{rlen} updates.

\item[\code{radii}] the radii of the neighbourhood to be used for each update: must be the
same length as \code{alpha}.  Default is to decline linearly from 4 to 1
over \code{rlen} updates.

\item[\code{init}] the initial representatives.  If missing, chosen (without replacement)
randomly from \code{data}.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{alpha} and \code{radii} can also be lists, in which case each component is
used in turn, allowing two- or more phase training.
\end{Details}
\begin{Value}
an object of class \code{"SOM"} with components

\begin{ldescription}
\item[\code{grid}] the grid, an object of class \code{"somgrid"}.

\item[\code{codes}] a matrix of representatives.

\end{ldescription}
\end{Value}
\begin{References}\relax
Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer-Verlag

Kohonen, T., Hynninen, J., Kangas, J. and Laaksonen, J. (1996)
\emph{SOM PAK: The self-organizing map program package.}
Laboratory of Computer and Information Science, Helsinki University
of Technology, Technical Report A31.

Ripley, B. D. (1996)
\emph{Pattern Recognition and Neural Networks.} Cambridge.

Venables, W. N. and Ripley, B. D. (2002)
\emph{Modern Applied Statistics with S.} Fourth edition.  Springer.\end{References}
\begin{SeeAlso}\relax
\code{\Link{somgrid}}, \code{\Link{batchSOM}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(crabs, package = "MASS")

lcrabs <- log(crabs[, 4:8])
crabs.grp <- factor(c("B", "b", "O", "o")[rep(1:4, rep(50,4))])
gr <- somgrid(topo = "hexagonal")
crabs.som <- SOM(lcrabs, gr)
plot(crabs.som)

## 2-phase training
crabs.som2 <- SOM(lcrabs, gr,
    alpha = list(seq(0.05, 0, len = 1e4), seq(0.02, 0, len = 1e5)),
    radii = list(seq(8, 1, len = 1e4), seq(4, 1, len = 1e5)))
plot(crabs.som2)
\end{ExampleCode}
\end{Examples}

