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

Simple user error makes code evaluate forever - Calling DynamicPPL.Model as a function. #2182

Open
JohannesNE opened this issue Mar 12, 2024 · 0 comments

Comments

@JohannesNE
Copy link

I tried to make posterior predictions by adapting the example from predict() for my model.

I made a mistake where I used the conditional model, m_lin_reg instead of linear_reg.
This made the code evaluate forever and therefore did not result in any useful error message.

This is of cause a user error, but it would have saved me a lot of frustration if an error was thrown.

# based on example from ?predict
using Turing

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

    μ = β .* x

    for i  eachindex(y)
        y[i] ~ Normal(μ[i], σ)
    end
end

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

Δ = 0.1
xs_train = 0:Δ:10; ys_train = f.(xs_train);
xs_test = [10 + Δ, 10 + 2 * Δ]; ys_test = f.(xs_test);

m_lin_reg = linear_reg(xs_train, ys_train);
chain_lin_reg = sample(m_lin_reg, NUTS(100, 0.65), 200);

# Mistake where I use conditional model `m_lin_reg` instead of the intended `linear_reg()`
# This hangs forever.
m_lin_reg_test = m_lin_reg(xs_test, Vector{Union{Missing, Float64}}(undef, length(ys_test)));

predictions = predict(m_lin_reg_test, chain_lin_reg)

ys_pred = ys_pred = vec(mean(Array(group(predictions, :y)); dims = 1));

@JohannesNE JohannesNE changed the title Simple user error makes code Evaluate forever - Calling DynamicPPL.Model as a function. Simple user error makes code evaluate forever - Calling DynamicPPL.Model as a function. Mar 12, 2024
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

1 participant