# Turing model not optimising; unstable ODE solutions

**URL:** <https://discourse.julialang.org/t/turing-model-not-optimising-unstable-ode-solutions/54526>\
**Category:** Probabilistic Programming\
**Tags:** question, diffeq, turing\
**Created:** [February 3, 2021, 11:47am UTC](https://discourse.julialang.org/t/turing-model-not-optimising-unstable-ode-solutions/54526 "2021-02-03T11:47:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PavanChaggar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pavanchaggar/32/21597_2.png) [@PavanChaggar](https://discourse.julialang.org/u/PavanChaggar)\
**Post date:** [February 3, 2021, 11:47am UTC](https://discourse.julialang.org/t/turing-model-not-optimising-unstable-ode-solutions/54526/1 "2021-02-03T11:47:40Z")

</div>

Hi,

I am getting an integration error with my Turing model. I have searched around but haven’t seen anything similar on discourse.

The ODE model is set up as follows:

```julia
using DifferentialEquations, LightGraphs, Random, Turing
using Turing: Variational

Random.seed!(1)

const N = 5
const P = 1.0

G = erdos_renyi(N, P)
L = laplacian_matrix(G)

function NetworkFKPP(u, p, t)
    κ, α = p 
    du = -κ * L * u .+ α .* u .* (1 .- u)
end

u0 = rand(N)
p = [2.0, 3.0]
t_span = (0.0, 2.0)

problem = ODEProblem(NetworkFKPP, u0, t_span, p)
sol = solve(problem, Tsit5(), saveat=0.05)

```

This seems to work fine.  
The Turing model is:

```julia
@model function fit(data, func)
    σ ~ InverseGamma(2, 3)
    k ~ truncated(Normal(5,10.0),0.0,10)
    a ~ truncated(Normal(5,10.0),0.0,10)
    u ~ MvNormal(0.5 * ones(5), ones(5))
    
    p = [k, a] 

    prob = remake(problem, u0=u, p=p)
    predicted = solve(prob, AutoTsit5(Rosenbrock23()), saveat=0.05)

    for i ∈ 1:length(predicted)
        data[:,i] ~ MvNormal(predicted[i], σ)
    end 
end 

```

When I run this using advi, I receive the following warning:

```julia
┌ Warning: dt <= dtmin. Aborting. There is either an error in your model specification or the true solution is unstable.
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/PW6zI/src/integrator_interface.jl:343
┌ Info: [ADVI] Should only be seen once: optimizer created for θ
└ objectid(θ) = 0x9425e7b5a1e9ddba

```

advi continues to run, but the end results are not accurate estimates of true parameters.

This warning does not present if I remove the line

```julia
 u ~ MvNormal(0.5 * ones(5), ones(5))

```

and only optimise the model parameters without updating the initial conditions.

Does anybody know what’s going wrong/have any suggestions on fixing?

Any help appreciated!

Thanks,  
Pavan

---

<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:** [February 3, 2021, 12:22pm UTC](https://discourse.julialang.org/t/turing-model-not-optimising-unstable-ode-solutions/54526/2 "2021-02-03T12:22:58Z")

</div>

I don’t think ADVI is stable for stiff equations.

---

<div class="post-metadata">

**Author:** ![PavanChaggar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pavanchaggar/32/21597_2.png) [@PavanChaggar](https://discourse.julialang.org/u/PavanChaggar)\
**Post date:** [February 3, 2021, 1:16pm UTC](https://discourse.julialang.org/t/turing-model-not-optimising-unstable-ode-solutions/54526/3 "2021-02-03T13:16:47Z")

</div>

Ok, thanks. Will this be true regardless of which optimiser I use for ADVI?

I will also try NUTS but I need to scale this problem up to 80-100 nodes, for which I thought ADVI would be better suited.
