Commit | Line | Data |
---|---|---|
15d1825d BA |
1 | #test matrix [de]standardization |
2 | test.de_standardize = function() | |
3 | { | |
4 | n = 100 | |
5 | m = 10 | |
6 | M = matrix(rnorm(n*m,mean=2.0,sd=2.0),nrow=n,ncol=m) | |
7 | ||
8 | std = synclust:::standardize(M) | |
9 | #result is centered: | |
10 | checkEquals(rep(0.0, m), colMeans(std$M)) | |
11 | #result is standardized: | |
12 | checkEquals(rep(1.0, m), sqrt( unlist( apply(std$M, 2, var) ) )) | |
13 | ||
14 | #rebuilt M == M: | |
15 | M_rec = synclust:::destandardize(std) | |
16 | checkEquals(M, M_rec) | |
17 | } | |
18 | ||
19 | #test neighborhoods remapping into one smaller component | |
20 | test.remap_neighbors = function() | |
21 | { | |
22 | #connex comp : 1-2-5-8-10 | |
23 | #to remap into 1-2-3-4-5 | |
24 | NI = list( | |
25 | "ix" = list( | |
26 | c(2,8,10), #V(1) | |
27 | c(1,5,8,10), #V(2) | |
28 | c(4,7,11), #V(3) | |
29 | c(3,6,9,12), #V(4) | |
30 | c(2,10), #V(5) | |
31 | c(4,7), #V(6) | |
32 | c(3,6,9,12), #V(7) | |
33 | c(1,2,10), #V(8) | |
34 | c(4,7,11), #V(9) | |
35 | c(1,2,5,8), #V(10) | |
36 | c(3,9), #V(11) | |
37 | c(4,7)), #V(12) | |
38 | "ds" = list( | |
39 | c(1.0,2.0,3.0), #1 | |
40 | c(1.0,2.0,3.0,4.0), #2 | |
41 | c(1.0,1.0,1.0), #3 | |
42 | c(1.0,1.0,1.0,1.0), #4 | |
43 | c(2.0,2.0), #5 | |
44 | c(1.0,1.0), #6 | |
45 | c(1.0,1.0,1.0,1.0), #7 | |
46 | c(2.0,3.0,1.0), #8 | |
47 | c(1.0,1.0,1.0), #9 | |
48 | c(3.0,4.0,2.0,1.0), #10 | |
49 | c(1.0,1.0), #11 | |
50 | c(1.0,1.0))) #12 | |
51 | ||
52 | indices = c(1,2,5,8,10) | |
53 | locNI = synclust:::remapNeighbors(NI, indices) | |
54 | checkEquals(2, length(locNI)) | |
55 | checkEquals(length(indices), length(locNI$ix)) | |
56 | checkEquals(length(indices), length(locNI$ds)) | |
57 | ||
58 | #formerly index 1 (now 1) | |
59 | checkEquals(c(2,4,5), locNI$ix[[1]]) | |
60 | checkEquals(NI$ds[[1]], locNI$ds[[1]],) | |
61 | #formerly index 2 (now 2) | |
62 | checkEquals(c(1,3,4,5), locNI$ix[[2]]) | |
63 | checkEquals(NI$ds[[2]], locNI$ds[[2]]) | |
64 | #formerly index 5 (now 3) | |
65 | checkEquals(c(2,5), locNI$ix[[3]]) | |
66 | checkEquals(NI$ds[[5]], locNI$ds[[3]]) | |
67 | #formerly index 8 (now 4) | |
68 | checkEquals(c(1,2,5), locNI$ix[[4]]) | |
69 | checkEquals(NI$ds[[8]], locNI$ds[[4]]) | |
70 | #formerly index 10 (now 5) | |
71 | checkEquals(c(1,2,3,4), locNI$ix[[5]]) | |
72 | checkEquals(NI$ds[[10]], locNI$ds[[5]]) | |
73 | } |