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

**URL:** <https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472>\
**Category:** Modelling & Simulations\
**Tags:** turing\
**Created:** [January 24, 2023, 4:47pm UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472 "2023-01-24T16:47:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfarndt](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@pfarndt](https://discourse.julialang.org/u/pfarndt)\
**Post date:** [January 24, 2023, 4:47pm UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472/1 "2023-01-24T16:47:38Z")

</div>

I slightly modifies the `gdemo` example in `Turing.jl` to accept more data to

```julia
# Import packages.
using Turing

# Define a simple Normal model with unknown mean and variance.
@model function gdemo(x)
    s² ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s²))
    x .~ Normal(m, sqrt(s²))
end

```

and generated some data - actually lots of it - this is key for the observed behaviour.

```julia
data = rand(Normal(2,1),10000);

```

and wanted to sample from the posterior:

```julia
c3 = sample(gdemo(data), HMC(0.1, 5), 100)

```

Which resulted in lots of warning messages:

```julia
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, false, false, false)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/4fByY/src/hamiltonian.jl:49
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, false, false, false)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/4fByY/src/hamiltonian.jl:49
...

```

In the end the sampler is stuck in one place:

```julia
Chains MCMC chain (100×11×1 Array{Float64, 3}):

Iterations = 1:1:100
Number of chains = 1
Samples per chain = 100
Wall duration = 0.13 seconds
Compute duration = 0.13 seconds
parameters = s², m
internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, step_size, nom_step_size

Summary Statistics
  parameters mean std naive_se mcse ess rhat es ⋯
      Symbol Float64 Float64 Float64 Float64 Float64 Float64 ⋯

          s² 2.2691 0.0000 0.0000 0.0000 2.0911 0.9899 ⋯
           m 0.1653 0.0000 0.0000 0.0000 NaN NaN ⋯
                                                                1 column omitted

Quantiles
  parameters 2.5% 25.0% 50.0% 75.0% 97.5% 
      Symbol Float64 Float64 Float64 Float64 Float64 

          s² 2.2691 2.2691 2.2691 2.2691 2.2691
           m 0.1653 0.1653 0.1653 0.1653 0.1653

```

What is wrong? Why is Turing performing badly when there is a lot of data?

---

<div class="post-metadata">

**Author:** ![sethaxen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sethaxen/32/35604_2.png) [@sethaxen](https://discourse.julialang.org/u/sethaxen)\
**Post date:** [January 27, 2023, 10:07am UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472/2 "2023-01-27T10:07:04Z")

</div>

> [@pfarndt](#):
>
> What is wrong? Why is Turing performing badly when there is a lot of data?

When you increase the data, often the posterior becomes more narrow, so the size and number of steps needed to cross the posterior will change. So the short answer is that the set of parameters you’re passing to `HMC` may be appropriate for that specific demo but will be unique to each problem.

A more general answer is, don’t use `HMC`. Use `NUTS`. `NUTS` tunes the step size and number of steps so you don’t have to. Even more importantly, Turing’s `HMC` implementation by default does not tune a metric, while `NUTS` tunes a diagonal metric, which would largely account for the change in posterior scale with increasing data.

Effectively, `HMC` represents decade-old methodologies, while `NUTS` is modern and fast and one of the key technologies that makes probabilistic programming practical. It’s really unfortunate that the Turing examples feature `HMC` so much.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 27, 2023, 10:27am UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472/3 "2023-01-27T10:27:07Z")

</div>

Should the examples just be changed? Would it be much harder than just swapping out `HMC` for `NUTS` and rerunning everything?

---

<div class="post-metadata">

**Author:** ![pfarndt](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@pfarndt](https://discourse.julialang.org/u/pfarndt)\
**Post date:** [January 28, 2023, 9:43pm UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472/5 "2023-01-28T21:43:38Z")

</div>

I agree the examples should probably updated, such that the examples generalise better.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [January 29, 2023, 12:26pm UTC](https://discourse.julialang.org/t/turing-jl-warning-the-current-proposal-will-be-rejected-due-to-numerical-error-s-isfinite-r-true-false-false-false/93472/6 "2023-01-29T12:26:14Z")

</div>

> [@sethaxen](#):
>
> Effectively, `HMC` represents decade-old methodologies, while `NUTS` is modern and fast

NUTS also **is** HMC it’s just HMC with an auto-tuning algorithm.
