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