fix: preserve LOWESS nearest-neighbor selection - #286
Merged
Merged
Conversation
666haiwen
approved these changes
Sep 18, 2026
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.
🤔 This is a ...
🔗 Related issue link
Scatter regression visual comparison (internal access required).
💡 Background and solution
The LOWESS optimization in b0766a0 (released in v1.0.21) replaced distance-ranked nearest neighbors with a fixed window around the insertion index. These select different samples when x values are unevenly distributed, changing the fitted curve and confidence intervals. In the 406-point scatter example, the neighborhood at x=12 changes from [9, 18] to [0, 18], doubling the weighting radius from 6 to 12.
Preserve sorting and binary search, then expand two pointers by actual distance to select the nearest samples. Clamp the neighborhood to the available sample count and preserve original input order when equally near points require a zero-weight fallback. Sampling, robust-iteration defaults, and public APIs remain unchanged.
Add deterministic tests for uneven distributions, duplicate x values, extrapolation, ties, empty/single-point inputs, plus frozen pre-optimization outputs for the original 406-point example. Restoring only the incorrect window in an isolated copy makes the compatibility test fail again.
Validation:
compilecommand fails with TS6059 becauserootDir=srcconflicts with including__tests__; the unchanged base fails identically. Type checking passed withtsc --noEmit --rootDir . --composite false --incremental false --types node,jest.📝 Changelog
No public API changes. LOWESS results affected by the incorrect neighborhood selection will change; existing large-data sampling and iteration policies remain in place.
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough