With sync_mean to average synchrones: bad idea, will be removed
[epclust.git] / epclust / tests / testthat / test.clustering.R
index a5dc3bd..e22835a 100644 (file)
@@ -62,7 +62,7 @@ test_that("clusteringTask1 behave as expected",
        L = length(x) #96 1/4h
        K1 = 60
        s = lapply( seq_len(K1), function(i) x^(1+i/30)*cos(x+i) )
-       series = matrix(nrow=n, ncol=L)
+       series = matrix(nrow=L, ncol=n)
        for (i in seq_len(n))
                series[,i] = s[[I(i,K1)]] + rnorm(L,sd=0.01)
        getSeries = function(indices) {
@@ -72,7 +72,9 @@ test_that("clusteringTask1 behave as expected",
        wf = "haar"
        ctype = "absolute"
        getContribs = function(indices) curvesToContribs(series[,indices],wf,ctype)
-       indices1 = clusteringTask1(1:n, getContribs, K1, 75, verbose=TRUE, parll=FALSE)
+       require("cluster", quietly=TRUE)
+       algoClust1 = function(contribs,K) cluster::pam(t(contribs),K,diss=FALSE)$id.med
+       indices1 = clusteringTask1(1:n, getContribs, K1, algoClust1, 75, verbose=TRUE, parll=FALSE)
        medoids_K1 = getSeries(indices1)
 
        expect_equal(dim(medoids_K1), c(L,K1))
@@ -92,16 +94,18 @@ test_that("clusteringTask2 behave as expected",
        K2 = 3
        #for (i in 1:60) {plot(x^(1+i/30)*cos(x+i),type="l",col=i,ylim=c(-50,50)); par(new=TRUE)}
        s = lapply( seq_len(K1), function(i) x^(1+i/30)*cos(x+i) )
-       series = matrix(nrow=n, ncol=L)
+       series = matrix(nrow=L, ncol=n)
        for (i in seq_len(n))
-               series[i,] = s[[I(i,K1)]] + rnorm(L,sd=0.01)
+               series[,i] = s[[I(i,K1)]] + rnorm(L,sd=0.01)
        getRefSeries = function(indices) {
                indices = indices[indices <= n]
                if (length(indices)>0) series[,indices] else NULL
        }
        # Artificially simulate 60 medoids - perfect situation, all equal to one of the refs
        medoids_K1 = bigmemory::as.big.matrix( sapply( 1:K1, function(i) s[[I(i,K1)]] ) )
-       medoids_K2 = clusteringTask2(medoids_K1, K2, getRefSeries, n, 75, verbose=TRUE, parll=FALSE)
+       algoClust2 = function(dists,K) cluster::pam(dists,K,diss=TRUE)$id.med
+       medoids_K2 = clusteringTask2(medoids_K1, K2, algoClust2, getRefSeries,
+               n, 75, sync_mean=TRUE, verbose=TRUE, parll=FALSE)
 
        expect_equal(dim(medoids_K2), c(L,K2))
        # Not easy to evaluate result: at least we expect it to be better than random selection of