add comments, fix some things. TODO: comment tests, finish computeWerDists, test it
[epclust.git] / epclust / tests / testthat / helper.clustering.R
1 # Shorthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3, ... (is base==3)
2 I = function(i, base)
3 (i-1) %% base + 1
4
5 # Compute the sum of (normalized) sum of squares of closest distances to a medoid.
6 # Note: medoids can be a big.matrix
7 computeDistortion = function(series, medoids)
8 {
9 if (bigmemory::is.big.matrix(medoids))
10 medoids = medoids[,] #extract standard matrix
11
12 n = nrow(series) ; L = ncol(series)
13 distortion = 0.
14 for (i in seq_len(n))
15 distortion = distortion + min( colSums( sweep(medoids,1,series[,i],'-')^2 ) / L )
16
17 distortion / n
18 }