Skip to content

Commit

Permalink
Added test for pinferunemjmcmc (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Nov 30, 2021
1 parent e29a738 commit 6793ce6
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions tests/testthat/test-pinferunemjmcmc-example-match-1.4.3.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
# TODO #8: fill empty tests

# inference

X <- read.csv("inst/extdata/exa1.csv")
X <- read.csv("../../inst/extdata/exa1.csv")
data.example <- as.data.frame(X)

# specify the initial formula
formula1 <- as.formula(
paste(colnames(X)[5], "~ 1 +", paste0(colnames(X)[-5], collapse = "+"))
)

# a set of nonlinearities that will be used in the DBRM model
# a set of nonlinearities that will be used in the DBRM model as well as the
# "relations" argument of pinferunemjmcmc
sini <- function(x) sin(x / 180 * pi)
expi <- function(x) exp(-abs(x))
logi <- function(x) log(abs(x) + 1)
troot <- function(x) abs(x)^(1 / 3)
to23 <- function(x) abs(x)^(2.3)
to35 <- function(x) abs(x)^(3.5)

# define the number or cpus
M <- 4
# define the size of the simulated samples
NM <- 1000
# define \k_{max} + 1 from the paper
compmax <- 16
# define treshold for preinclusion of the tree into the analysis
th <- (10)^(-5)
# define a final treshold on the posterior marginal probability for reporting a
# tree
thf <- 0.05
M <- 4 # define the number or cpus
NM <- 1000 # define the size of the simulated samples
compmax <- 16 # define \k_{max} + 1 from the paper
th <- (10)^(-5) # define treshold for preinclusion of the tree into the analysis
thf <- 0.05 # final treshold on the posterior marginal prob for reporting a tree
# specify tuning parameters of the algorithm for exploring DBRM of interest
# notice that allow_offsprings=3 corresponds to the GMJMCMC runs and
# allow_offsprings=4 -to the RGMJMCMC runs
set.seed(9239838)
res1 <- pinferunemjmcmc(
n.cores = M, report.level = 0.5, num.mod.best = NM, simplify = TRUE,
runemjmcmc.params = list(
Expand All @@ -56,8 +48,14 @@ res1 <- pinferunemjmcmc(
)
)

print(res1$feat.stat)

test_that("pinferunemjmcmc output matches version 1.4.3", {

expect_named(
res1,
c("feat.stat", "predictions", "allposteriors", "threads.stats")
)
expect_length(res1, 4)
expect_length(res1$feat.stat, 14)
expect_equal(mean(res1$allposteriors$posterior), 0.280891, tolerance = 1e-4)
expect_equal(mean(res1$threads.stats[[1]]$p.post), 0.543057, tolerance = 1e-4)
})

0 comments on commit 6793ce6

Please sign in to comment.