Hello,
I am new to Turing and try to do MCMC sampling from a simple linear forward model with gaussian prior.
I got the following model:
A = randn(20, 1000)
m = size(A, 1)
n = size(A, 2)
x_true = randn(n)
σ_prior = 0.1
x = x_true + σ_prior * randn(n)
σ_obs = 0.001
y = A * x_true + σ_obs * randn(m)
@model function gaussian_model(A::Matrix{T},
σ_noise::T, prior_emissions::Vector{T}, σ_prior::T, obs::Vector{T}, ::Type{T2}=Float64) where {T, T2}
## unknown emission field
# σ_prior ~ truncated(Normal(0, 1), 0, Inf)
X ~ MvNormal(prior_emissions, σ_prior)
## likelihood
y = A * T2.(X)
obs ~ MvNormal(y, σ_noise)
end
model = gaussian_model(A, σ_obs, x, σ_prior, y)
I am trying to use the NUTS sampler as followed:
chains = sample(model, NUTS(0.65), 20, progress=true, adtype=AutoReverseDiff())
I end up with a very small step size and the NUTS sampler is fast for the first 10 samples but slows down dramatically afterwards. I read that this could happen because of large data model mismatches, but I don’t think this is the case in my model.
I had to add the types as above in the model in order to not get errors with Prior sampling, for some reason otherwise A * X
would be of type Vector{Any}
.
Did I do something wrong in defining the model or setting up NUTS? Or is NUTS not the right sampler for this problem?