add some folders; more complete package structure
[valse.git] / pkg / tests / testthat / helper-clustering.R
diff --git a/pkg/tests/testthat/helper-clustering.R b/pkg/tests/testthat/helper-clustering.R
new file mode 100644 (file)
index 0000000..785b7f0
--- /dev/null
@@ -0,0 +1,11 @@
+# Compute the sum of (normalized) sum of squares of closest distances to a medoid.
+computeDistortion <- function(series, medoids)
+{
+       n <- ncol(series)
+       L <- nrow(series)
+       distortion <- 0.
+       for (i in seq_len(n))
+               distortion <- distortion + min( colSums( sweep(medoids,1,series[,i],'-')^2 ) / L )
+
+       sqrt( distortion / n )
+}