Skip to content

Commit

Permalink
updated hmc_checkTarget to use checkADsupportForDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
danielturek committed Jun 1, 2024
1 parent 1efafc4 commit 89c4865
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions nimbleHMC/R/HMC_samplers.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,8 @@ hmc_checkTarget <- function(model, targetNodes, hmcType) {
dists <- targetDists_unique
ADok <- rep(TRUE, length(dists))
for(i in seq_along(dists)) {
##
## if/when modelDef$checkADsupportForDistribution() is added to core nimble,
## change the entire body of this for-loop to instead be:
## ADoak[i] <- model$getModelDef()$checkADsupportForDistribution(dists[i])
##
## these distributions get re-named to a nimble-version, and won't be found:
if(dists[i] %in% c('dweib', 'dmnorm', 'dmvt', 'dwish', 'dinvwish')) next
##
##
## find the function or this distribution:
nfObj <- get(dists[i], envir = parent.frame(4)) ## this took a bit of an investigation to make work
## is a user-defined distribution:
if(!is.null(environment(nfObj)$nfMethodRCobject)) {
## check for AD support:
ADok[i] <- !isFALSE(environment(nfObj)$nfMethodRCobject[['buildDerivs']])
}
dist_deparsed <- deparse(dists[i])
ADoak[i] <- model$getModelDef()$checkADsupportForDistribution(dist_deparsed)
}
if(!all(ADok))
stop(paste0(hmcType, ' sampler cannot operate on user-defined distributions which do not support AD calculations. Try using buildDerivs = TRUE in the definition the distributions: ', paste0(dists[!ADok], collapse = ', ')))
Expand Down

0 comments on commit 89c4865

Please sign in to comment.