Documentation
¶
Overview ¶
Package stats provides statistical functions for CI performance analysis.
Index ¶
- func ClampOutliers(data []float64, multiplier float64) []float64
- func IQR(data []float64) (q1, q3, iqr float64)
- func MannWhitneyU(sample1, sample2 []float64) (u, pValue float64)
- func MannWhitneyURand(sample1, sample2 []float64, rng *rand.Rand) (u, pValue float64)
- func Mean(data []float64) float64
- func Median(data []float64) float64
- func Percentile(data []float64, p float64) float64
- func Stddev(data []float64) float64
- type ChangePoint
- type OutlierResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClampOutliers ¶
ClampOutliers replaces isolated extreme values with the nearest fence value. Uses the IQR method: values beyond Q3 + multiplier×IQR (or below Q1 - multiplier×IQR) are clamped to the fence. This prevents single extreme outliers from poisoning downstream analysis while preserving genuine level shifts (which move the IQR).
func MannWhitneyU ¶
MannWhitneyU performs a two-sided Mann-Whitney U test comparing two samples. Uses a fresh random source for the permutation path, so results are non-deterministic. For deterministic tests use MannWhitneyURand.
func MannWhitneyURand ¶
MannWhitneyURand performs a two-sided Mann-Whitney U test comparing two samples. Uses three strategies depending on sample size:
- Exact enumeration when n1+n2 <= 20 (feasible combinatorics)
- Monte Carlo permutation test when min(n1,n2) <= 20 (small sample, exact infeasible)
- Normal approximation when both n1,n2 > 20
If rng is nil, a fresh random source is used. A small p-value (< 0.05) indicates the two samples likely come from different distributions.
func Percentile ¶
Percentile returns the p-th percentile (0-100) using linear interpolation. The input is not modified.
Types ¶
type ChangePoint ¶
type ChangePoint struct {
Index int // position in the series where the change was detected
BeforeMean float64 // mean of values before the change
AfterMean float64 // mean of values after the change
PctChange float64 // percentage change (positive = slowdown, negative = speedup)
Direction string // "slowdown" or "speedup"
}
ChangePoint represents a detected shift in a time series.
func CUSUMDetect ¶
func CUSUMDetect(data []float64, thresholdMultiplier float64, minSegment int) []ChangePoint
CUSUMDetect runs two-sided CUSUM (Cumulative Sum) change-point detection. It uses adaptive thresholds based on the local coefficient of variation:
- slack (k) = 0.5 * stddev of baseline
- threshold (h) = thresholdMultiplier * stddev of baseline
minSegment controls the minimum number of points between detected change points and at the start/end of the series.
type OutlierResult ¶
type OutlierResult struct {
Index int
Value float64
Percentile float64 // what percentile this value falls at (0-100)
IsOutlier bool
}
OutlierResult contains the result of outlier detection for a single data point.
func LogIQROutliers ¶
func LogIQROutliers(data []float64, multiplier float64) (outliers []OutlierResult, upperFence float64)
LogIQROutliers detects abnormally slow values using the IQR method on log-transformed data. Only flags the upper tail — unusually fast runs are not interesting for CI analysis. The multiplier controls sensitivity (standard: 1.5, conservative: 3.0).
func MADOutliers ¶
func MADOutliers(data []float64, threshold float64) (outliers []OutlierResult)
MADOutliers detects abnormally slow values using Median Absolute Deviation. Only flags the upper tail. The threshold is applied to the modified z-score (commonly 3.5).