Use float64 in Jenks natural breaks internals (#1100)#1101
Merged
brendancol merged 3 commits intomasterfrom Mar 31, 2026
Merged
Use float64 in Jenks natural breaks internals (#1100)#1101brendancol merged 3 commits intomasterfrom
brendancol merged 3 commits intomasterfrom
Conversation
The Jenks matrices and bin edge array used float32, causing the naive variance formula (sum_squares - sum*sum/w) to lose all significant digits when data had a large offset relative to its spread. Changed lower_class_limits, var_combinations, val cast, and kclass to float64.
test_natural_breaks_large_offset_1100: five tight clusters offset by 100,000 must be separated into 5 distinct classes. With float32 internals, the variance calculation lost all signal and merged clusters.
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.
Summary
Fixes #1100. The Jenks natural breaks algorithm used float32 for its internal matrices and bin edge array. The naive variance formula
sum_squares - (sum * sum) / wloses all significant digits when data has a large offset relative to its spread (elevations around 1000m, projected coordinates in the millions, etc.).Changed four float32 sites to float64:
lower_class_limitsmatrix dtypevar_combinationsmatrix dtypeval = np.float32(data[i4])cast removedkclassbin edge array dtypeTest plan
test_natural_breaks_large_offset_1100: five tight clusters at offset 100,000 with spread of 10 -- all 5 classes must be separated cleanlytest_classify.pysuite: 85 passed, no regressions