forked from JuliaStats/Clustering.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hclust-gen-examples.R
59 lines (56 loc) · 1.33 KB
/
hclust-gen-examples.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
59
# used to build the test examples for hclust in hclust_generated_examples.jl
# run as: Rscript hclust_gen_examples.R
catExample <- function(h, D, method) {
cat("Dict{Any,Any}(\n\"method\" => :")
cat(method)
cat(",\n")
cat("\"D\" => [")
for (i in 1:dim(D)[1]) {
for (j in 1:dim(D)[2]) {
cat(" ")
cat(D[i,j])
}
cat(";")
}
cat("],\n")
cat("\"merge\" => [")
for (i in 1:dim(h$merge)[1]) {
for (j in 1:dim(h$merge)[2]) {
cat(" ")
cat(h$merge[i,j])
}
cat(";")
}
cat("],\n")
cat("\"order\" => [")
for (i in 1:length(h$order)) {
cat(h$order[i])
cat(", ")
}
cat("],\n")
cat("\"height\" => [")
for (i in 1:length(h$height)) {
cat(h$height[i])
cat(", ")
}
cat("]\n),\n")
}
catMethodExamples <- function(method="single") {
for (i in 2:20) {
for (j in 1:3) { # three examples of each size
D = matrix(rnorm(i*i), i) * matrix(sample(c(1,0), i*i, replace=TRUE), i) + matrix(rnorm(i*i), i)*0.01
D = D + t(D)
catExample(hclust(as.dist(D), method), D, method)
catExample(hclust(as.dist(abs(D)), method), abs(D), method)
}
}
}
# save a Julia file full of test examples
set.seed(1)
sink("hclust-generated-examples.jl")
cat("examples = [")
catMethodExamples("complete")
catMethodExamples("average")
catMethodExamples("single")
cat("]\n")
sink()