unit.distances {kohonen} | R Documentation |
Calculate distances between units in a SOM.
unit.distances(grid, toroidal)
grid |
an object of class |
toroidal |
if true, edges of the map are joined so that the topology is that of a torus. |
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.
Ron Wehrens
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)