Hello Everyone,
I asked this a few years ago, and it did not seem possible. However, maybe the situation has changed.
I have my own custom sampler in which I have to calculate the sum of some log densities under different values of a parameter. I use the calculate function for this, but unfortunately, it updates the model, so I have to run it an extra time to go back. Anyway, I will paste the code below.
end_lf <- model$getLogProb(f_dependencies[f_start_depend[ct]:f_end_depend[ct]])
lf[ct,1] <<- end_lf
lf[ct,3] <<- end_lf
#now need to calcl epi_lf
model$S[loc,ct] <<- 2
epi_lf <- model$calculate(f_dependencies[f_start_depend[ct]:f_end_depend[ct]])
lf[ct,2] <<- epi_lf
#now have to go back, no way around this
model$S[loc,ct] <<- original_state
model$calculate(nodes=f_dependencies[f_start_depend[ct]:f_end_depend[ct]])
Ideally, it would look something like this.
end_lf <- model$getLogProb(f_dependencies[f_start_depend[ct]:f_end_depend[ct]])
lf[ct,1] <<- end_lf
lf[ct,3] <<- end_lf
#now need to calcl epi_lf
model$S[loc,ct] <<- 2
epi_lf <- model$calculate(f_dependencies[f_start_depend[ct]:f_end_depend[ct]],update=FALSE)
lf[ct,2] <<- epi_lf
#now have to go back, no way around this
model$S[loc,ct] <<- original_state
I was wondering if there was anyway to avoid the last calculate. Hopefully, it makes sense.
Best,
Dirk