Open torfjelde opened 3 days ago
@DominiqueMakowski made an issue from this as it's slightly more appropriate 👍
So I can't actually reproduce this on my end. Do you have a MWE maybe? The expected behavior of predict
is that all the variables present in the chain
you pass to predict
do not end up in the resulting pred
. If they do, then it's generally an indication that the varialbes in chain
are treated as random, which is clearly not what you want.
The following example works fine on my end though:
julia> using Turing
julia> @model function demo()
x ~ Normal()
y ~ Normal(x, 1)
end
demo (generic function with 2 methods)
julia> model = demo() | (y = 1.0,);
julia> chain = sample(model, NUTS(), 1000)
┌ Info: Found initial step size
└ ϵ = 6.4
Sampling 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:00
Chains MCMC chain (1000×13×1 Array{Float64, 3}):
Iterations = 501:1:1500
Number of chains = 1
Samples per chain = 1000
Wall duration = 0.61 seconds
Compute duration = 0.61 seconds
parameters = x
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
x 0.4624 0.6919 0.0278 621.3428 837.0866 0.9999 1023.6290
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
x -0.8236 -0.0280 0.4350 0.9221 1.8457
julia> predictions = predict(demo(), chain)
Chains MCMC chain (1000×1×1 Array{Float64, 3}):
Iterations = 1:1:1000
Number of chains = 1
Samples per chain = 1000
parameters = y
internals =
Summary Statistics
parameters mean std mcse ess_bulk ess_tail rhat ess_per_sec
Symbol Float64 Float64 Float64 Float64 Float64 Float64 Missing
y 0.4929 1.2464 0.0429 844.6265 876.9116 1.0064 missing
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
y -1.9575 -0.3699 0.5125 1.3360 2.8975
Let me try to make an MWE
(On a side note, regarding the new conditioning syntax, I thought I'd bring up Christopher's comment about possible drawbacks)
Alright, I think managed to make it reproducible 😥 , but i didn't manage to narrow it down to a simpler model so I'm not exactly sure what causes the error, it might be me doing something silly.
The script is here (in the folder there's also the manifest).
It takes a few long seconds to sample and compute unfortunately
Very oddly, if I predict on a subset of the data, it then works...
pred2 = predict(model_ExGaussian(fill(missing, length(df.ISI[1:60])), df.ISI[1:60], df.Participant[1:60]; min_rt=minimum(df.RT)), posteriors)
size(Array(pred2))
(200, 60)
Discussed in https://github.com/TuringLang/Turing.jl/discussions/2387