Learn R Programming

GowerSom (version 0.1.0)

gsom_updateCategorical: Update categorical prototype in Gower-SOM (internal)

Description

Updates the categorical prototype of a neuron given candidate factor levels and associated weights.

Usage

gsom_updateCategorical(values, weights, sampling = FALSE)

Value

A factor of length 1 with the chosen level.

Arguments

values

A factor vector of candidate categories.

weights

A numeric vector of weights, same length as values.

sampling

Logical; if TRUE sample proportionally, else take weighted mode.

Author

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

Details

If sampling = FALSE, the function returns the weighted mode (i.e., the most probable level according to weights). If sampling = TRUE, it samples one level with probability proportional to the normalized weights, introducing stochasticity.

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
vals <- factor(c("A","A","B","C"))
wts  <- c(0.2, 0.5, 0.2, 0.1)

# Deterministic update (weighted mode)
gsom_updateCategorical(vals, wts, sampling = FALSE)

# Stochastic update (weighted sampling)
gsom_updateCategorical(vals, wts, sampling = TRUE)

Run the code above in your browser using DataLab