Documentation
¶
Overview ¶
Package stats provides core statistical functions for numerical analysis. All standard deviation calculations use population stddev (÷n, not ÷(n−1)).
Index ¶
- Constants
- func Clamp[T cmp.Ordered](val, lo, hi T) T
- func Distribution[T any](items []T, classify func(T) string) map[string]int
- func ExceedsThreshold(observed, predicted, threshold float64) bool
- func Max[T cmp.Ordered](values []T) T
- func Mean(values []float64) float64
- func MeanStdDev(values []float64) (mean, stddev float64)
- func Median(values []float64) float64
- func Min[T cmp.Ordered](values []T) T
- func Percentile(values []float64, p float64) float64
- func Sum[T cmp.Ordered](values []T) T
- func ToPercent(ratio float64) float64
- type EMA
Constants ¶
const ( PercentileMedian = 0.5 PercentileP95 = 0.95 )
Well-known percentile thresholds.
const PercentMultiplier = 100
PercentMultiplier is the standard multiplier for converting ratios to percentages.
const ZScoreMaxSentinel = 100.0
ZScoreMaxSentinel is the cap for z-score when stddev is zero but value differs from mean.
Variables ¶
This section is empty.
Functions ¶
func Distribution ¶
Distribution counts items per label as determined by classify. Returns nil for a nil slice. Returns an empty map for an empty slice.
func ExceedsThreshold ¶
ExceedsThreshold reports whether observed diverges from predicted by more than threshold (as a fraction, e.g. 0.1 = 10%). Returns false when predicted <= 0 (no meaningful baseline).
func Max ¶
Max returns the largest element in values. Returns the zero value of T for an empty slice.
func MeanStdDev ¶
MeanStdDev returns the arithmetic mean and population standard deviation. Returns (0, 0) for an empty slice.
func Min ¶
Min returns the smallest element in values. Returns the zero value of T for an empty slice.
func Percentile ¶
Percentile returns the p-th percentile of values using linear interpolation. p must be in [0, 1]. The input slice is not modified (a copy is sorted internally). Returns 0 for an empty slice.
Types ¶
type EMA ¶
type EMA struct {
// contains filtered or unexported fields
}
EMA computes an exponential moving average with a fixed smoothing factor.
func (*EMA) Initialized ¶
Initialized reports whether Update has been called at least once.