I’ve tried running the code on my computer and got exactly the same results (for the first and second run). So, things are stable and reproducible - and not random.
A third run, gives the same result as the second. So the problem should be in some initialization/compilation on the first run.
Not sure what the problem is in my system. To check - I reran it three times, and these are the exact results. Same for first two times then different in 3rd times
julia> using Turing, StableRNGs
julia> @model function example(x)
m ~ Normal(0, 1)
x ~ Normal(m, sqrt(1))
end
example (generic function with 2 methods)
julia> res1 = sample(StableRNG(123), example(1), NUTS(), 1000)
┌ Info: Found initial step size
└ ϵ = 1.6
Chains MCMC chain (1000×13×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 0.49 seconds
Compute duration = 0.49 seconds
parameters = m
internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size
Summary Statistics
parameters mean std naive_se mcse ess rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64
m 0.4905 0.6835 0.0216 0.0314 490.8002 1.0054 1005.7380
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
m -0.8832 0.0403 0.4865 0.9456 1.7660
julia> res2 = sample(StableRNG(123), example(1), NUTS(), 1000)
┌ Info: Found initial step size
└ ϵ = 1.6
Chains MCMC chain (1000×13×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 0.07 seconds
Compute duration = 0.07 seconds
parameters = m
internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size
Summary Statistics
parameters mean std naive_se mcse ess rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64
m 0.4905 0.6835 0.0216 0.0314 490.8002 1.0054 7011.4309
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
m -0.8832 0.0403 0.4865 0.9456 1.7660
julia> res3 = sample(StableRNG(123), example(1), NUTS(), 1000)
┌ Info: Found initial step size
└ ϵ = 3.2
Chains MCMC chain (1000×13×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 0.05 seconds
Compute duration = 0.05 seconds
parameters = m
internals = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size
Summary Statistics
parameters mean std naive_se mcse ess rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64
m 0.5167 0.7029 0.0222 0.0301 533.6340 0.9999 10262.1917
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
m -0.8081 0.0530 0.5059 0.9911 1.8123
The problem seems to be in the initial step_size estimation. The alternative result is always given when the initial step_size is alternative as well. In any case, the following: