
k-means++ seeding (Geron Ch 9, morie.fn grkmpp)
Source:R/geron_train_native.R
morie_geron_kmeans_pp_seeding.RdCentre t+1 sampled with P(x) proportional to min_c ||x - c||^2 using the searchsorted-on-cumsum draw, one LCG uniform per centre. Indices are 0-based.
Examples
set.seed(3)
X <- rbind(matrix(rnorm(20, 0), 10, 2), matrix(rnorm(20, 4), 10, 2))
morie_geron_kmeans_pp_seeding(X, k = 2, seed = 1)
#> $centroids
#> [,1] [,2]
#> [1,] 0.1957828 0.1520457
#> [2,] 2.3335252 4.7365021
#>
#> $indices
#> [1] 4 13
#>
#> $min_pairwise_distance
#> [1] 5.058378
#>
#> $sampling_probabilities
#> $sampling_probabilities[[1]]
#> [1] 0.0064943187 0.0057088201 0.0022956728 0.0055325277 0.0000000000
#> [6] 0.0007230425 0.0037348275 0.0045071424 0.0095417867 0.0034841921
#> [11] 0.0997927350 0.0916880910 0.1026571588 0.0774833758 0.0703804877
#> [16] 0.0912004378 0.1549071545 0.1159780199 0.0670994808 0.0867907281
#>
#>
#> $seed
#> [1] 1
#>
#> $estimate
#> [,1] [,2]
#> [1,] 0.1957828 0.1520457
#> [2,] 2.3335252 4.7365021
#>
#> $n
#> [1] 20
#>