1 context("alignMatrices")
3 # Helper to generate a random series of matrices to align
4 .generateMatrices = function(d, K, N, noise)
6 matrices = list( matrix(runif(d*K, min=-1, max=1),ncol=K) ) #reference
9 matrices[[i]] <- matrices[[1]][,sample(1:K)]
11 matrices[[i]] = matrices[[i]] + matrix(rnorm(d*K, sd=0.05), ncol=K)
16 test_that("labelSwitchingAlign correctly aligns de-noised parameters",
18 N = 30 #number of matrices
19 d_K_list = list(c(2,2), c(5,3))
25 # 1] Generate matrix series
26 matrices_permut = .generateMatrices(d,K,N,noise=FALSE)
28 # 2] Call align function with mode=approx1
30 alignMatrices(matrices_permut[2:N], ref=matrices_permut[[1]], ls_mode="approx1")
34 expect_equal(matrices_aligned[[j-1]], matrices_permut[[1]])
36 # 2bis] Call align function with mode=approx2
38 alignMatrices(matrices_permut[2:N], ref=matrices_permut[[1]], ls_mode="approx2")
40 # 3bis] Check alignment
42 expect_equal(matrices_aligned[[j-1]], matrices_permut[[1]])
46 test_that("labelSwitchingAlign correctly aligns noisy parameters",
48 N = 30 #number of matrices
49 d_K_list = list(c(2,2), c(5,3))
54 max_error = d * 0.2 #TODO: what value to choose ?
56 # 1] Generate matrix series
57 matrices_permut = .generateMatrices(d,K,N,noise=TRUE)
59 # 2] Call align function
60 matrices_aligned = alignMatrices(matrices_permut, ref="mean", ls_mode="exact")
65 expect_that( norm(matrices_aligned[[j]] - matrices_permut[[1]]),
66 is_less_than(max_error) )