TuringLang / docs

Documentation and tutorials for the Turing language
https://turinglang.org/docs/
MIT License
231 stars 99 forks source link

Inference Tutorials of a Stochastic Differential Equation runs incorrectly #281

Closed lilianping closed 2 years ago

lilianping commented 2 years ago

When I ran the tutorial SDE, I ended up with an error “DimensionMismatch("parent has 101 elements, which is incompatible with size (202,)")” ,Why is this? image

rikhuijzer commented 2 years ago

I've moved this issue since it is about https://turing.ml/dev/tutorials/10-bayesian-differential-equations/.

Why is this?

The core of this issue is that the Differential Equations tutorial is never evaluated in an automated job because it takes too long to do so. If it would be evaluated regularly, we could have spotted and fixed this issue earlier. The tutorials would be helped by having more computing power available, but efforts such as https://github.com/TuringLang/TuringTutorials/pull/280 have stalled.

rikhuijzer commented 2 years ago

crossref: https://discourse.julialang.org/t/the-bayesian-sde-in-the-turing-tutorial-issues-an-error/73447.

devmotion commented 2 years ago

The tutorial was just updated yesterday (https://github.com/TuringLang/TuringTutorials/pull/296) and runs fine with the latest versions of Turing and DifferentialEquations (see https://turing.ml/dev/tutorials/10-bayesian-differential-equations/). It's part of our CI pipeline, and hence it should be easy to spot and fix regressions when e.g. updating Turing or DifferentialEquations in the future.

erinaldi commented 2 years ago

Thanks for the update @devmotion

I may have a small comment about this closed issue. Even if the code of the SDE part of the tutorial "runs fine", it is using the wrong data in the model See: https://github.com/TuringLang/TuringTutorials/blob/0e1fa7a385037c59b4f00f0aa521680601472f53/tutorials/10-bayesian-differential-equations/10_bayesian-differential-equations.jmd#L433

It uses the original LV ode data (with gaussian noise) instead of the ensemble of SDE solutions generated in the previous cell. If we run the SDE model on the ensemble data the likelihood

    for i in 1:length(predicted)
        data[:, i] ~ MvNormal(predicted[i], σ^2 * I)
    end

will fail with

ERROR: BoundsError: attempt to access EnsembleSolution Solution of length 1000 with uType:
devmotion commented 2 years ago

Well, it was what I wanted to do. The model is written such that the observations are a single trajectory, and the noisy ODE data is one possibility. I viewed the ensembles of SDE solutions merely as an illustration of the SDE behaviour and the stochasticity.

However, https://github.com/TuringLang/TuringTutorials/blob/0e1fa7a385037c59b4f00f0aa521680601472f53/tutorials/10-bayesian-differential-equations/10_bayesian-differential-equations.jmd#L371 indicates that possibly the intention of the original author was different and they wanted to use multiple trajectories instead.

erinaldi commented 2 years ago

Yes, indeed that is what I think too. It seems the previous cell is setup to use the entire ensemble, but the model is not.