Skip to content

Commit

Permalink
change also NUTS_classic and defensively run model$calculate before i…
Browse files Browse the repository at this point in the history
…nitEpsilon
  • Loading branch information
perrydv committed Dec 18, 2024
1 parent 4d06ceb commit 4f0b429
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nimbleHMC/R/HMC_samplers.R
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ sampler_NUTS_classic <- nimbleFunction(
j <- j + 1
checkInterrupt()
}
if((timesRan <= nwarmup) & adaptive) adaptiveProcedure(btNL$a, btNL$na)
inverseTransformStoreCalculate(qNew)
nimCopy(from = model, to = mvSaved, row = 1, nodes = calcNodes, logProb = TRUE)
if((timesRan <= nwarmup) & adaptive) adaptiveProcedure(btNL$a, btNL$na)
},
methods = list(
drawMomentumValues = function() {
Expand Down Expand Up @@ -580,6 +580,7 @@ sampler_NUTS_classic <- nimbleFunction(
##for(i in 1:d) M[i] <<- 1 / warmupCovRegularized[i,i]
sqrtM <<- sqrt(M)
if(adaptEpsilon) {
inverseTransformStoreCalculate(qNew) #defensively ensure model states are up to date
initEpsilon()
epsilonAdaptCount <<- 0
mu <<- log(10 * epsilon)
Expand Down Expand Up @@ -995,7 +996,10 @@ sampler_NUTS <- nimbleFunction(
update <- FALSE
if(adaptM) update <- adapt_M()
if(update & adaptEpsilon) {
if(initializeEpsilon) initEpsilon()
if(initializeEpsilon) {
inverseTransformStoreCalculate(state_sample$q) # defensively ensure model states are up to date.
initEpsilon()
}
Hbar <<- 0
logEpsilonBar <<- 0
stepsizeCounter <<- 0
Expand Down

0 comments on commit 4f0b429

Please sign in to comment.