Commit | Line | Data |
---|---|---|
cbd88fe5 BA |
1 | context("computeMu") |
2 | ||
3 | test_that("on input of sufficient size, β/||β|| is estimated accurately enough", | |
4 | { | |
6dd5c2ac BA |
5 | n = 100000 |
6 | d = 2 | |
7 | K = 2 | |
8 | p = 1/2 | |
cbd88fe5 | 9 | |
6dd5c2ac BA |
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="") | |
cbd88fe5 | 17 | |
6dd5c2ac BA |
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]] | |
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") | |
28 | diff_norm = norm(μ_ref - μ_aligned) | |
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 | }) |