Commit | Line | Data |
---|---|---|
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 | } |