-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Some RTMB users have become used to having a list including all data and potential hyperparameters, unpacked by getAll(), in their custom likelihood function. This was shown in many RTMB examples.
Sampling with SparseNUTS fails in this case because rebuilding of the AD function fails. Presumably, this is because the list (called dat below) is only available in the global environment, not inside sample_snuts().
The simple code below generates this error for me:
library(RTMB)
library(SparseNUTS)
data(ChickWeight)
nll <- function(par) {
getAll(par, dat)
mu <- beta0 + beta1 * x
-sum(dnorm(y, mu, sdeps, log=TRUE))
}
par <- list(beta0 = mean(ChickWeight$weight), beta1 = 0, sdeps = 1)
# list with data and often hyperparameters
dat <- list(y = ChickWeight$weight, x = ChickWeight$Time)
# MakeADFun pulls dat from the global environment, so this works fine
obj <- MakeADFun(nll, par)
opt <- nlminb(obj$par, obj$fn, obj$gr)
fit <- sample_snuts(obj)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels