sp.kmeans: k-Means Clustering for Data on Hypersphere

Description Usage Arguments Value Examples

View source: R/sp.kmeans.R

Description

k-Means Clustering for Data on Hypersphere

Usage

1
2
3
4
5
6
7
sp.kmeans(
  x,
  k = 2,
  init = c("kmeans", "random"),
  maxiter = 100,
  type = c("intrinsic", "extrinsic")
)

Arguments

x

an (n\times p) row-stacked matrix for \mathbb{S}^{p-1}.

k

the number of clusters to be found.

init

method for setting initial configuration. "random" or "kmeans".

maxiter

maximum number of iterations to be run.

type

type of distance, either "intrinsic" or "extrinsic".

Value

a named list containing

cluster

length-n vector of class membership indices.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## generate two-cluster data
mymu1 = c(0,0,0,1)  # center of class 1
mymu2 = c(-1,0,0,0) # center of class 2

x1 = rvmf(50, mymu1, kappa=10)
x2 = rvmf(50, mymu2, kappa=10)
xx = rbind(x1,x2)

## apply clustering with different k values
cl2 <- sp.kmeans(xx, k=2)
cl3 <- sp.kmeans(xx, k=3)
cl4 <- sp.kmeans(xx, k=4)

## compute 2-dimensional embedding for visualization
mds2d <- sp.mds(xx, ndim=2)
mdsx  <- mds2d$embed[,1]
mdsy  <- mds2d$embed[,2]

## compare via visualization
opar  <- par(mfrow=c(1,3), pty="s")
plot(mdsx, mdsy, col=cl2$cluster, main="k=2 means", pch=19)
plot(mdsx, mdsy, col=cl3$cluster, main="k=3 means", pch=19)
plot(mdsx, mdsy, col=cl4$cluster, main="k=4 means", pch=19)
par(opar)

kyoustat/RiemSphere documentation built on April 13, 2020, 10:04 a.m.