X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-computeMu.R;h=c1fd4f910e5c63fae03499eec47e70244694cd0a;hp=fccef55fbfa3f49841a69ae575642b050d2eedd4;hb=ab35f6102896a49e86e853262c0650faa2931638;hpb=6dd5c2acccd10635449230faa824b7e8906911bf diff --git a/pkg/tests/testthat/test-computeMu.R b/pkg/tests/testthat/test-computeMu.R index fccef55..c1fd4f9 100644 --- a/pkg/tests/testthat/test-computeMu.R +++ b/pkg/tests/testthat/test-computeMu.R @@ -1,23 +1,21 @@ -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) ) + β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")) + μ_ref <- normalize(βs_ref[,,i]) + for (link in c("logit","probit")) { - cat("\n\n",model," :\n",sep="") + 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") @@ -25,11 +23,11 @@ test_that("on input of sufficient size, β/||β|| is estimated accurately enough 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) + 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 ) } } })