X-Git-Url: https://git.auder.net/?p=epclust.git;a=blobdiff_plain;f=epclust%2Ftests%2Ftestthat%2Ftest.clustering.R;h=49afe601ad6a6b6eac7aed4cc216914ea8c2b8a4;hp=9333876aa4fcb4e640ee942d74c8b7bc8b3b0a09;hb=492cd9e74a79cbcc0ecde55fa3071a44b7e463dc;hpb=dc646a9749509ce4c52079d456f6967e9ac833b5 diff --git a/epclust/tests/testthat/test.clustering.R b/epclust/tests/testthat/test.clustering.R index 9333876..49afe60 100644 --- a/epclust/tests/testthat/test.clustering.R +++ b/epclust/tests/testthat/test.clustering.R @@ -63,10 +63,11 @@ test_that("computeSynchrones behave as expected", for (i in seq_len(n)) series[i,] = s[[I(i,K)]] + rnorm(L,sd=0.01) getRefSeries = function(indices) { - indices = indices[indices < n] + indices = indices[indices <= n] if (length(indices)>0) series[indices,] else NULL } - synchrones = computeSynchrones(rbind(s1,s2,s3), getRefSeries, 100) + synchrones = computeSynchrones(rbind(s1,s2,s3), getRefSeries, n, 100, + verbose=TRUE, parll=FALSE) expect_equal(dim(synchrones), c(K,L)) for (i in 1:K) @@ -95,23 +96,23 @@ test_that("computeClusters2 behave as expected", for (i in seq_len(n)) series[i,] = s[[I(i,K1)]] + rnorm(L,sd=0.01) getRefSeries = function(indices) { - indices = indices[indices < n] + 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 = do.call(rbind, lapply( 1:K1, function(i) s[[I(i,K1)]] ) ) - medoids_K2 = computeClusters2(medoids_K1, K2, getRefSeries, 75) + medoids_K2 = computeClusters2(medoids_K1, K2, getRefSeries, n, 75, + verbose=TRUE, parll=FALSE) expect_equal(dim(medoids_K2), c(K2,L)) # Not easy to evaluate result: at least we expect it to be better than random selection of # medoids within 1...K1 (among references) - distorGood = computeDistortion(series, medoids_K2) for (i in 1:3) expect_lte( distorGood, computeDistortion(series,medoids_K1[sample(1:K1, K2),]) ) }) -test_that("clusteringTask + computeClusters2 behave as expected", +test_that("clusteringTask1 + computeClusters2 behave as expected", { n = 900 x = seq(0,9.5,0.1) @@ -129,8 +130,10 @@ test_that("clusteringTask + computeClusters2 behave as expected", wf = "haar" ctype = "absolute" getContribs = function(indices) curvesToContribs(series[indices,],wf,ctype) - medoids_K1 = getSeries( clusteringTask(1:n, getContribs, K1, 75, 4) ) - medoids_K2 = computeClusters2(medoids_K1, K2, getSeries, 120) + medoids_K1 = getSeries( clusteringTask1(1:n, getContribs, K1, 75, + verbose=TRUE, parll=FALSE) ) + medoids_K2 = computeClusters2(medoids_K1, K2, getSeries, n, 120, + verbose=TRUE, parll=FALSE) expect_equal(dim(medoids_K1), c(K1,L)) expect_equal(dim(medoids_K2), c(K2,L))