save state; test clustering not OK, all others OK
[epclust.git] / epclust / tests / testthat / test.computeMedoidsIndices.R
CommitLineData
6ad3f3fd
BA
1context("computeMedoidsIndices")
2
0486fbad 3test_that("computeMedoidsIndices behave as expected",
6ad3f3fd 4{
0486fbad
BA
5 # Generate a gaussian mixture
6 n = 999
7 L = 7
8 medoids = cbind( rep(0,L), rep(-5,L), rep(5,L) )
9 # short series...
10 series = t( rbind( MASS::mvrnorm(n/3, medoids[,1], diag(L)),
0fe757f7
BA
11 MASS::mvrnorm(n/3, medoids[,2], diag(L)),
12 MASS::mvrnorm(n/3, medoids[,3], diag(L)) ) )
6ad3f3fd 13
0486fbad 14 # With high probability, medoids indices should resemble 1,1,1,...,2,2,2,...,3,3,3,...
0fe757f7
BA
15 require("bigmemory", quietly=TRUE)
16 mi = epclust:::computeMedoidsIndices(bigmemory::as.big.matrix(medoids)@address, series)
0486fbad 17 mi_ref = rep(1:3, each=n/3)
0fe757f7 18 expect_lt( mean(mi != mi_ref), 0.01 )
6ad3f3fd 19
0486fbad
BA
20 # Now with a random matrix, compare with (trusted) R version
21 series = matrix(runif(n*L, min=-7, max=7), nrow=L)
0fe757f7 22 mi = epclust:::computeMedoidsIndices(bigmemory::as.big.matrix(medoids)@address, series)
0486fbad
BA
23 mi_ref = R_computeMedoidsIndices(medoids, series)
24 expect_equal(mi, mi_ref)
6ad3f3fd 25})