785b7f02af289cf50d3bddc9ab3ea51e70c1b886
[epclust.git] / epclust / tests / testthat / helper-clustering.R
1 # Compute the sum of (normalized) sum of squares of closest distances to a medoid.
2 computeDistortion <- function(series, medoids)
3 {
4 n <- ncol(series)
5 L <- nrow(series)
6 distortion <- 0.
7 for (i in seq_len(n))
8 distortion <- distortion + min( colSums( sweep(medoids,1,series[,i],'-')^2 ) / L )
9
10 sqrt( distortion / n )
11 }