-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclusterGraph.R
61 lines (39 loc) · 1.19 KB
/
clusterGraph.R
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
###################################################
### chunk number 1: clustering
###################################################
library("graph")
library("cluster")
data(ruspini)
pm <- pam(ruspini, 4)
cG <- new("clusterGraph",
clusters = split(names(pm$clustering), pm$clustering))
nodes(cG)
###################################################
### chunk number 2: kmeans
###################################################
library(stats)
km = kmeans(ruspini, 4)
cG.km = new("clusterGraph",
clusters=split(as.character(1:75), km$cluster))
inBoth = intersection(cG.km, cG)
###################################################
### chunk number 3:
###################################################
d1 = dist(ruspini)
dG = new("distGraph", Dist=d1)
rl = NULL
j=1
for(i in c(40, 30, 10, 5) ){
nG = threshold(dG, i)
rl[[j]] = connComp(nG)
j=j+1
}
###################################################
### chunk number 4: howmany
###################################################
sapply(rl, length)
###################################################
### chunk number 5: somecomps
###################################################
dr = range(d1)
rl.lens = sapply(rl[[4]], length)