Skip to content

Commit

Permalink
Reduced test length (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Feb 19, 2024
1 parent 5feb0c4 commit 4c91632
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
37 changes: 22 additions & 15 deletions tests/testthat/test-LogicRegr-example-match-1.4.3.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
set.seed(040590)
set.seed(265508)
n_cores <- 1L
n_row <- 100L
n_col <- 11L
n_tot <- n_row * n_col
X1 <- as.data.frame(
array(
data = rbinom(n = 50 * 1000, size = 1,
prob = runif(n = 50 * 1000, 0, 1)), dim = c(1000, 50)
data = rbinom(n = n_tot, size = 1, prob = runif(n = n_tot)),
dim = c(n_row, n_col)
)
)
Y1 <- rnorm(
n = 1000,
mean = 1 + 0.7 * (X1$V1 * X1$V4) + 0.8896846 * (X1$V8 * X1$V11) + 1.434573 * (X1$V5 * X1$V9),
n = n_row,
mean = 1 +
0.7 * (X1$V1 * X1$V4) +
0.8896846 * (X1$V8 * X1$V11) +
1.434573 * (X1$V5 * X1$V9),
sd = 1
)
X1$Y1 <- Y1

# specify the initial formula
formula1 <- as.formula(
paste(colnames(X1)[51], "~ 1 +", paste0(colnames(X1)[-c(51)], collapse = "+"))
paste(
colnames(X1)[n_col + 1L], "~ 1 +",
paste0(colnames(X1)[-c(n_col + 1L)], collapse = "+")
)
)
data.example <- as.data.frame(X1)

# run the inference with robust g prior
n_cores <- parallel::detectCores() - 1

res4G <- EMJMCMC::LogicRegr(
formula = formula1, data = data.example, family = "Gaussian", prior = "G",
report.level = 0.5, d = 15, cmax = 2, kmax = 15, p.and = 0.9, p.not = 0.01,
Expand All @@ -35,11 +43,10 @@ res4J <- EMJMCMC::LogicRegr(
)

test_that("LogicRegr output matches version 1.4.3", {
# TODO: results below are from dev version. Install 1.4.3 and rerun to match.
obs_4G <- as.numeric(res4G$feat.stat[, 2])
obs_4J <- as.numeric(res4J$feat.stat[, 2])
expect_length(obs_4G, 3L)
expect_true(all(obs_4G > 0.9) && all(obs_4G < 1))
expect_length(obs_4J, 4L)
expect_true(all(obs_4J > 0.6) && all(obs_4J < 1))
obs_4G <- as.numeric(res4G$allposteriors[, 2])
obs_4J <- as.numeric(res4J$allposteriors[, 2])
expect_length(obs_4G, 15L)
expect_true(all(obs_4G >= 0) && all(obs_4G <= 1))
expect_length(obs_4J, 15L)
expect_true(all(obs_4J >= 0) && all(obs_4J <= 1))
})
50 changes: 26 additions & 24 deletions tests/testthat/test-parall.gmj-example-match-1.4.3.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
j <- 1
M <- 4
set.seed(80334)
n_cores <- min(parallel::detectCores() - 1L, 20L)
M <- 1L
n_row <- 100L
n_col <- 50L
n_tot <- n_row * n_col
X4 <- as.data.frame(
array(
data = rbinom(n = 50 * 1000, size = 1, prob = runif(n = 50 * 1000, 0, 1)),
dim = c(1000, 50)
data = rbinom(n = n_tot, size = 1, prob = runif(n = n_tot)),
dim = c(n_row, n_col)
)
)
Y4 <- rnorm(
n = 1000,
n = n_row,
mean = 1 +
7 * (X4$V4 * X4$V17 * X4$V30 * X4$V10) +
7 * (X4$V50 * X4$V19 * X4$V13 * X4$V11) +
Expand All @@ -22,53 +26,51 @@ Y4 <- rnorm(
X4$Y4 <- Y4

formula1 <- as.formula(
paste(colnames(X4)[51], "~ 1 +", paste0(colnames(X4)[-c(51)], collapse = "+"))
paste(
colnames(X4)[n_col + 1L], "~ 1 +",
paste0(colnames(X4)[-c(n_col + 1L)], collapse = "+")
)
)
data.example <- as.data.frame(X4)

vect <- list(
formula = formula1, outgraphs = FALSE, data = X4,
estimator = estimate.logic.lm,
estimator.args = list(data = data.example, n = 100, m = 50),
recalc_margin = 249, save.beta = FALSE, interact = TRUE,
estimator.args = list(data = data.example, n = 100, m = n_col),
recalc_margin = 1000L, 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 = 250, last.mutation = 15000,
allow_offsprings = 1, mutation_rate = 250, last.mutation = 1000,
max.tree.size = 4, Nvars.max = 40, p.allow.replace = 0.7,
p.allow.tree = 0.2, p.nor = 0, p.and = 0.9
), n.models = 20000, unique = TRUE, max.cpu = 4, max.cpu.glob = 4,
), n.models = 20000, unique = TRUE, max.cpu = n_cores, max.cpu.glob = n_cores,
create.table = FALSE, create.hash = TRUE, pseudo.paral = TRUE,
burn.in = 50, 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
max.N.glob = 10L, min.N.glob = 5L, max.N = 3L, min.N = 1L, printable = FALSE
)
)

params <- list(vect)[rep(1, M)]

for (i in 1:M) {
for (i in seq_len(M)) {
params[[i]]$cpu <- i
params[[i]]$NM <- 1000
params[[i]]$NM <- n_row
params[[i]]$simlen <- 21
}

message("begin simulation ", j)
set.seed(363571)
results <- parall.gmj(X = params, M = 1)
results <- parall.gmj(X = params, M = n_cores)

test_that("parall.gmj output matches version 1.4.3", {
# TODO: results below are from dev version. Install 1.4.3 and rerun to match.
expect_length(results, 4L)
for (i in 1:4) {
expect_length(results, M)
for (i in seq_len(M)) {
expect_length(results[[i]], 4L)
expect_named(results[[i]], c("post.populi", "p.post", "cterm", "fparam"))
expect_length(results[[i]][[2]], 40L)
expect_true(all(results[[i]][[2]] < 1.0))
expect_lt(results[[i]][[3]], 0)
expect_true(all(results[[i]][[2]] <= 1.0))
expect_length(results[[i]][[3]], 1L)
expect_length(results[[i]][[4]], 40L)
}
})

0 comments on commit 4c91632

Please sign in to comment.