I am defining a custom distribution (i.e. a user defined
*_lpdf function) which makes use of
integrate_1d to numerically solve for the normalization constant. This is a 1D integration over
y for a distribution whose shape (
sigma), location (
y_0), etc. parameters are parameters of the Stan model. While debugging, I added some print statements and noticed that the integrate_1d function seems to be called many times for the same parameter values. Presumably this happens because the
*_lpdf function is called once per data sample, where the normalization will be constant because the parameters are not changing within the leapfrog step.
In a situation like this, will Stan automatically cache the integrator output so that it can skip repeated
integrate_1d evaluations? If not, is it possible to manually do that in some way?
In particular, I wondered if I could extract the integration out of the
*_lpdf function so that I could manually enforce that it be run just once per step, but I wasn’t sure how to do that while still making use of sampling statements (with the
~ operator) associated with a custom distribution.
Thanks in advance for any guidance!