You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lately I've been experimenting with various ways to speed up the Turing model.I tried the @distributed method but got completely wrong results after using it.
One of my questions is how to get the correct results using the @distributed method?Another question is is there any other way to get the results quickly and correctly? I've tried Threads.@threads but the speed increase is not good enough.
Running the code below I can get the same result as the initial definition of the mean of the Poisson distribution.
using Distributions,Turing,Random
using Distributed
n=3000
μ=(rand(Uniform(20,40),10))
10-element Vector{Float64}:
30.256065112894298
26.014315408019847
24.61075823480178
21.519220815830373
24.423829409052153
31.93931799311691
36.88338733245446
23.069268268746683
27.68725276509452
22.156260959934805
rd=rand.(Poisson.(μ),n)
@model function Turing_tele(y)
# Our prior belief about the probability of heads in a coin.
ρ ~ filldist(Gamma(6.5,2.25),10) #
for i = 1:10
y[i] ~ Poisson(ρ[i])
end
end
model = Turing_tele(rd)
Random.seed!(1) @time chn = sample(model, NUTS(),1000)
Info: Found initial step size
└ ϵ = 0.00625
16.337205 seconds (23.63 M allocations: 1.696 GiB, 3.03% gc time, 38.45% compilation time)
Chains MCMC chain (1000×22×1 Array{Float64, 3}):
But if I use @distributed before the loop in the Turing model, the result is completely wrong
@model function Turing_tele(y)
# Our prior belief about the probability of heads in a coin.
ρ ~ filldist(Gamma(6.5,2.25),10) # @distributed for i = 1:10
y[i] ~ Poisson(ρ[i])
end
end
Info: Found initial step size
└ ϵ = 1.6
11.582992 seconds (4.06 M allocations: 425.341 MiB, 0.37% gc time, 9.47% compilation time: 73% of which was recompilation)
Chains MCMC chain (1000×22×1 Array{Float64, 3}):
Lately I've been experimenting with various ways to speed up the Turing model.I tried the @distributed method but got completely wrong results after using it.
One of my questions is how to get the correct results using the @distributed method?Another question is is there any other way to get the results quickly and correctly? I've tried Threads.@threads but the speed increase is not good enough.
Running the code below I can get the same result as the initial definition of the mean of the Poisson distribution.
using Distributions,Turing,Random
using Distributed
n=3000
μ=(rand(Uniform(20,40),10))
10-element Vector{Float64}:
30.256065112894298
26.014315408019847
24.61075823480178
21.519220815830373
24.423829409052153
31.93931799311691
36.88338733245446
23.069268268746683
27.68725276509452
22.156260959934805
rd=rand.(Poisson.(μ),n)
@model function Turing_tele(y)
# Our prior belief about the probability of heads in a coin.
ρ ~ filldist(Gamma(6.5,2.25),10) #
for i = 1:10
y[i] ~ Poisson(ρ[i])
end
end
model = Turing_tele(rd)
Random.seed!(1)
@time chn = sample(model, NUTS(),1000)
Info: Found initial step size
└ ϵ = 0.00625
16.337205 seconds (23.63 M allocations: 1.696 GiB, 3.03% gc time, 38.45% compilation time)
Chains MCMC chain (1000×22×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 13.49 seconds
Compute duration = 13.49 seconds
parameters = ρ[1], ρ[2], ρ[3], ρ[4], ρ[5], ρ[6], ρ[7], ρ[8], ρ[9], ρ[10]
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 mcse ess_bulk ess_tail rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
But if I use @distributed before the loop in the Turing model, the result is completely wrong
@model function Turing_tele(y)
# Our prior belief about the probability of heads in a coin.
ρ ~ filldist(Gamma(6.5,2.25),10) #
@distributed for i = 1:10
y[i] ~ Poisson(ρ[i])
end
end
Info: Found initial step size
└ ϵ = 1.6
11.582992 seconds (4.06 M allocations: 425.341 MiB, 0.37% gc time, 9.47% compilation time: 73% of which was recompilation)
Chains MCMC chain (1000×22×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 11.34 seconds
Compute duration = 11.34 seconds
parameters = ρ[1], ρ[2], ρ[3], ρ[4], ρ[5], ρ[6], ρ[7], ρ[8], ρ[9], ρ[10]
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 mcse ess_bulk ess_tail rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64
The text was updated successfully, but these errors were encountered: