Hello,
I am new to Turing and trying to use it for my research on network ODE models.
I have started with a simple model (network diffusion)
\frac{du}{dt} = - \rho \mathbf{L} \mathbf{u}
and am trying to infer the value of \rho.
Below is the code for the ODE problem:
NetworkDiffusion(u, p, t) = -p * L * u
u0 = [0.9,0.1,0.1,0.1,0.1];
p = 1.0;
prob = ODEProblem(NetworkDiffusion, u0, (0.0,2.0), p);
sol = solve(prob, saveat=0.1);
data = Array(sol)
(L = 5×5 SparseArrays.SparseMatrixCSC{Int64,Int64} with 25 stored entries)
and for the Turing model:
Turing.setadbackend(:forwarddiff)
@model function fit(data, problem)
σ ~ InverseGamma(2, 3) # ~ is the tilde character
p ~ truncated(Normal(1.0,1.0),0.0,2.5)
prob = remake(problem, p=p)
predicted = solve(prob, saveat=0.1)
for i = 1:length(predicted)
data[:,i] ~ MvNormal(predicted[i], σ)
end
end
model = fit(data, problem);
chain = sample(model, NUTS(0.65), 1000)
With this code, I receive the following error:
TypeError: in typeassert, expected Float64, got a value of type ForwardDiff.Dual{Nothing,Float64,2}
(I can share more of the error message if needed).
I have been unable to identify what the problem is. There was a similar post in Oct 2020, but I doesn’t seem that the solutions presented there would apply in this case (I may be wrong). I would be very grateful for any help on how to fix the error!
Thanks,
Pavan