code seems OK; still wavelets test to write
[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
a52836b2 12 n = ncol(series) ; L = nrow(series)
0486fbad 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
a52836b2 17 sqrt( distortion / n )
0486fbad 18}