Function theil_sen_slope

Source
pub fn theil_sen_slope(samples: &[(f64, f64)]) -> Result<f64, StatsError>
Expand description

Computes the deterministic Theil–Sen slope of (seconds, value) samples.

The estimator is the median of every pairwise slope with distinct timestamps. Input ordering does not affect the result. It is robust to isolated RSS spikes and is therefore preferable to an endpoint delta for a long-running memory gate.

Time is in seconds and values use the caller’s unit, so the returned slope is value-units per second. Equal-time pairs are ignored. Memory use is quadratic in sample count because every distinct-time pair contributes.

§Errors

Returns InsufficientTrendSamples, NonFinite, or NoDistinctTrendTimestamps for the corresponding invalid inputs.

§Examples

let slope = ailloli_ui_bench::theil_sen_slope(&[(0.0, 10.0), (2.0, 11.0)])?;
assert_eq!(slope, 0.5);