c1fd4f910e5c63fae03499eec47e70244694cd0a
[morpheus.git] / pkg / tests / testthat / test-computeMu.R
1 test_that("on input of sufficient size, β/||β|| is estimated accurately enough",
2 {
3 n <- 100000
4 d <- 2
5 K <- 2
6 p <- 1/2
7
8 βs_ref <- array( c(1,0,0,1 , 1,-2,3,1), dim=c(d,K,2) )
9 for (i in 1:(dim(βs_ref)[3]))
10 {
11 μ_ref <- normalize(βs_ref[,,i])
12 for (link in c("logit","probit"))
13 {
14 cat("\n\n",link," :\n",sep="")
15
16 io <- generateSampleIO(n, p, βs_ref[,,i], rep(0,K), link)
17 μ <- computeMu(io$X, io$Y, list(K=K))
18 μ_aligned <- alignMatrices(list(μ), ref=μ_ref, ls_mode="exact")[[1]]
19
20 #Some traces: 0 is not well estimated, but others are OK
21 cat("Reference normalized matrix:\n")
22 print(μ_ref)
23 cat("Estimated normalized matrix:\n")
24 print(μ_aligned)
25 cat("Difference norm (Matrix norm ||.||_1, max. abs. sum on a column)\n")
26 diff_norm <- norm(μ_ref - μ_aligned)
27 cat(diff_norm,"\n")
28
29 # NOTE: 0.5 is loose threshold, but values around 0.3 are expected...
30 expect_lt( diff_norm, 0.5 )
31 }
32 }
33 })