TypeError using ODEs in Turing.jl

Hi all,

I try using ODEs within Turing model, but I have the following error:
TypeError: in typeassert, expected Float64, got ForwardDiff.Dual{Nothing,Float64,1}

Here is my code:

function myODE(du,u,p,t)
    du[1] = p[1] * (0.1-u[1])
end


@model bayesODE(x, t) = begin
  # 1. SET PRIORS
  prior ~ Normal(0, 1)
  #kd = 1
  # 2. MECHANISTIC MODELS
  x0 = [0.0]
  tspan = (0.0,10.0)
  #paramODE = convert.(Float64, kd)
  prob = ODEProblem(myODE,x0,tspan,prior)
  _saveat = t === nothing ? Float64[] : t
  sol_tmp = solve(prob ; saveat = _saveat)
  for i in 1:length(x)
      x[i] ~ Normal(sol_tmp.u[i][1], 2)
  end
end
#  Run sampler, collect results
chn = sample(bayesODE([10 11 12], [1 2 3]), HMC(0.1, 5), 100)

Thanks

prob = ODEProblem(myODE,eltype(prior).(x0),tspan,prior)

https://docs.juliadiffeq.org/latest/basics/faq/#Native-Julia-solvers-compatibility-with-autodifferentiation-1

1 Like

perfect. Thank you