Loo cv to Bayesian Estimation of Differential Equations (challenge)

For ArviZ.jl, you’ll need to compute the likelihoods using Turing and then package them into an array for ArviZ. There’s an example of how to do this in Quickstart · ArviZ.jl, but I’ve adapted it here:

julia> using ArviZ

julia> log_likelihood = let
           log_likelihood = pointwise_loglikelihoods(
               model, MCMCChains.get_sections(chain, :parameters)
           )
           names = sort(collect(keys(log_likelihood)); by=x->parse(Int, split(x, ",")[2][1:end-1]))
           log_likelihood_data = getindex.(Ref(log_likelihood), names)
           (; data=cat(log_likelihood_data...; dims=3))
       end;

julia> idata = from_mcmcchains(chain; log_likelihood)
InferenceData with groups:
  > posterior
  > log_likelihood
  > sample_stats

julia> loo(idata)
1×9 DataFrame
 Row │ elpd_loo  se       p_loo    n_samples  n_data_points  warning  ⋯
     │ Float64   Float64  Float64  Int64      Int64          Bool     ⋯
─────┼─────────────────────────────────────────────────────────────────
   1 │ -411.174  9.93684  105.107       3000            101    false  ⋯
2 Likes