Repository navigation
FIX: prevent overflow in _incremental_mean_and_var - #35248
tatopenn-cell wants to merge 1 commit into
Conversation
The cumulative-sum formula reconstructs last_sum = last_mean * last_sample_count and new_sum, both of which overflow on long streams with large values. The delta-based update of Chan, Golub and LeVeque (1979) is algebraically equivalent but never reconstructs the sum. This fixes the mean and the variance in one pass. The previous attempt (scikit-learn#11549) fixed only the mean and left the cross-term of the variance untouched, which is why it was closed as incomplete. Two non-regression tests: - test_incremental_mean_and_var_large_values_no_overflow - test_incremental_mean_and_var_constant_values Fixes scikit-learn#5602.
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
❌ Linting issuesThis PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling You can see the details of the linting issues under the
|
The cumulative-sum formula reconstructs last_sum = last_mean * last_sample_count and new_sum, both of which overflow on long streams with large values. The delta-based update of Chan, Golub and LeVeque (1979) is algebraically equivalent but never reconstructs the sum.
This fixes the mean and the variance in one pass. The previous attempt (#11549) fixed only the mean and left the cross-term of the variance untouched, which is why it was closed as incomplete.
Two non-regression tests:
Fixes #5602.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Introduce yourself
AI usage disclosure
I used AI assistance for:
Any other comments?