Learn R Programming

GowerSom (version 0.1.0)

gsom_Training: Train a Gower-SOM on mixed-attribute data

Description

Train a Self-Organizing Map (SOM) on datasets with mixed attributes (numeric and categorical) using Gower distance to find the BMU and heuristics to update categorical prototypes.

Usage

gsom_Training(data, grid_rows = 5, grid_cols = 5,
         learning_rate = 0.1, num_iterations = 100,
         radius = NULL, batch_size = 10,
         sampling = TRUE, set_seed = 123)

Value

An object of class gowersom with:

  • weights: data.frame of trained neuron prototypes.

  • coords: data.frame of grid coordinates per neuron.

Arguments

data

data.frame with correctly typed columns (numeric, factor, etc.).

grid_rows, grid_cols

SOM grid dimensions (rows x cols).

learning_rate

Initial learning rate (decays exponentially).

num_iterations

Number of iterations.

radius

Initial neighborhood radius; default max(grid_rows, grid_cols)/2.

batch_size

Mini-batch size per iteration.

sampling

Logical; if TRUE, multinomial sampling for categorical updates, else weighted mode.

set_seed

Integer random seed for reproducibility.

Author

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

Details

Learning rate and neighborhood radius decay exponentially per iteration: $$\alpha_t = \alpha_0 \exp(-t/T), \quad r_t = r_0 \exp(-t/(T/\log r_0))$$ where \(T\) is num_iterations and \(r_0\) is radius (default max(grid_rows, grid_cols)/2). For categorical variables, the prototype combines current and input values weighted by \(\alpha_t\) and the neighborhood kernel; if sampling = TRUE, a weighted draw is used; otherwise a weighted mode is applied.

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/."

Examples

Run this code
set.seed(1)
df <- data.frame(
  x1 = rnorm(50),
  x2 = rnorm(50),
  g  = factor(sample(letters[1:3], 50, TRUE))
)
fit <- gsom_Training(df, grid_rows = 3, grid_cols = 3,
                learning_rate = 0.1, num_iterations = 10,
                batch_size = 8, sampling = TRUE, set_seed = 123)
str(fit)

Run the code above in your browser using DataLab