somInit: Initialize SOM prototypes

Description Usage Arguments Details Value Examples

View source: R/train.R

Description

Prototypes are the artificial points in data space that are used to cluster observations: each observation is assigned to the cluster of its closest prototype. In self-organizing maps, each cell of the map has its own prototype, and training is performed by iteratively adjusting the prototypes. This function creates an initial guess for the prototypes of a SOM grid, to be used as the 'init' argument to the 'kohonen::som' function (see example).

Usage

1
somInit(traindat, nrows, ncols, method = c("pca.sample", "pca", "random"))

Arguments

traindat

Matrix of training data, that will also be used to train the SOM.

nrows

Number of rows on the map.

ncols

Number of columns on the map.

method

Method used, see Details. "pca" or "random"

Details

The default method "pca.sample" takes as prototypes the observations that are closest to the nodes of a 2d grid placed along the first two components of a PCA. The "pca" method uses the nodes instead of the observations. The "random" method samples random observations.

Value

A matrix of prototype coordinates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dat <- iris[, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")]
### Scale training data
dat <- scale(dat)
## Train SOM
### Initialization (PCA grid)
init <- somInit(dat, 4, 4)
the.som <- kohonen::som(dat, grid = kohonen::somgrid(4, 4, 'hexagonal'), 
                        rlen = 100, alpha = c(0.05, 0.01), 
                        radius = c(6.08,-6.08), init = init, 
                        dist.fcts = 'sumofsquares')

jansodoge/awesom_dev_version documentation built on Jan. 26, 2021, 8:53 a.m.