Description Usage Arguments Value Examples
View source: R/summaries_kgroups.R
Given N functional summaries Λ_1 (t), Λ_2 (t), …, Λ_N (t), perform k-groups clustering by energy distance using L_2 metric.
1 |
fslist |
a length-N list of functional summaries of persistent diagrams. |
k |
the number of clusters. |
... |
extra parameters including
|
a length-N vector of class labels (from 1:k).
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 | # ---------------------------------------------------------------------------
# K-Groups Clustering via Energy Distance
#
# We will cluster dim=0 under top-5 landscape functions with
# - Class 1 : 'iris' dataset with noise
# - Class 2 : samples from 'gen2holes()'
# - Class 3 : samples from 'gen2circles()'
# ---------------------------------------------------------------------------
## Generate Data and Diagram from VR Filtration
ndata = 10
list_rips = list()
for (i in 1:ndata){
dat1 = as.matrix(iris[,1:4]) + matrix(rnorm(150*4), ncol=4)
dat2 = gen2holes(n=100, sd=1)$data
dat3 = gen2circles(n=100, sd=1)$data
list_rips[[i]] = diagRips(dat1, maxdim=1)
list_rips[[i+ndata]] = diagRips(dat2, maxdim=1)
list_rips[[i+(2*ndata)]] = diagRips(dat3, maxdim=1)
}
## Compute Persistence Landscapes from Each Diagram with k=5 Functions
list_land0 = list()
for (i in 1:(3*ndata)){
list_land0[[i]] = diag2landscape(list_rips[[i]], dimension=0, k=5)
}
## Run K-Groups Clustering with different K's
label2 = fskgroups(list_land0, k=2)
label3 = fskgroups(list_land0, k=3)
label4 = fskgroups(list_land0, k=4)
truelab = rep(c(1,2,3), each=ndata)
## Run MDS & Visualization
embed = fsmds(list_land0, ndim=2)
opar = par(no.readonly=TRUE)
par(mfrow=c(2,2), pty="s")
plot(embed, col=truelab, pch=19, main="true label")
plot(embed, col=label2, pch=19, main="k=2 label")
plot(embed, col=label3, pch=19, main="k=3 label")
plot(embed, col=label4, pch=19, main="k=4 label")
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.