skills/timeseries/transit-depth-polynomial-optimization/SKILL.md
Estimate event depth by optimizing a scalar scaling factor on the in-event segment that minimizes polynomial baseline residual across the full signal
npx skillsauth add wenmin-wu/ds-skills timeseries-transit-depth-polynomial-optimizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Given a time series with a known dip region (ingress/egress boundaries detected), estimate the dip depth by finding a scalar s such that scaling the in-dip segment by (1+s) produces the smoothest polynomial fit across the full signal. Minimize the mean absolute residual of the polynomial. This is a physics-free, general-purpose depth estimation technique.
import numpy as np
from scipy.optimize import minimize
def estimate_depth(signal, ingress, egress, margin=10, poly_deg=3):
"""Estimate dip depth via polynomial baseline optimization.
Args:
signal: 1D time series
ingress, egress: dip boundary indices
margin: buffer around boundaries to exclude
poly_deg: polynomial degree for baseline
Returns:
depth: estimated fractional depth of the dip
"""
def objective(s):
corrected = np.concatenate([
signal[:ingress - margin],
signal[ingress + margin:egress - margin] * (1 + s[0]),
signal[egress + margin:]
])
x = np.arange(len(corrected))
poly = np.poly1d(np.polyfit(x, corrected, poly_deg))
return np.mean(np.abs(poly(x) - corrected))
result = minimize(objective, x0=[0.0001], method='Nelder-Mead')
return result.x[0]
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF