Hi, I’m working with an ODE model in RStan 2.26.1. The log_prob function is calculated correctly from what I can tell – it matches what I calculate by hand from the mean-square error of the difference between the ODE solution and given data. However, grad_log_prob says the gradient is (NaN, NaN) (for the two free parameters) for any values I tried. In each case grad_log_prob also reports log_prob, and the log_prob is correct.
How can I dig into what’s going on here to see where the gradient is getting messed up? For example, can I find the code which was generated to compute the gradient? Can I get Stan to print out any intermediate quantities in the gradient calculation? I know I can get Stan to print the gradient to a diagnostic output file, however, what I think I need to look at are the values of things during the calculation, not just the final output (which is NaN for all the examples I tried).
Incidentally I have plotted contours of the RMSE (this should be a simple function of the log likelihood, and therefore the log probability as well, given that the priors are uniform over some range) and from what I can tell the likelihood function is well behaved.
Another message which I found on a similar topic (Gradient evaluated at the initial value is not finite although the lp is finite) didn’t have any specific advice about how to debug this problem. I found some other messages which mentioned similar problems, but, again, didn’t find something applicable to the problem I am encountering.
Thank you for any insights which you may offer,