2

Model in Turing.jl seems to be stuck in errors with

Warning: The current proposal will be rejected due to numerical error(s).
│   isfinite.((θ, r, ℓπ, ℓκ)) = (true, false, false, false)

for NUTS(), HMCDA() and sometimes HMC() sampling methods. I don't really understand what's causing these errors (what's θ?), but it makes NUTS and HMCDA unusable as sampling methods while HMC has around 2/3 of samples rejected. I looked at similar questions on here and on the forums, but no one seems to have a fix for this so far.

Kevin
  • 149
  • 6
  • 2
    It depends on the model, I guess. Perhaps add more information to help readers try to answer. Usually the best is to have something runnable (if possible). – Dan Getz Nov 04 '22 at 21:33
  • if isfinite(r) is giving errors, consider using !isapprox(1/r, 0) if the model allows it. – Bill Nov 05 '22 at 01:01
  • @DanGetz It is extremely model specific, and so I don't think creating a MRE is in the question. I was more referencing to the fact that this isn't the first time this has come up in stack, and there wasn't a definite fix for this. Also, I was hoping to get more info about what the 4 things that is infinite is checking for are? – Kevin Nov 05 '22 at 23:29
  • @Bill This function is something from within `Turing.jl` so I have no control in changing the checking function. – Kevin Nov 05 '22 at 23:30
  • Can you give a minimal sized runnable example that generates the error? – Bill Nov 06 '22 at 00:03
  • @Kevin this kind of feels like more of a statement than a question then. If you have a specific model that errors, Someone may be able to identify the problem, and this may point you towards how to debug other models. Regarding what is being checked by isinfinite, I have linked your question on the Turing slack channel in the Julia slack, so hopefully someone will be able to answer. – Arthur Newbury Nov 06 '22 at 19:05
  • @ArthurNewbury Thanks for that, how does one get access to the Julia slack? – Kevin Nov 07 '22 at 00:11
  • @Kevin https://julialang.org/slack/ – tsojtc Nov 07 '22 at 11:22

2 Answers2

1

From AdvancedHMC GitHub https://github.com/TuringLang/AdvancedHMC.jl/blob/beeb37b418992a3280fc3e59d01d2a124639507e/src/hamiltonian.jl

θ::T  # Position variables / model parameters.
r::T  # Momentum variables
ℓπ::V # Cached neg potential energy for the current θ.
ℓκ::V # Cached neg kinect energy for the current r.
1

θ is the current parameter vector, while the other three will depend on the target posterior distribution and are parameters to the physics engine used by HMC to explore the posterior.

If you are getting this warning for almost all of the proposed samples, your model is probably misspecified, but it's impossible to tell without the Turing model code of course.

It's not a big deal if you get this message a few dozen times while fitting model, especially if its during the warmup stage. I frequently get this message if there are parts of parameter space where the likelihood is not defined - for example if the model depends on the solution to a differential equation that returns NaN with the current parameters.

brendaisy
  • 71
  • 5