fixes: TODO, debug test.clustering.R and finish writing clustering.R
[epclust.git] / epclust / tests / testthat / helper.clustering.R
diff --git a/epclust/tests/testthat/helper.clustering.R b/epclust/tests/testthat/helper.clustering.R
new file mode 100644 (file)
index 0000000..21a791a
--- /dev/null
@@ -0,0 +1,15 @@
+#shorthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3, ... (is base==3)
+I = function(i, base)
+       (i-1) %% base + 1
+
+# NOTE: medoids can be a big.matrix
+computeDistortion = function(series, medoids)
+{
+       n = nrow(series) ; L = ncol(series)
+       distortion = 0.
+       if (bigmemory::is.big.matrix(medoids))
+               medoids = medoids[,]
+       for (i in seq_len(n))
+               distortion = distortion + min( colSums( sweep(medoids,1,series[,i],'-')^2 ) / L )
+       distortion / n
+}