GitHub
deepbox/stats

Descriptive Statistics

Compute summary statistics from tensor data. All functions accept Tensor inputs and support axis-wise reduction.
mean
mean(t: Tensor, axis?: AxisLike, keepdims?: boolean): Tensor

Arithmetic mean: μ = (1/n) Σᵢ xᵢ. Supports axis-wise reduction with optional dimension preservation.

median
median(t: Tensor, axis?: AxisLike, keepdims?: boolean): Tensor

Middle value when data is sorted. For even-sized arrays, returns the average of the two middle values. More robust to outliers than mean.

mode
mode(t: Tensor, axis?: AxisLike): Tensor

Most frequently occurring value. For multiple modes, returns the smallest.

std
std(t: Tensor, axis?: AxisLike, keepdims?: boolean, ddof?: number): Tensor

Standard deviation: σ = √(Var(x)). Measures the spread of values around the mean. ddof=0 for population, ddof=1 for sample.

variance
variance(t: Tensor, axis?: AxisLike, keepdims?: boolean, ddof?: number): Tensor

Variance: σ² = (1/n) Σᵢ (xᵢ − μ)². Square of the standard deviation.

skewness
skewness(t: Tensor, axis?: AxisLike, bias?: boolean): Tensor

Third standardized moment. Measures asymmetry. Positive = right-skewed, negative = left-skewed, 0 = symmetric.

kurtosis
kurtosis(t: Tensor, axis?: AxisLike, fisher?: boolean, bias?: boolean): Tensor

Fourth standardized moment (excess kurtosis by default). Measures tail heaviness. >0 = heavy tails, <0 = light tails, 0 = normal-like.

percentile
percentile(t: Tensor, q: number | number[], axis?: AxisLike): Tensor

Value below which q% of data falls. q must be in [0, 100]. percentile(t, 50) equals the median.

quantile
quantile(t: Tensor, q: number | number[], axis?: AxisLike): Tensor

Same as percentile but q is in [0, 1]. quantile(t, 0.5) equals the median.

moment
moment(t: Tensor, n: number, axis?: AxisLike): Tensor

Compute the nth central moment about the mean. moment(t, 2) is the variance, moment(t, 3) relates to skewness.

geometricMean
geometricMean(t: Tensor, axis?: AxisLike): Tensor

Geometric mean: (∏ xᵢ)^(1/n). Appropriate for data that is multiplied together or grows exponentially. All values must be positive.

harmonicMean
harmonicMean(t: Tensor, axis?: AxisLike): Tensor

Harmonic mean: n / Σ(1/xᵢ). Appropriate for rates and ratios. All values must be positive. Always ≤ geometric mean ≤ arithmetic mean.

trimMean
trimMean(t: Tensor, proportiontocut: number, axis?: AxisLike): Tensor

Trimmed mean: compute the mean after removing a fraction of the smallest and largest values. proportiontocut in [0, 0.5). Robust to outliers.

descriptive.ts
import { mean, median, std, variance, skewness, kurtosis, percentile, geometricMean, trimMean } from "deepbox/stats";import { tensor } from "deepbox/ndarray";const data = tensor([2, 4, 4, 4, 5, 5, 7, 9]);mean(data);               // 5.0median(data);             // 4.5std(data);                // population stdstd(data, undefined, false, 1); // sample std (ddof=1)variance(data);           // population varianceskewness(data);           // asymmetry measurekurtosis(data);           // excess kurtosispercentile(data, 75);     // 75th percentile// Robust statisticsgeometricMean(data);      // geometric meantrimMean(data, 0.1);      // trim 10% from each end