TODO: tests, reports
[talweg.git] / pkg / tests / testthat / test.computeFilaments.R
1 #TODO: toy dataset, check that indices returned are correct + colors
2
3 context("Check that getParamsDirs behaves as expected")
4
5 test_that("on input of sufficient size, beta is estimated accurately enough", {
6 n = 100000
7 d = 2
8 K = 2
9 Pr = c(0.5, 0.5)
10
11 betas_ref = array( c(1,0,0,1 , 1,-2,3,1), dim=c(2,2,2) )
12 for (i in 1:(dim(betas_ref)[3]))
13 {
14 beta_ref = betas_ref[,,i]
15 #all parameters are supposed to be of norm 1: thus, normalize beta_ref
16 norm2 = sqrt(colSums(beta_ref^2))
17 beta_ref = beta_ref / norm2[col(beta_ref)]
18
19 io = generateSampleIO(n, d, K, Pr, beta_ref)
20 beta = getParamsDirs(io$X, io$Y, K)
21 betas = .labelSwitchingAlign(
22 array( c(beta_ref,beta), dim=c(d,K,2) ), compare_to="first", ls_mode="exact")
23
24 #Some traces: 0 is not well estimated, but others are OK
25 cat("\n\nReference parameter matrix:\n")
26 print(beta_ref)
27 cat("Estimated parameter matrix:\n")
28 print(betas[,,2])
29 cat("Difference norm (Matrix norm ||.||_1, max. abs. sum on a column)\n")
30 diff_norm = norm(beta_ref - betas[,,2])
31 cat(diff_norm,"\n")
32
33 #NOTE: 0.5 is loose threshold, but values around 0.3 are expected...
34 expect_that( diff_norm, is_less_than(0.5) )
35 }
36 })