Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add predict to online documentation #332

Open
itsdfish opened this issue Sep 3, 2022 · 1 comment
Open

Add predict to online documentation #332

itsdfish opened this issue Sep 3, 2022 · 1 comment

Comments

@itsdfish
Copy link

itsdfish commented Sep 3, 2022

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)

@youainti
Copy link

youainti commented Oct 5, 2022

With regards to your first point, I think that would be simple to add to the current examples, maybe the current Linear Regression example would be a good place?

As far as plotting posterior predictive distributions goes, my initial inclination would be to have predict still return an MCMCChains struct, but build a posterior_predict function (or set of functions) that would allow easy comparison etc. In my mind I am envisioning a hypothetical TuringPredictiveAnalysis.jl package that has utilities and plot recipes for easy analysis. This seems like a separate issue so it might be good to open it as a different issue somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants