Last data update: 2014.03.03
R: Calculate distances between units in a SOM
unit.distances R Documentation
Calculate distances between units in a SOM
Description
Calculate distances between units in a SOM.
Usage
unit.distances(grid, toroidal)
Arguments
grid
an object of class somgrid
.
toroidal
if true, edges of the map are joined so that the
topology is that of a torus.
Value
Returns a (symmetrical) matrix containing distances. When
grid$n.hood
equals "circular", Euclidean distances are used; for
grid$n.hood
is "square" maximum distances. If toroidal
equals TRUE
, maps are joined at the edges and distances are
calculated for the shortest path.
Author(s)
Ron Wehrens
Examples
library(kohonen)
data(wines)
kohmap <- som(wines, grid = somgrid(5, 5, "hexagonal"), rlen=10)
dists <- unit.distances(kohmap$grid, toroidal=FALSE)
plot(kohmap, type="property", property=dists[1,],
main="Distances to unit 1", zlim=c(0,6),
palette = rainbow, ncolors = 7, contin = TRUE)
dists <- unit.distances(kohmap$grid, toroidal=TRUE)
plot(kohmap, type="property", property=dists[1,],
main="Distances to unit 1 (toroidal)", zlim=c(0,6),
palette = rainbow, ncolors = 7, contin = TRUE)
kohmap <- som(wines, grid = somgrid(5, 5), rlen=10)
dists <- unit.distances(kohmap$grid, toroidal=FALSE)
plot(kohmap, type="property", property=dists[1,],
main="Distances to unit 1", zlim=c(0,4),
palette = rainbow, ncolors = 5, contin = TRUE)
dists <- unit.distances(kohmap$grid, toroidal=TRUE)
plot(kohmap, type="property", property=dists[1,],
main="Distances to unit 1 (toroidal)", zlim=c(0,4),
palette = rainbow, ncolors = 5, contin = TRUE)
Results