X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-computeMu.R;h=fccef55fbfa3f49841a69ae575642b050d2eedd4;hp=8234cd72dbb5f78f75fba1074c56f807ea492f2d;hb=6dd5c2acccd10635449230faa824b7e8906911bf;hpb=bbdcfe44da4011574dabb19b4f83e2ab199c667a diff --git a/pkg/tests/testthat/test-computeMu.R b/pkg/tests/testthat/test-computeMu.R index 8234cd7..fccef55 100644 --- a/pkg/tests/testthat/test-computeMu.R +++ b/pkg/tests/testthat/test-computeMu.R @@ -2,34 +2,34 @@ 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 (model in c("logit","probit")) + { + cat("\n\n",model," :\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), model) + μ = 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_that( diff_norm, is_less_than(0.5) ) + } + } })