elbow_helper.smoothing module
Phase 2 — the smoothing scale-space.
Generates a grid of odd smoothing windows (always including 1 = no
smoothing) and applies a centered Gaussian smoother with reflected boundaries,
implemented in pure NumPy (no scipy.ndimage).
- elbow_helper.smoothing.signal_and_noise(y, config)[source]
Split
yinto a smooth signal and noise of the curve’s own scale.The signal is a lightly smoothed copy of the observed curve, so every replicate keeps the shape actually measured. The noise is the smoother’s residual, rescaled so its standard deviation matches
robust_sigma_from_diffs(), the successive-difference estimate of the per-sample noise. The rescaling is what makes the bandwidth a shape choice rather than a noise-level choice: whatever curvature the smoother leaves behind, the perturbation injected into the replicates is always the size of the noise the data actually carry.This replaces fitting the accepted broken line and resampling its residuals. On a smoothly bending curve those residuals are dominated by the broken line’s own misfit rather than by noise – on a 784-point PCA scree spectrum they had a standard deviation of 0.054 against a true noise level of 0.00013, a 400-fold inflation – so the replicates were curves far noisier than anything observed and the knee went undetected in a fifth to a third of them. The failure grew with how sharply the curve bent, i.e. with how clear the elbow was, which is how a strong elbow ended up reported as
BOOTSTRAP_UNSTABLE.- Parameters:
y (numpy.ndarray) – The observed (scaled) curve.
config (RobustKneeConfig) – Supplies
bootstrap_signal_window.
- Returns:
(signal, residuals), both the length ofy.- Return type:
tuple of (numpy.ndarray, numpy.ndarray)
- elbow_helper.smoothing.smooth_curve(y, window, method='gaussian')[source]
Smooth
ywith a centered kernel and reflected boundaries.
- elbow_helper.smoothing.smoothing_grid(n, config)[source]
Odd smoothing windows for
nsamples, sorted ascending, deduplicated.- Parameters:
n (int) – Number of samples in the curve.
config (RobustKneeConfig) –
smoothing_fractionsare multiplied bynto size the windows.
- Returns:
Distinct odd window widths, always starting with
1.- Return type: