Description Usage Arguments Value Author(s) Examples
k-Medoids algorithm depends solely on the availability of concept that gives dissimilarity. We adopt pam
algorithm
from cluster package. See pam
for more details.
1 2 3 4 5 6 | gr.kmedoids(
input,
k = 2,
type = c("Intrinsic", "Extrinsic", "Asimov", "Binet-Cauchy", "Chordal",
"Fubini-Study", "Martin", "Procrustes", "Projection", "Spectral")
)
|
input |
either an array of size (n\times k\times N) or a list of length N whose elements are (n\times k) orthonormal basis (ONB) on Grassmann manifold. |
k |
the number of clusters |
type |
type of distance measure. measure. Name of each type is Case Insensitive and hyphen can be omitted. |
an object of class pam
. See pam
for details.
Kisung You
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ## generate a dataset with two types of Grassmann elements
# group1 : first four columns of (8x8) identity matrix + noise
# group2 : last four columns of (8x8) identity matrix + noise
mydata = list()
sdval = 0.25
diag8 = diag(8)
for (i in 1:10){
mydata[[i]] = qr.Q(qr(diag8[,1:4] + matrix(rnorm(8*4,sd=sdval),ncol=4)))
}
for (i in 11:20){
mydata[[i]] = qr.Q(qr(diag8[,5:8] + matrix(rnorm(8*4,sd=sdval),ncol=4)))
}
## do k-medoids clustering with 'intrinsic' distance
# First, apply MDS for visualization
dmat = gr.pdist(mydata, type="intrinsic")
embd = stats::cmdscale(dmat, k=2)
# Run 'gr.kmedoids' with different numbers of clusters
grint2 = gr.kmedoids(mydata, type="intrinsic", k=2)$clustering
grint3 = gr.kmedoids(mydata, type="intrinsic", k=3)$clustering
grint4 = gr.kmedoids(mydata, type="intrinsic", k=4)$clustering
# Let's visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3), pty="s")
plot(embd, pch=19, col=grint2, main="k=2")
plot(embd, pch=19, col=grint3, main="k=3")
plot(embd, pch=19, col=grint4, main="k=4")
par(opar)
## perform k-medoids clustering with different distance measures
# iterate over all distance measures
alltypes = c("intrinsic","extrinsic","asimov","binet-cauchy",
"chordal","fubini-study","martin","procrustes","projection","spectral")
ntypes = length(alltypes)
labels = list()
for (i in 1:ntypes){
labels[[i]] = gr.kmedoids(mydata, k=2, type=alltypes[i])$clustering
}
## visualize
# 1. find MDS scaling for each distance measure as well
embeds = list()
for (i in 1:ntypes){
pdmat = gr.pdist(mydata, type=alltypes[i])
embeds[[i]] = stats::cmdscale(pdmat, k=2)
}
# 2. plot the clustering results
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,5), pty="s")
for (i in 1:ntypes){
pm = paste0("k-medoids::",alltypes[i])
plot(embeds[[i]], col=labels[[i]], main=pm, pch=19)
}
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.