\HeaderA{batchSOM}{Self-Organizing Maps: Batch Algorithm}{batchSOM}
\keyword{classif}{batchSOM}
\begin{Description}\relax
Kohonen's Self-Organizing Maps are a crude form of multidimensional scaling.
\end{Description}
\begin{Usage}
\begin{verbatim}
batchSOM(data, grid = somgrid(), 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{\LinkA{somgrid}{somgrid}}.

\item[\code{radii}] the radii of the neighbourhood to be used for each pass: one pass is
run for each element of \code{radii}.

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

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The batch SOM algorithm of Kohonen(1995, section 3.14) is used.
\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.

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{\LinkA{somgrid}{somgrid}}, \code{\LinkA{SOM}{SOM}}
\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 <- batchSOM(lcrabs, gr, c(4, 4, 2, 2, 1, 1, 1, 0, 0))
plot(crabs.som)

bins <- as.numeric(knn1(crabs.som$code, lcrabs, 0:47))
plot(crabs.som$grid, type = "n")
symbols(crabs.som$grid$pts[, 1], crabs.som$grid$pts[, 2],
        circles = rep(0.4, 48), inches = FALSE, add = TRUE)
text(crabs.som$grid$pts[bins, ] + rnorm(400, 0, 0.1),
     as.character(crabs.grp))
\end{ExampleCode}
\end{Examples}

