I have a (complicated) Poisson model that perfectly works when I don’t have an offset variable (e.g. y=exp(a+Bx)). On the contrary, when I specify an offset (y = exp(a+Bx+logE)) this is returned (at around 3% of the NUTS using jitter+adapt_diag process):
ValueError: Bad initial energy: nan. The model might be misspecified.
How can I debug it? I tried to print the test_points but I don’t see anything strange
In that case there must be some areas in your posterior is undefined and sometimes a large step size take the parameters outside of the supported domain. You can try to use a more informative prior to cut out those part of your parameter space.
Another explanation might be that some parameters don’t change at all, maybe because a gradient is zero. In that case, the mass matrix adaptation will try to use a variance of 0 at some point, which can lead to a nan. We should probably print a better error message in cases like that though.