X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-alignMatrices.R;h=47625b18e26e4fef8b617a88dbfd7a20cf629a6d;hp=8ce7abf44b5bcb36e3c059ee518edb89116f3d8f;hb=2b3a6af5c55ac121405e3a8da721626ddf46b28b;hpb=2989133a738da99b78594cb00afdd3d87916b8bd diff --git a/pkg/tests/testthat/test-alignMatrices.R b/pkg/tests/testthat/test-alignMatrices.R index 8ce7abf..47625b1 100644 --- a/pkg/tests/testthat/test-alignMatrices.R +++ b/pkg/tests/testthat/test-alignMatrices.R @@ -4,7 +4,7 @@ context("alignMatrices") .generateMatrices = function(d, K, N, noise) { matrices = list( matrix(runif(d*K, min=-1, max=1),ncol=K) ) #reference - for (i in 2:N) + for (i in 2:(N+1)) { matrices[[i]] <- matrices[[1]][,sample(1:K)] if (noise) @@ -15,55 +15,50 @@ context("alignMatrices") test_that("labelSwitchingAlign correctly aligns de-noised parameters", { - N = 30 #number of matrices - d_K_list = list(c(2,2), c(5,3)) + N <- 30 #number of matrices + d_K_list <- list(c(2,2), c(5,3)) for (i in 1:2) { - d = d_K_list[[i]][1] - K = d_K_list[[i]][2] + d <- d_K_list[[i]][1] + K <- d_K_list[[i]][2] # 1] Generate matrix series - matrices_permut = .generateMatrices(d,K,N,noise=FALSE) + Ms <- .generateMatrices(d, K, N, noise=FALSE) # 2] Call align function with mode=approx1 - matrices_aligned = - alignMatrices(matrices_permut[2:N], ref=matrices_permut[[1]], ls_mode="approx1") + aligned <- alignMatrices(Ms[2:(N+1)], ref=Ms[[1]], ls_mode="approx1") # 3] Check alignment - for (j in 2:N) - expect_equal(matrices_aligned[[j-1]], matrices_permut[[1]]) + for (j in 1:N) + expect_equal(aligned[[j]], Ms[[1]]) # 2bis] Call align function with mode=approx2 - matrices_aligned = - alignMatrices(matrices_permut[2:N], ref=matrices_permut[[1]], ls_mode="approx2") + aligned <- alignMatrices(Ms[2:(N+1)], ref=Ms[[1]], ls_mode="approx2") # 3bis] Check alignment - for (j in 2:N) - expect_equal(matrices_aligned[[j-1]], matrices_permut[[1]]) + for (j in 1:N) + expect_equal(aligned[[j]], Ms[[1]]) } }) test_that("labelSwitchingAlign correctly aligns noisy parameters", { - N = 30 #number of matrices - d_K_list = list(c(2,2), c(5,3)) + N <- 30 #number of matrices + d_K_list <- list(c(2,2), c(5,3)) for (i in 1:2) { - d = d_K_list[[i]][1] - K = d_K_list[[i]][2] - max_error = d * 0.2 #TODO: what value to choose ? + d <- d_K_list[[i]][1] + K <- d_K_list[[i]][2] + max_error <- d * 0.2 #TODO: what value to choose ? # 1] Generate matrix series - matrices_permut = .generateMatrices(d,K,N,noise=TRUE) + Ms <- .generateMatrices(d, K, N, noise=TRUE) # 2] Call align function - matrices_aligned = alignMatrices(matrices_permut, ref="mean", ls_mode="exact") + aligned <- alignMatrices(Ms[2:(N+1)], ref=Ms[[1]], ls_mode="exact") # 3] Check alignment for (j in 2:N) - { - expect_that( norm(matrices_aligned[[j]] - matrices_permut[[1]]), - is_less_than(max_error) ) - } + expect_that( norm(aligned[[j]] - Ms[[1]]), is_less_than(max_error) ) } })