Learn R Programming

GowerSom (version 0.1.0)

get_bmu_gower: Map observations to BMUs (Best Matching Units) using Gower distance

Description

Computes, for each observation, the index of the best-matching neuron (BMU) in a trained Gower-SOM codebook and the corresponding Gower distance. Also converts BMU indices into grid coordinates (row, col).

Usage

get_bmu_gower(data, codebook, n_rows, n_cols)

Value

A data.frame with the following columns:

bmu

Integer BMU index (1 .. n_rows * n_cols).

distance

Numeric, the Gower distance to the BMU.

row

Integer, BMU grid row coordinate.

col

Integer, BMU grid column coordinate.

Arguments

data

A data.frame of observations to map. Must be typed consistently with the training data (numeric, factor, etc.).

codebook

A data.frame (or coercible matrix) with one row per neuron and the same columns as data.

n_rows, n_cols

Integers, the SOM grid dimensions.

Author

Patricio Sáez <patricsaez@udec.cl>; Patricio Salas <patricioasalas@udec.cl>

References

Sáez, P., Salas, P. Gower-SOM: a self-organizing map for mixed data with gower distance and heuristic adaptation for data analytics. Int J Data Sci Anal 22, 26 (2026). https://doi.org/10.1007/s41060-025-00941-6/."

See Also

gsom_predict

Examples

Run this code
set.seed(1)
df <- data.frame(
  x1 = rnorm(10),
  x2 = rnorm(10),
  g  = factor(sample(letters[1:3], 10, TRUE))
)
fit <- gsom_Training(df, grid_rows = 3, grid_cols = 3,
                num_iterations = 5, batch_size = 5)
res <- get_bmu_gower(df, codebook = fit$weights,
                     n_rows = 3, n_cols = 3)
head(res)

Run the code above in your browser using DataLab