# DifferentialEquations with Turing

**URL:** <https://discourse.julialang.org/t/differentialequations-with-turing/33100>\
**Category:** General Usage\
**Tags:** package\
**Created:** [January 8, 2020, 3:06pm UTC](https://discourse.julialang.org/t/differentialequations-with-turing/33100 "2020-01-08T15:06:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![virgile-baudrot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virgile-baudrot/32/6857_2.png) [@virgile-baudrot](https://discourse.julialang.org/u/virgile-baudrot)\
**Post date:** [January 8, 2020, 3:06pm UTC](https://discourse.julialang.org/t/differentialequations-with-turing/33100/1 "2020-01-08T15:06:18Z")

</div>

Dear all,

I’d like to use [DifferentialEquations.jl](https://github.com/JuliaDiffEq/DifferentialEquations.jl) with [Turing.jl](https://turing.ml/dev/), 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?

```julia
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])
end

# 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)) 
    end
end

# 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)

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 8, 2020, 3:25pm UTC](https://discourse.julialang.org/t/differentialequations-with-turing/33100/2 "2020-01-08T15:25:10Z")

</div>

See

> **[GitHub - SciML/DiffEqBayes.jl: Extension functionality which uses Stan.jl,...](https://github.com/SciML/DiffEqBayes.jl)**
>
> Extension functionality which uses Stan.jl, DynamicHMC.jl, and Turing.jl to estimate the parameters to differential equations and perform Bayesian probabilistic scientific machine learning - GitHub...

for various approaches.

---

<div class="post-metadata">

**Author:** ![virgile-baudrot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virgile-baudrot/32/6857_2.png) [@virgile-baudrot](https://discourse.julialang.org/u/virgile-baudrot)\
**Post date:** [January 8, 2020, 3:46pm UTC](https://discourse.julialang.org/t/differentialequations-with-turing/33100/3 "2020-01-08T15:46:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 9, 2020, 4:22am UTC](https://discourse.julialang.org/t/differentialequations-with-turing/33100/4 "2020-01-09T04:22:28Z")

</div>

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.
