Skip to content

fix: preserve LOWESS nearest-neighbor selection - #286

Merged
xile611 merged 2 commits into
mainfrom
codex/fix-lowess-nearest-neighbors
Sep 18, 2026
Merged

xile611 merged 2 commits into
mainfrom
codex/fix-lowess-nearest-neighbors

Conversation

@xile611

@xile611 xile611 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

🤔 This is a ...

  • Bug fix
  • Test Case

🔗 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:

  • 197 package tests passed; all 6 performance tests passed separately with unchanged thresholds.
  • ESLint and CJS/ES/UMD builds passed.
  • The built CJS output matches all 101 original curve points within 5.9e-12 and confidence interval fields within 5.4e-12 (test tolerance: 1e-8).
  • The existing compile command fails with TS6059 because rootDir=src conflicts with including __tests__; the unchanged base fails identically. Type checking passed with tsc --noEmit --rootDir . --composite false --incremental false --types node,jest.
  • Pending integration verification: rerun the bugserver image comparison with a ChartSpace build consuming this fix. The online baseline has not been reset.

📝 Changelog

Language Changelog
🇺🇸 English Fix LOWESS curves and confidence intervals for unevenly distributed x values by restoring distance-based nearest-neighbor selection.
🇨🇳 Chinese 修复横轴分布不均时 LOWESS 曲线及置信区间偏移,恢复按实际距离选择最近邻。

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

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

copilot:summary

🔍 Walkthrough

copilot:walkthrough

@xile611
xile611 merged commit 9365af9 into main Sep 18, 2026
5 of 6 checks passed
@xile611
xile611 deleted the codex/fix-lowess-nearest-neighbors branch September 18, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants