X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-computeMu.R;h=c1fd4f910e5c63fae03499eec47e70244694cd0a;hp=8234cd72dbb5f78f75fba1074c56f807ea492f2d;hb=ab35f6102896a49e86e853262c0650faa2931638;hpb=cbd88fe5729bf206a784238a2637aa60e697fcdc diff --git a/pkg/tests/testthat/test-computeMu.R b/pkg/tests/testthat/test-computeMu.R index 8234cd7..c1fd4f9 100644 --- a/pkg/tests/testthat/test-computeMu.R +++ b/pkg/tests/testthat/test-computeMu.R @@ -1,35 +1,33 @@ -context("computeMu") - test_that("on input of sufficient size, β/||β|| is estimated accurately enough", { - n = 100000 - d = 2 - K = 2 - p = 1/2 + n <- 100000 + d <- 2 + K <- 2 + p <- 1/2 - βs_ref = array( c(1,0,0,1 , 1,-2,3,1), dim=c(d,K,2) ) - for (i in 1:(dim(βs_ref)[3])) - { - μ_ref = normalize(βs_ref[,,i]) - for (model in c("logit","probit")) - { - cat("\n\n",model," :\n",sep="") + βs_ref <- array( c(1,0,0,1 , 1,-2,3,1), dim=c(d,K,2) ) + for (i in 1:(dim(βs_ref)[3])) + { + μ_ref <- normalize(βs_ref[,,i]) + for (link in c("logit","probit")) + { + cat("\n\n",link," :\n",sep="") - io = generateSampleIO(n, p, βs_ref[,,i], rep(0,K), model) - μ = computeMu(io$X, io$Y, list(K=K)) - μ_aligned = alignMatrices(list(μ), ref=μ_ref, ls_mode="exact")[[1]] + io <- generateSampleIO(n, p, βs_ref[,,i], rep(0,K), link) + μ <- computeMu(io$X, io$Y, list(K=K)) + μ_aligned <- alignMatrices(list(μ), ref=μ_ref, ls_mode="exact")[[1]] - #Some traces: 0 is not well estimated, but others are OK - cat("Reference normalized matrix:\n") - print(μ_ref) - cat("Estimated normalized matrix:\n") - print(μ_aligned) - cat("Difference norm (Matrix norm ||.||_1, max. abs. sum on a column)\n") - diff_norm = norm(μ_ref - μ_aligned) - cat(diff_norm,"\n") + #Some traces: 0 is not well estimated, but others are OK + cat("Reference normalized matrix:\n") + print(μ_ref) + cat("Estimated normalized matrix:\n") + print(μ_aligned) + cat("Difference norm (Matrix norm ||.||_1, max. abs. sum on a column)\n") + diff_norm <- norm(μ_ref - μ_aligned) + cat(diff_norm,"\n") - #NOTE: 0.5 is loose threshold, but values around 0.3 are expected... - expect_that( diff_norm, is_less_than(0.5) ) - } - } + # NOTE: 0.5 is loose threshold, but values around 0.3 are expected... + expect_lt( diff_norm, 0.5 ) + } + } })