DifferentialEquations with Turing

Dear all,

I’d like to use DifferentialEquations.jl with Turing.jl, I read that this was possible, but I’ve trouble to run it.

Here is a simple try with Lotka-Voltera equation, how to fix it to make it running?

using DifferentialEquations
using Turing

# define Lotka-Voltera model
function odeLotkaVoltera(dx,x,p,t)
 dx[1] = x[1]*(p[1]-p[2]*x[2])
 dx[2] = x[2]*(p[3]*x[1]-p[4])

# Turing Bayesian model
@model probLotkaVoltera(x,y,tspan) = begin
    # priors
    s ~ InverseGamma(2, 3)
    α ~ Normal(0, sqrt(s))
    β ~ Normal(0, sqrt(s))
    p = [α,β,1.0,1.0]
    x0 = [1.0;1.0]
    # models
    prob = ODEProblem(odeLotkaVoltera,x0,tspan,p)
    xProb = prob(1,:)
    yProb = prob(2,:)
    # likelihood
    for i in 1:length(xProb)
        x[i] ~ Normal(xProb[i], sqrt(s))
        y[i] ~ Normal(yProb[i], sqrt(s)) 

# Data
x0 = [1.0;1.0]
p = [2/3,4/3,1.0,1.0]
tspan = (0.0, 10.0)
prob = ODEProblem(odeLotkaVoltera,x0,tspan,p)
sol = solve(prob)
x = sol[1,:]
y = sol[2,:]

#  Run sampler, collect results
chnLotkaVoltera = sample(probLotkaVoltera(x, y, tspan), HMC(0.1, 5), 100)


for various approaches.

Great. I’m going to look at it. Thank you.

Note that @Vaibhavdixit02 is working on a fix right now actually. There was an update in Turing that broke DiffEqBayes but we’ll have it running again in a day or so.