Repository navigation
Clamp Pareto-smoothed Pathfinder init weights at 0 - #1324
Merged
Merged
Conversation
Member
|
I changed this to target the v1.0 branch (instead of master) so I could see if there are any merge conflicts with v1.0. Looks like there is a conflict. I'll fix the merge conflict and push. |
jgabry
approved these changes
Oct 13, 2026
jgabry
left a comment
Member
There was a problem hiding this comment.
I changed this to target the v1.0 branch, fixed the merge conflict, and simplified the test a little bit. I also added a comment about removing this once we require a version of posterior with the fix. When CI passes we can merge this into the v1.0 branch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1.0 #1324 +/- ##
=======================================
Coverage ? 93.95%
=======================================
Files ? 19
Lines ? 7656
Branches ? 0
=======================================
Hits ? 7193
Misses ? 463
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1323.
This PR was assisted by Claude
Summary
$sample(init = pathfinder_fit)can fail withAssertion on 'weights' failed: Element <i> is not >= 0.This PR sets negative Pareto-smoothed weights inprocess_init_approx()to 0 beforeposterior::resample_draws().Cause
process_init_approx()Pareto-smooths the importance weights on the natural scale,exp(lp__ - lp_approx__ - max(...)). When most Pathfinder paths are poor, most of these values underflow to exactly 0. With posterior 1.7.1 and earlier,pareto_smooth()can then return weights of about-2e-16, andresample_draws()rejects them. stan-dev/posterior#468 fixes the cause in posterior. This PR protects users with a posterior version without that fix.Change
In
process_init_approx()(R/args.R), after the call toposterior::pareto_smooth():The change applies only to the branch that Pareto-smooths the weights. The values that the clamp changes are of the order of
1e-16, so the selection probabilities do not change in practice. Therowsum()collapse of duplicate draws that follows then sums non-negative values.Tests
New test in
tests/testthat/test-fit-init.R,Pathfinder init weights are not negative after Pareto smoothing. It uses a fake Pathfinder fit, as the existing tests in that file do, so it does not need CmdStan.posterior::pareto_smooth()andresample_draws(). With posterior 1.7.1 on master, this gives the errorAssertion on 'weights' failed: Element 341 is not >= 0.pareto_smooth()that returns negative weights, and with three duplicate draws. This part tests the clamp with any posterior version, also with a version that contains Remove the offset at a tied Pareto tail cutoff posterior#468.On master, the new test gives 3 failures. With this PR, it passes.
Tested versions
master55342f4f.NOT_CRAN=true, the new test and the existing tests intest-fit-init.Rthat use fake fits pass (Pathfinder fit initializations use the intended weights,Pathfinder init candidates are distinct target parameter vectors,VB and Laplace inits error with the right algorithm label,draws inits are recycled in order when too few are supplied), and their snapshots do not change. I did not run the tests that compile and fit models locally.Copyright and Licensing
Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Aalto University
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: