Hi,
I’m wondering if hyperpriors work on Turing. I’m playing around with Turing and trying to use it to estimate a Hidden Markov Model. In my HMM model, I’ve used a multivariate normal prior on parameters of my transition probability model with its mean and variance components respectively having a multivariate normal and inverse wishart prior (hyperpriors). With the hyper priors, I always get the error:
ERROR: PosDefException: matrix is not Hermitian; Cholesky factorization failed.
Its tough to explain the code and model and be concise so I’ve created a similar example on bayesian linear regression with similar prior and hyper priors to estimate the regression coefficients. This time however, I did not get the earlier error seen above but was instead returned a long error as follows:
ERROR: MethodError: no method matching PDMats.PDMat{ForwardDiff.Dual{ForwardDiff.Tag{getfield(Turing.Core, Symbol("#f#24")){Turing.Core.VarReplay.VarInfo,Turing.Model{Tuple{:σ₂,:Sigma,:Mu,:beta_hat},Tuple{:y},getfield(Main, Symbol("###inner_function#31011#140")).......... and more...
The code for the bayesian regression is as follows:
####################################################################
# Data Generation
####################################################################
df = DataFrame(
x1 = rand(Normal(), 100),
x2 = rand(Normal(), 100)
);
beta = [5, 4, 5];
df[:y] = beta[1] .+ beta[2]*df[:x1] + beta[3]*df[:x2] + rand(Normal(), 100);
####################################################################
# Bayesian Inference with Turing
####################################################################
@model BayesReg(y, x1, x2) = begin
n_obs = length(y)
σ₂ ~ InverseGamma(0.001, 0.001)
Sigma ~ InverseWishart(
3 + 1,
Matrix{Float64}(I, 3, 3)
)
Mu ~ MvNormal(
zeros(3),
Matrix{Float64}(I, 3, 3)
)
beta_hat ~ MvNormal(Mu, Sigma)
mu = beta_hat[1] .+ beta_hat[2]*x1 .+ beta_hat[3]*x2
for i = 1:n_obs
y[i] ~ Normal(mu[i], σ₂)
end
end;
model = BayesReg(df[:y], df[:x1], df[:x2])
chain = sample(model, NUTS(1500, 200, 0.65));
Any ideas where I may have gone wrong or misunderstood something about the package…?