Skip to content

Commit

Permalink
another attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
danielturek committed Jan 24, 2024
1 parent 4b95292 commit 658c29f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions nimbleHMC/R/HMC_samplers.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ hmc_checkTarget <- function(model, targetNodes, hmcType) {
##
dists <- model$getDistribution(targetNodes)
###### delete after here:
dists
dist <- dists[1]
if(dist %in% c('ddistNoAD', 'ddistAD')) {
print('AAAAAAA')
Expand All @@ -160,15 +161,24 @@ hmc_checkTarget <- function(model, targetNodes, hmcType) {
print('FFFFFFF')
}
##### stop deleting here
ADok <- sapply(dists,
function(dist) {
## this took some detective work to find the right environment:
nfObj <- eval(as.name(dist), envir = parent.frame(6))
if(!is.null(environment(nfObj)$nfMethodRCobject)) {
## user-defined:
return(!isFALSE(environment(nfObj)$nfMethodRCobject[['buildDerivs']]))
} else return(TRUE) ## non-user-defined
})
ADok <- rep(TRUE, length(dists))
for(i in seq_along(dists)) {
nfObj <- get(dists[i], envir = parent.frame(4))
if(!is.null(environment(nfObj)$nfMethodRCobject)) {
## is a user-defined distribution:
ADok[i] <- !isFALSE(environment(nfObj)$nfMethodRCobject[['buildDerivs']])
}
}
ADok
##ADok <- sapply(dists,
## function(dist) {
## ## this took some detective work to find the right environment:
## nfObj <- eval(as.name(dist), envir = parent.frame(6))
## if(!is.null(environment(nfObj)$nfMethodRCobject)) {
## ## user-defined:
## return(!isFALSE(environment(nfObj)$nfMethodRCobject[['buildDerivs']]))
## } else return(TRUE) ## non-user-defined
## })
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 658c29f

Please sign in to comment.