From bcdd01277bbcab042bde778ad0112b36b8a5e777 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 30 Aug 2023 10:04:05 +0200 Subject: [PATCH 1/5] Fixed output number format --- R/EMJMCMC2016-method-modejumping_mcmc.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/EMJMCMC2016-method-modejumping_mcmc.R b/R/EMJMCMC2016-method-modejumping_mcmc.R index 55968a5..c1900e5 100644 --- a/R/EMJMCMC2016-method-modejumping_mcmc.R +++ b/R/EMJMCMC2016-method-modejumping_mcmc.R @@ -96,7 +96,8 @@ EMJMCMC2016$methods( j.a <- j.a + 1 if (glob.model$print.freq > 0 && j %% glob.model$print.freq == 0) { cat( - formatC(j, width = 4L), "iterations completed up to now after", + formatC(j, width = 4L, format = "d"), + "iterations completed up to now after", formatC(delta.time, digits = 6L, flag = "-", format = "f"), "cpu minutes", "best MLIK found", From 81995b4208afba51ba2b22db5713bb5bdb72ebc8 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 30 Aug 2023 10:47:41 +0200 Subject: [PATCH 2/5] Refactoring --- R/LogicRegr.R | 38 +++++++++++++++++++++++--------------- man/LogicRegr.Rd | 24 ++++++++++++------------ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/R/LogicRegr.R b/R/LogicRegr.R index a1989fb..148e7ac 100644 --- a/R/LogicRegr.R +++ b/R/LogicRegr.R @@ -42,19 +42,23 @@ #' @export LogicRegr = function( formula, data, family = "Gaussian",prior = "J",report.level = 0.5, d = 20, - cmax = 5, kmax = 20, p.and = 0.9, p.not = 0.05, p.surv = 0.1,ncores = -1, - n.mods = 1000 ,advanced = list(presearch = T,locstop = F , - estimator = estimate.logic.bern.tCCH, - estimator.args = list(data = data.example,n = 1000, m = 50,r=1), - recalc_margin = 250, save.beta = FALSE, interact = TRUE, - relations = c("","lgx2","cos","sigmoid","tanh","atan","erf"), - relations.prob =c(0.4,0.0,0.0,0.0,0.0,0.0,0.0), - interact.param = list( - allow_offsprings=1,mutation_rate = 300,last.mutation = 5000, - max.tree.size = 1, Nvars.max = 100,p.allow.replace=0.9,p.allow.tree=0.2, - p.nor=0.2,p.and = 1),n.models = 10000,unique = TRUE,max.cpu = 4, - max.cpu.glob = 4,create.table = FALSE, create.hash = TRUE, - pseudo.paral = TRUE, burn.in = 50, outgraphs = FALSE, print.freq = 1000, + cmax = 5, kmax = 20, p.and = 0.9, p.not = 0.05, p.surv = 0.1, ncores = -1, + n.mods = 1000, + advanced = list( + presearch = TRUE,locstop = FALSE, + estimator = estimate.logic.bern.tCCH, + estimator.args = list(data = data.example,n = 1000, m = 50,r=1), + recalc_margin = 250, save.beta = FALSE, interact = TRUE, + relations = c("","lgx2","cos","sigmoid","tanh","atan","erf"), + relations.prob =c(0.4,0.0,0.0,0.0,0.0,0.0,0.0), + interact.param = list( + allow_offsprings=1, mutation_rate = 300, last.mutation = 5000, + max.tree.size = 1, Nvars.max = 100, p.allow.replace=0.9, p.allow.tree=0.2, + p.nor=0.2, p.and = 1 + ), + n.models = 10000, unique = TRUE, max.cpu = 4, max.cpu.glob = 4, + create.table = FALSE, create.hash = TRUE, pseudo.paral = TRUE, burn.in = 50, + outgraphs = FALSE, print.freq = 1000, advanced.param = list( max.N.glob=as.integer(10), min.N.glob=as.integer(5), @@ -108,6 +112,10 @@ LogicRegr = function( if(ncores<1) ncores = parallel::detectCores() - return(pinferunemjmcmc(n.cores = ncores,report.level = report.level, simplify = T, num.mod.best = n.mods, predict = F, runemjmcmc.params = advanced)) - + return( + pinferunemjmcmc( + n.cores = ncores, report.level = report.level, simplify = TRUE, + num.mod.best = n.mods, predict = FALSE, runemjmcmc.params = advanced + ) + ) } diff --git a/man/LogicRegr.Rd b/man/LogicRegr.Rd index c0bd88b..885568e 100644 --- a/man/LogicRegr.Rd +++ b/man/LogicRegr.Rd @@ -19,18 +19,18 @@ LogicRegr( p.surv = 0.1, ncores = -1, n.mods = 1000, - advanced = list(presearch = T, locstop = F, estimator = estimate.logic.bern.tCCH, - estimator.args = list(data = data.example, n = 1000, m = 50, r = 1), recalc_margin = - 250, save.beta = FALSE, interact = TRUE, relations = c("", "lgx2", "cos", "sigmoid", - "tanh", "atan", "erf"), relations.prob = c(0.4, 0, 0, 0, 0, 0, 0), interact.param = - list(allow_offsprings = 1, mutation_rate = 300, last.mutation = 5000, max.tree.size = - 1, Nvars.max = 100, p.allow.replace = 0.9, p.allow.tree = 0.2, p.nor = 0.2, p.and = - 1), n.models = 10000, - unique = TRUE, max.cpu = 4, max.cpu.glob = 4, - create.table = FALSE, create.hash = TRUE, pseudo.paral = TRUE, burn.in = 50, - outgraphs = FALSE, print.freq = 1000, advanced.param = list(max.N.glob = - as.integer(10), min.N.glob = as.integer(5), max.N = as.integer(3), min.N = - as.integer(1), printable = FALSE)) + advanced = list(presearch = TRUE, locstop = FALSE, estimator = + estimate.logic.bern.tCCH, estimator.args = list(data = data.example, n = 1000, m = + 50, r = 1), recalc_margin = 250, save.beta = FALSE, interact = TRUE, relations = + c("", "lgx2", "cos", "sigmoid", "tanh", "atan", "erf"), relations.prob = c(0.4, 0, 0, + 0, 0, 0, 0), interact.param = list(allow_offsprings = 1, mutation_rate = 300, + last.mutation = 5000, max.tree.size = 1, Nvars.max = 100, p.allow.replace = 0.9, + p.allow.tree = 0.2, p.nor = 0.2, p.and = 1), + n.models = 10000, unique = TRUE, + max.cpu = 4, max.cpu.glob = 4, create.table = FALSE, create.hash = TRUE, pseudo.paral + = TRUE, burn.in = 50, outgraphs = FALSE, print.freq = 1000, advanced.param = + list(max.N.glob = as.integer(10), min.N.glob = as.integer(5), max.N = as.integer(3), + min.N = as.integer(1), printable = FALSE)) ) } \arguments{ From 71d996faabf8f5e060b1a64af6496af4886a87fb Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 30 Aug 2023 10:48:10 +0200 Subject: [PATCH 3/5] Simplified BLR example --- tests/testthat/test-BLR-tutorial.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-BLR-tutorial.R b/tests/testthat/test-BLR-tutorial.R index 91779d9..d5374c4 100644 --- a/tests/testthat/test-BLR-tutorial.R +++ b/tests/testthat/test-BLR-tutorial.R @@ -8,7 +8,7 @@ # omp_set_num_threads(1) # #***********************IMPORTANT****************************************************** -n_threads <- min(parallel::detectCores() - 1, 7L) +n_threads <- 1L set.seed(040590) # construct a correlation matrix for M = 50 variables @@ -16,7 +16,7 @@ M <- 50 m <- clusterGeneration::rcorrmatrix(M, alphad = 2.5) # simulate 1000 binary variables with this correlation matrix -sample_size <- 100L +sample_size <- 1000L X <- suppressWarnings(bindata::rmvbin(sample_size, margprob = rep(0.5, M), bincorr = m)) # prepare the correlation matrix in the melted format @@ -44,10 +44,8 @@ formula1 <- as.formula( # FIXME: returns NULL objects even if ran at full power res4G <- LogicRegr( formula = formula1, data = df, family = "Gaussian", prior = "G", - report.level = 0.5, d = 15, cmax = 2, kmax = 15, p.and = 0.9, p.not = 0.1, - p.surv = 0.2, - ncores = n_threads, - n.mods = 10L + report.level = 0, d = 10, cmax = 2, kmax = 25, p.and = 0.5, p.not = 0.1, + p.surv = 0.2, ncores = 1L, n.mods = 3L ) # Bayesian logic regression with the Jeffreys prior From efd3d9e9319b7554a62943e6cb587f9b27bd9d6a Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 30 Aug 2023 13:18:24 +0200 Subject: [PATCH 4/5] Further unwrap of BLR tutorial test (#17) --- tests/testthat/test-BLR-tutorial.R | 44 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-BLR-tutorial.R b/tests/testthat/test-BLR-tutorial.R index d5374c4..2ac1d0e 100644 --- a/tests/testthat/test-BLR-tutorial.R +++ b/tests/testthat/test-BLR-tutorial.R @@ -17,7 +17,9 @@ m <- clusterGeneration::rcorrmatrix(M, alphad = 2.5) # simulate 1000 binary variables with this correlation matrix sample_size <- 1000L -X <- suppressWarnings(bindata::rmvbin(sample_size, margprob = rep(0.5, M), bincorr = m)) +X <- suppressWarnings( + bindata::rmvbin(sample_size, margprob = rep(0.5, M), bincorr = m) +) # prepare the correlation matrix in the melted format melted_cormat <- reshape2::melt(cor(X)) @@ -41,26 +43,44 @@ formula1 <- as.formula( ) # Bayesian logic regression with the robust-g-prior -# FIXME: returns NULL objects even if ran at full power res4G <- LogicRegr( formula = formula1, data = df, family = "Gaussian", prior = "G", - report.level = 0, d = 10, cmax = 2, kmax = 25, p.and = 0.5, p.not = 0.1, - p.surv = 0.2, ncores = 1L, n.mods = 3L + report.level = 0.5, d = 15, cmax = 2, kmax = 15, p.and = 0.9, p.not = 0.1, + p.surv = 0.2, ncores = n_threads ) # Bayesian logic regression with the Jeffreys prior -# res4J <- LogicRegr( -# formula = formula1, data = df, family = "Gaussian", prior = "J", -# report.level = 0.5, d = 15, cmax = 2, kmax = 15, p.and = 0.9, p.not = 0.1, -# p.surv = 0.2, ncores = n_threads -# ) +res4J <- LogicRegr( + formula = formula1, data = df, family = "Gaussian", prior = "J", + report.level = 0.5, d = 15, cmax = 2, kmax = 15, p.and = 0.9, p.not = 0.1, + p.surv = 0.2, ncores = n_threads +) + +# NULLs are expected because predict = FALSE on LogicRegr # # print the results for the robust g-prior -# print(base::rbind(c("expressions","probabilities"),res4G$feat.stat)) +test_that("Results for the G-prior are sensible", { + for (i in seq_len(nrow(res4G$allposteriors))) { + expect_gte(res4G$allposteriors[i, 2], 0) + expect_lte(res4G$allposteriors[i, 2], 1) + } + expect_gte(res4G$threads.stats[[1]]$post.populi, 0) + expect_gt(res4G$threads.stats[[1]]$cterm, 1000) + expect_equal(res4G$threads.stats[[1]]$preds, NULL) + expect_length(res4G, 4L) +}) # #print the results for the Jeffreys prior -# print(base::rbind(c("expressions","probabilities"),res4J$feat.stat)) - +test_that("Results for the Jeffrey's prior are sensible", { + for (i in seq_len(nrow(res4J$allposteriors))) { + expect_gte(res4J$allposteriors[i, 2], 0) + expect_lte(res4J$allposteriors[i, 2], 1) + } + expect_gte(res4J$threads.stats[[1]]$post.populi, 0) + expect_gt(res4J$threads.stats[[1]]$cterm, -1000) + expect_equal(res4J$threads.stats[[1]]$preds, NULL) + expect_length(res4J, 4L) +}) # # simulate Gaussian responses from a model with two-way interactions # # and an age effect which is an extension of S.4 of the paper From b5f02be48d5cda840a2eb8173522d326bfcd26fd Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 30 Aug 2023 14:06:38 +0200 Subject: [PATCH 5/5] Increment version number to 1.4.4.9031 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6848acb..8e972f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: EMJMCMC Type: Package Title: Flexible Bayesian Nonlinear Model Configuration -Version: 1.4.4.9030 +Version: 1.4.4.9031 Date: 2022-03-06 Authors@R: c(