View source: R/clustering_kmeans18B.R
| riem.kmeans18B | R Documentation |
The modified version of lightweight coreset for scalable k-means computation is applied for manifold-valued data X_1,X_2,…,X_N \in \mathcal{M}. The smaller the set is, the faster the execution becomes with potentially larger quantization errors.
riem.kmeans18B(
riemobj,
k = 2,
M = length(riemobj$data)/2,
geometry = c("intrinsic", "extrinsic"),
...
)
riemobj |
a S3 |
k |
the number of clusters. |
M |
the size of coreset (default: N/2). |
geometry |
(case-insensitive) name of geometry; either geodesic ( |
... |
extra parameters including
|
a named list containing
a length-N vector of class labels (from 1:k).
a 3d array where each slice along 3rd dimension is a matrix representation of class mean.
within-cluster sum of squares (WCSS).
bachem_scalable_2018aRiemann
riem.coreset18B
#-------------------------------------------------------------------
# Example on Sphere : a dataset with three types
#
# class 1 : 10 perturbed data points near (1,0,0) on S^2 in R^3
# class 2 : 10 perturbed data points near (0,1,0) on S^2 in R^3
# class 3 : 10 perturbed data points near (0,0,1) on S^2 in R^3
#-------------------------------------------------------------------
## GENERATE DATA
mydata = list()
for (i in 1:10){
tgt = c(1, stats::rnorm(2, sd=0.1))
mydata[[i]] = tgt/sqrt(sum(tgt^2))
}
for (i in 11:20){
tgt = c(rnorm(1,sd=0.1),1,rnorm(1,sd=0.1))
mydata[[i]] = tgt/sqrt(sum(tgt^2))
}
for (i in 21:30){
tgt = c(stats::rnorm(2, sd=0.1), 1)
mydata[[i]] = tgt/sqrt(sum(tgt^2))
}
myriem = wrap.sphere(mydata)
mylabs = rep(c(1,2,3), each=10)
## TRY DIFFERENT SIZES OF CORESET WITH K=4 FIXED
core1 = riem.kmeans18B(myriem, k=3, M=5)
core2 = riem.kmeans18B(myriem, k=3, M=10)
core3 = riem.kmeans18B(myriem, k=3, M=15)
## MDS FOR VISUALIZATION
mds2d = riem.mds(myriem, ndim=2)$embed
## VISUALIZE
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2), pty="s")
plot(mds2d, pch=19, main="true label", col=mylabs)
plot(mds2d, pch=19, main="kmeans18B: M=5", col=core1$cluster)
plot(mds2d, pch=19, main="kmeans18B: M=10", col=core2$cluster)
plot(mds2d, pch=19, main="kmeans18B: M=15", col=core3$cluster)
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.