Skip to content

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Oct 22, 2025

I think pretty much all that is needed is fixing initial_params.

Edit: Oh, there was istrans -> is_transformed too.

Edit 2: Oh no, there's SamplingContext 😭

@github-actions
Copy link
Contributor

Preview the changes: https://turinglang.org/docs/pr-previews/661
Please avoid using the search feature and navigation bar in PR previews!

Comment on lines -40 to 46
w = [0.5, 0.5]
μ = [-3.5, 0.5]
mixturemodel = MixtureModel([MvNormal(Fill(μₖ, 2), I) for μₖ in μ], w)
μ = [-2.0, 2.0]
mixturemodel = MixtureModel([MvNormal(Fill(μₖ, 2), 0.2 * I) for μₖ in μ], w)
# We draw the data points.
N = 60
N = 30
x = rand(mixturemodel, N);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having 30 observations just makes life easier because it triggers fewer resampling steps with PG. To compensate for that I made the data more tightly clustered to make sure that the results are still somewhat meaningful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locally, this cuts the time taken to run this tutorial to about 12 minutes. I'm not sure what it was before but I think it was certainly over 20 minutes.

Comment on lines 144 to 146
model = linear_regression(train, train_target)
chain = sample(model, NUTS(), 5_000)
chain = sample(StableRNG(468), model, NUTS(), 20_000)
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually know what went wrong here, i struggled to get this to work without bumping the samples. It might just be that the 5000 samples one just happened to be a very lucky seed. It takes very little time because NUTS is quite fast anyway.

@penelopeysm penelopeysm requested a review from mhauru October 23, 2025 16:21
Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the OLS/Bayesian linear regression match previously was just a fluke. In that case, happy to approve, thanks for doing this.

@assert isapprox(bayes_train_loss, ols_train_loss; rtol=0.01) "Difference between Bayesian training loss ($bayes_train_loss) and OLS training loss ($ols_train_loss) unexpectedly large!"
@assert isapprox(bayes_test_loss, ols_test_loss; rtol=0.05) "Difference between Bayesian test loss ($bayes_test_loss) and OLS test loss ($ols_test_loss) unexpectedly large!"
@assert bayes_train_loss > ols_train_loss "Bayesian training loss ($bayes_train_loss) <= OLS training loss ($bayes_train_loss)"
@assert bayes_test_loss < ols_test_loss "Bayesian test loss ($bayes_test_loss) >= OLS test loss ($ols_test_loss)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if it was just happenstance that these actually pretty much matched each other before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, not sure to be honest. I think the atols were quite fragile, even changing the way the test/train split was done led to things failing there. So I'd say yes.

@penelopeysm penelopeysm merged commit 9ce0077 into main Oct 24, 2025
2 checks passed
@penelopeysm penelopeysm deleted the py/turing041 branch October 24, 2025 14:09
github-actions bot added a commit that referenced this pull request Oct 24, 2025
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

Successfully merging this pull request may close these issues.

3 participants