projects
/
epclust.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
code seems OK; still wavelets test to write
[epclust.git]
/
epclust
/
tests
/
testthat
/
helper.clustering.R
diff --git
a/epclust/tests/testthat/helper.clustering.R
b/epclust/tests/testthat/helper.clustering.R
index
21a791a
..
f39257e
100644
(file)
--- a/
epclust/tests/testthat/helper.clustering.R
+++ b/
epclust/tests/testthat/helper.clustering.R
@@
-1,15
+1,18
@@
-#
s
horthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3, ... (is base==3)
+#
S
horthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3, ... (is base==3)
I = function(i, base)
(i-1) %% base + 1
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)
{
computeDistortion = function(series, medoids)
{
- n = nrow(series) ; L = ncol(series)
- distortion = 0.
if (bigmemory::is.big.matrix(medoids))
if (bigmemory::is.big.matrix(medoids))
- medoids = medoids[,]
+ medoids = medoids[,] #extract standard matrix
+
+ 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 )
for (i in seq_len(n))
distortion = distortion + min( colSums( sweep(medoids,1,series[,i],'-')^2 ) / L )
- distortion / n
+
+ sqrt( distortion / n )
}
}