Skip to content

Smooth layer#223

Merged
teunbrand merged 16 commits intoposit-dev:mainfrom
teunbrand:smooth
Mar 18, 2026
Merged

Smooth layer#223
teunbrand merged 16 commits intoposit-dev:mainfrom
teunbrand:smooth

Conversation

@teunbrand
Copy link
Collaborator

This PR adds working smooth layer.

It comes in 3 variants, OLS, TLS and Kernel regression. The first 2 are straight line fits, the 3rd is a locally weighted average.
In addition to the layer, this PR also adds trimming logic to the core density code.

A think I wish I could've handled was using these layers for date position scales like timeseries. However, I've not found palatable solutions to switch between date(time) to numeric back to date(time) again.

teunbrand and others added 8 commits March 10, 2026 16:36
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Smooth and violin layers now trim their rendering to the actual data range
instead of extrapolating beyond it. Grid expansion uses 3×bandwidth (kernel-aware)
instead of a fixed 10% extension.

Key optimizations:
- Consolidated min/max computation into bandwidth CTE (eliminates redundant query)
- Unified grid construction logic in build_grid_cte() with per-group trimming
- Removed compute_range_sql() and unused execute parameter throughout call chain
- Extracted shared SQL generation logic to reduce duplication

All density/smooth/violin tests pass (269 tests verified).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The violin renderer was filtering out low-density points (< 0.001) to trim thin
tails, but this is now handled properly upstream with grid trimming in the stat
transform. The stat_violin function trims the grid to data range + 3×bandwidth,
making this downstream filter redundant.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@teunbrand teunbrand mentioned this pull request Mar 13, 2026
24 tasks
teunbrand and others added 7 commits March 16, 2026 16:05
Resolved merge conflicts in density.rs by combining:
- Grid trimming with dynamic range computation (917fde8)
- Dialect support with SqlDialect parameter (88baccd)

Key changes:
- density_sql_bandwidth: Combined dynamic MIN/MAX range with dialect-aware silverman_rule
- build_grid_cte: Added dialect support while keeping grid trimming
- choose_kde_kernel: Changed ANY_VALUE to MIN for portability, kept Nadaraya-Watson support
- Fixed smooth.rs and violin.rs to include dialect parameter

All tests pass: density (14), violin (8), smooth (4)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@teunbrand teunbrand marked this pull request as ready for review March 18, 2026 12:19
@teunbrand teunbrand requested review from thomasp85 March 18, 2026 12:19
Copy link
Collaborator

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not many comments - the queries looks as crazy as always :-)

@teunbrand teunbrand merged commit 3bbed9d into posit-dev:main Mar 18, 2026
18 checks passed
@teunbrand teunbrand deleted the smooth branch March 18, 2026 14:58
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