Skip to content

Add predict to online documentation #332

@itsdfish

Description

@itsdfish

Hi all,

Turing includes a useful function predict
for generating posterior predictive samples. Unfortunately, many users will not find this because it is not listed in the online documentation.

A secondary issue is plotting the posterior predictive distributions. Currently, predict returns a chain, which is not conducive to certain plots (e.g. a scatter plot in the case of regression). Would it better to return an array of predictions, which could be converted to an MCMCChain if needed? Here is an example based on the doc string:

 using Turing; Turing.setprogress!(false);

 @model function linear_reg(x, y, σ = 0.1)
           β ~ Normal(0, 1)

           for i ∈ eachindex(y)
               y[i] ~ Normal(β * x[i], σ)
           end
       end;

 σ = 0.1; f(x) = 2 * x + 0.1 * randn();

 Δ = 0.1; xs = 0:Δ:10; ys = f.(xs);


 model = linear_reg(xs, ys, σ);

 chain_lin_reg = sample(model, NUTS(100, 0.65), 200);

 m_pred = linear_reg(xs, Vector{Union{Missing, Float64}}(undef, length(ys)), σ);

 predictions = predict(m_pred, chain_lin_reg)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions