# Combining DiffEqFlux with Turing for Bayesian Inference and Neural ODEs

**URL:** https://discourse.julialang.org/t/combining-diffeqflux-with-turing-for-bayesian-inference-and-neural-odes/46520
**Category:** New to Julia
**Tags:** package, turing, machine-learning
**Created:** [September 12, 2020, 7:22pm UTC](https://discourse.julialang.org/t/combining-diffeqflux-with-turing-for-bayesian-inference-and-neural-odes/46520 "2020-09-12T19:22:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![a\_garval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a_garval/32/18371_2.png) [@a\_garval](https://discourse.julialang.org/u/a_garval)
#### Post date: [September 12, 2020, 7:22pm UTC](https://discourse.julialang.org/t/combining-diffeqflux-with-turing-for-bayesian-inference-and-neural-odes/46520/1 "2020-09-12T19:22:17Z")

</div>

Hi all, I’m trying to implement a Bayesian Neural Network. The catch is that this neural network is used to approximate a function that is then integrated to predict time series generated by an ODE.

Reading through Turing’s tutorials I naively implemented the following:

```julia

ann = FastChain(FastDense(2, 5, sigmoid), FastDense(5,2, sigmoid))
nn_ode = NeuralODE(ann, (0.0, 4.9), alg = Vern7(), saveat = 0.1)

@model function fitlv(data)
    σ ~ InverseGamma(2, 3)
    p ~ MvNormal(zeros(27), 0.5)
    predict = Array(nn_ode(u0, p))
  
    for i = 1:size(data,2)
    
        data[:,i] ~ MvNormal(vec(predict[:,i]), σ)
    end
end

model = fitlv(odedata)
chain = sample(model, HMC(0.05, 4), 500)

```

Where `odedata` is a 2\*50 array with my training time series.

I run into the following error:

```julia
MethodError: Cannot `convert` an object of type Nothing to an object of type Array{Array{Float64,1},1}
Closest candidates are:
  convert(::Type{Array{T,N}}, !Matched::StaticArrays.SizedArray{S,T,N,M} where M) where {T, S, N} at /home/aslan_garcia/.julia/packages/StaticArrays/l7lu2/src/SizedArray.jl:72
  convert(::Type{Array{T,N}}, !Matched::AxisArrays.AxisArray{T,N,D,Ax} where Ax where D) where {T, N} at /home/aslan_garcia/.julia/packages/AxisArrays/IFpjG/src/core.jl:304
  convert(::Type{Array{T,N}}, !Matched::FillArrays.Zeros{V,N,Axes} where Axes) where {T, V, N} at /home/aslan_garcia/.julia/packages/FillArrays/NjFh2/src/FillArrays.jl:419

```

Any pointers will be very much appreciated, thanks!

---

<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: [September 13, 2020, 5:48am UTC](https://discourse.julialang.org/t/combining-diffeqflux-with-turing-for-bayesian-inference-and-neural-odes/46520/2 "2020-09-13T05:48:00Z")

</div>

Join the Slack. You might want to talk with Raj who is working through some of these examples right now.
