You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to save and reload dbarts fits. I saw the section in the help explaining the necessary step of touching the state object:
Saving
saveing and loading fitted BART objects for use with predict requires that R's serialization mechanism be able to access the underlying trees, in addition to being fit with keeptrees/keepTrees as TRUE. For memory purposes, the trees are not stored as R objects unless specifically requested. To do this, one must “touch” the sampler's state object before saving, e.g. for a fitted object bartFit, execute invisible(bartFit$fit$state).
However, saving and loading still breaks predictions even with this step. Here's an example:
# example from dbarts help
library(dbarts)
## simulate data (example from Friedman MARS paper)
## y = f(x) + epsilon , epsilon ~ N(0, sigma)
## x consists of 10 variables, only first 5 matter
f <- function(x) {
10 * sin(pi * x[,1] * x[,2]) + 20 * (x[,3] - 0.5)^2 +
10 * x[,4] + 5 * x[,5]
}
set.seed(99)
sigma <- 1.0
n <- 100
x <- matrix(runif(n * 10), n, 10)
Ey <- f(x)
y <- rnorm(n, Ey, sigma)
## run BART
set.seed(99)
bartFit <- bart(x, y, keeptrees=TRUE)
# generate predictions
preds <- predict(bartFit, x)
# touch the state object
invisible(bartFit$fit$state)
# attempt to save and load
tmp <- tempfile()
save(bartFit, file=tmp)
rm(bartFit)
load(tmp)
# new predictions are NaN
preds_after_save <- predict(bartFit, x)
all(is.nan(preds_after_save))
Are there additional steps necessary for this to work?
The text was updated successfully, but these errors were encountered:
I'm trying to save and reload dbarts fits. I saw the section in the help explaining the necessary step of touching the state object:
However, saving and loading still breaks predictions even with this step. Here's an example:
Are there additional steps necessary for this to work?
The text was updated successfully, but these errors were encountered: