Repository navigation
Fix L1 distance to use Manhattan sum - #1998
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe ChangesMetric distance behavior
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The focused regression change is ready for maintainer review. The test suite coverage and formatting checks are complete. |
|
sum fix looks right but it's a breaking change for existing l1 users — distances will scale with dim now. Consider adding a deprecation warning or changelog note |
|
Hi @SahilKumar75 Thanks for the pull request! Please so our guidelines for the usual contribution process: https://sbi.readthedocs.io/en/latest/contributing.html The usual workflow would be first creating an issue stating the problem and discussing a solution. Can you please provide more details (as intended in our Pull Request Template): What's the problem here? what is this PR implementing and why? Thanks |
|
I opened #2008 to discuss the intended metric behavior and compatibility approach before changing the numerical convention. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1998 +/- ##
==========================================
- Coverage 89.43% 88.88% -0.55%
==========================================
Files 140 141 +1
Lines 14312 16612 +2300
==========================================
+ Hits 12800 14766 +1966
- Misses 1512 1846 +334
Flags with carried forward coverage won't be shown. Click here to find out more.
|
l1 now sums over dimensions, so the acceptance threshold in test_mcabc_performance needs one more factor of num_dim than the L2-norm distance. Without it the two-dimensional l1 case accepts a quarter of the simulations and the c2st check fails. Drop the l2 assertion from the new metrics test, which covers unchanged code, and check instead that differing coordinates add up.
janfb
left a comment
There was a problem hiding this comment.
Thanks for fixing this @SahilKumar75 !
This is a breaking change in principle, but in practice TARP, SMCABC and MCABC are not affected in their default settings. Still, we will mention this in the changelog for the next release.
Added a small fix for the tests: the eps needs scaling with d now that it's not averaged out.
Otherwise good to do! 👏
What does this PR do?
Changes
l1()from the mean of absolute differences to their sum, implementing the standard Manhattan distance.Updates the docstring and adds a regression test showing that a single differing coordinate contributes a distance of 1, including when additional identical coordinates are present.
Does this close any issues?
Related discussion: #2008
Anything else we should know?
The existing docstring explicitly describes averaging. This change therefore alters existing behavior: for an axis of length n, the new distance is n times the previous distance. The intended convention and compatibility approach need discussion before merging.
Previously reported validation:
ruff check sbi/utils/metrics.py tests/metrics_test.pyruff format --check sbi/utils/metrics.py tests/metrics_test.pypytest_harvestandnflowswere unavailable.No tests were rerun for this description update. The broader checks below remain unverified.
Checklist
uv run pytest -n auto -m "not slow and not gpu"passes.uv run pre-commit run --all-filespasses (ruff and formatting).uv run pyright sbipasses.pytest.mark.slow.