Run inference where it has to live: inside a latency-critical Rust path, in-process and deterministic, with no Python round-trip and nothing to link. The standout is a classical hypothesis-test suite with scipy-grade p-values (exact and asymptotic modes) — the piece the Rust ecosystem otherwise lacks.
[]
= "0.1"
use ;
let z = NormalDistribution ;
assert!; // 1/sqrt(2*pi)
assert!;
assert!;
assert_eq!;
Why stats-claw
- Zero runtime dependencies. std-only. No BLAS, no LAPACK, no transitive supply chain — it compiles in seconds and drops into any Rust binary, including constrained targets.
- scipy-grade, and proven so. Every numeric is checked against committed golden fixtures generated from the reference Python libraries, within documented tolerances (down to 1e-12).
- Deterministic by construction. A hand-written
SplitMix64PRNG gives byte-identical sampling and resampling across platforms — reproducible tests, reproducible science. - The inference suite Rust was missing. Exact and asymptotic p-values for the classical tests (t, ANOVA, χ², Fisher, Mann–Whitney, Wilcoxon, Kruskal–Wallis, KS, Shapiro), with log-space tails for extreme significance.
Validated against reference libraries
| Area | Reference | Tolerance |
|---|---|---|
| Distributions (pdf/cdf/ppf/moments, log-space tails) | scipy.stats |
1e-9 – 1e-12 |
| Hypothesis tests (t/ANOVA, χ²/Fisher/McNemar, KS/Anderson/Shapiro, Mann–Whitney/Wilcoxon/Kruskal) | scipy.stats (incl. method="exact") |
≤ 1e-8 |
| Regression (OLS, ridge) | scikit-learn |
~1e-12 |
| Clustering / decomposition / change-point | scikit-learn, ruptures |
per-test |
| Association rules | mlxtend |
1e-12 |
What's in the box
Distributions — pdf/pmf, cdf, quantile, moments, log-space cdf/sf, and
seeded sampling for 14 families: normal, uniform, Cauchy, Laplace, exponential, gamma, beta,
Weibull, log-normal, chi-squared, Student's t, F, binomial, and Poisson.
Hypothesis tests — parametric (one-sample / independent / paired / Welch t-tests, ANOVA, variance), non-parametric (Mann–Whitney, Wilcoxon, Kruskal–Wallis, Friedman), categorical (χ², Fisher, McNemar, Cochran), goodness-of-fit (KS, Anderson–Darling, Shapiro–Wilk), and correlation — each returning the statistic, p-value (exact or asymptotic), degrees of freedom, and effect size where defined.
Resampling — bootstrap, jackknife, permutation, cross-validation, and percentile confidence / credible intervals, all driven by the deterministic PRNG.
Streaming — single-pass online estimators (RunningMoments via Welford, P2Quantile)
for latency-critical and unbounded-data workloads.
Also included — gradient and second-order optimizers (gradient descent, Adam, RMSProp,
AdaGrad, SGD, Newton, L-BFGS, conjugate-gradient) plus stochastic search (genetic, simulated
annealing); regression (OLS, ridge); clustering (k-means, DBSCAN, GMM, hierarchical, spectral,
mean-shift, affinity propagation); decomposition / embedding (PCA, ICA, factor analysis, t-SNE,
UMAP, LLE); and density, outlier, feature-selection, change-point (PELT), cardinality, and
association-rule utilities. These overlap mature crates like linfa
and smartcore; the inference suite above is the focus.
Usage
Distributions are plain parameter structs with Default; the behaviour lives in traits you
bring into scope (Pdf, Pmf, Cdf, Quantile, Moments, LogCdf, Sample).
Distributions
use ;
let coins = BinomialDistribution ;
assert_eq!;
assert!; // 5 heads is likelier than 3
Deterministic sampling
use ;
use SplitMix64;
let dist = NormalDistribution ;
let mut rng = new; // same seed => same stream, on every platform
let draws: = .map.collect;
assert_eq!;
Hypothesis testing
use ;
let control = ;
let treated = ;
// Returns a TestResult; `?` works in any function returning stats_claw::error::Result.
let r = t_test_ind?;
println!;
assert!; // significantly different means
assert_eq!; // n_a + n_b - 2
For ordinal or non-normal data, reach for the rank tests:
use ;
let a = ;
let b = ;
let r = mann_whitney_u?;
assert!;
assert!; // rank-biserial correlation
Bootstrap confidence intervals
use ;
use SplitMix64;
let sample = ;
let mean = ;
let boots = bootstrap_statistic?;
let = percentile_ci?; // 95% interval
assert!;
Streaming estimators
use RunningMoments;
let mut acc = new;
for x in
assert_eq!;
assert!;
assert!; // Bessel-corrected (n-1) sample variance
Regression
use ols;
let x = vec!; // one row per observation
let y = vec!; // y = 3x + 2
let model = ols?;
assert!;
assert!;
Performance
The hot paths are written for throughput: a SIMD ziggurat normal sampler (with a scalar
fallback and runtime feature detection), log-space tail evaluation to keep extreme p-values
accurate instead of underflowing to zero, and single-pass streaming estimators that hold O(1)
state. unsafe is confined to feature-gated SIMD intrinsics, each carrying a // SAFETY:
justification; everything else is safe Rust.
Compatibility
- MSRV: Rust 1.93 (edition 2024). The minimum supported version is tested in CI.
- Dependencies: none at runtime (std-only).
- Determinism: identical results across operating systems and architectures.
Status
Pre-stable (0.x): the public API is still being refined and may change before 1.0,
following semantic versioning. The validation harness and tolerances are part of the test
suite, so numeric behaviour is held stable even while names settle.
License
Dual-licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option. Contributions are accepted under the same dual license.