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