First commit
[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{
5 n = 100000
6 d = 2
7 K = 2
8 p = 1/2
9
10 βs_ref = array( c(1,0,0,1 , 1,-2,3,1), dim=c(d,K,2) )
11 for (i in 1:(dim(βs_ref)[3]))
12 {
13 μ_ref = normalize(βs_ref[,,i])
14 for (model in c("logit","probit"))
15 {
16 cat("\n\n",model," :\n",sep="")
17
18 io = generateSampleIO(n, p, βs_ref[,,i], rep(0,K), model)
19 μ = computeMu(io$X, io$Y, list(K=K))
20 μ_aligned = alignMatrices(list(μ), ref=μ_ref, ls_mode="exact")[[1]]
21
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")
28 diff_norm = norm(μ_ref - μ_aligned)
29 cat(diff_norm,"\n")
30
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 }
35})