Adjustments + bugs fixing
[morpheus.git] / pkg / tests / testthat / test-computeMu.R
CommitLineData
cbd88fe5
BA
1test_that("on input of sufficient size, β/||β|| is estimated accurately enough",
2{
2b3a6af5
BA
3 n <- 100000
4 d <- 2
5 K <- 2
6 p <- 1/2
cbd88fe5 7
2b3a6af5 8 βs_ref <- array( c(1,0,0,1 , 1,-2,3,1), dim=c(d,K,2) )
6dd5c2ac
BA
9 for (i in 1:(dim(βs_ref)[3]))
10 {
2b3a6af5
BA
11 μ_ref <- normalize(βs_ref[,,i])
12 for (link in c("logit","probit"))
6dd5c2ac 13 {
2b3a6af5 14 cat("\n\n",link," :\n",sep="")
cbd88fe5 15
2b3a6af5
BA
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]]
cbd88fe5 19
6dd5c2ac
BA
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")
2b3a6af5 26 diff_norm <- norm(μ_ref - μ_aligned)
6dd5c2ac 27 cat(diff_norm,"\n")
cbd88fe5 28
ab35f610
BA
29 # NOTE: 0.5 is loose threshold, but values around 0.3 are expected...
30 expect_lt( diff_norm, 0.5 )
6dd5c2ac
BA
31 }
32 }
cbd88fe5 33})