X-Git-Url: https://git.auder.net/?p=epclust.git;a=blobdiff_plain;f=epclust%2Ftests%2Ftestthat%2Fhelper.clustering.R;h=273a0b7912af8c6f362af19d015fec38d5910060;hp=21a791a4b7a3a42fe71618d50f63c5025f277e38;hb=d9bb53c5e1392018bf67f92140edb10137f3423c;hpb=9f05a4a0b703deffd7bdb9cd99b0aaa2246a5c83 diff --git a/epclust/tests/testthat/helper.clustering.R b/epclust/tests/testthat/helper.clustering.R index 21a791a..273a0b7 100644 --- a/epclust/tests/testthat/helper.clustering.R +++ b/epclust/tests/testthat/helper.clustering.R @@ -1,15 +1,18 @@ -#shorthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3, ... (is base==3) +# 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 +# Compute the sum of (normalized) sum of squares of closest distances to a medoid. +# Note: medoids can be a big.matrix computeDistortion = function(series, medoids) { + if (bigmemory::is.big.matrix(medoids)) + medoids = medoids[,] #extract standard matrix + 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 }