Functional Data Analysis (FDA)
High-performance Functional Data Analysis tools implemented in Rust, with Python and R bindings.
Packages
| Package | Language | Registry | Folder | Status |
|---|---|---|---|---|
| fdars-core | Rust | crates.io | fdars-core/ |
|
| pyfda | Python | GitHub | sipemu/pyfda | Python bindings |
| fdars | R | CRAN | sipemu/fdars-r |
Features
| Area | Capabilities |
|---|---|
| Core | Simulation (KL expansion, GP with 8 kernels), functional operations, smoothing (NW, local polynomial, k-NN), spline interpolation, basis representations (B-spline, Fourier, P-spline) |
| Descriptive | 8 depth measures + streaming online depth, functional summary statistics (variance, std, covariance, depth-based median, trimmed mean), 12 distance metrics (Lp, DTW, elastic, semimetrics, KL), LRT outlier detection |
| Regression | Scalar-on-function (FPC, kernel, logistic, robust), function-on-scalar (FOSR, 2D FOSR, FANOVA), FPCA, PLS, ridge, mixed effects; wavelet-domain regressors (wcr: PCR/PLS in wavelet space, wnet: elastic-net) |
| Classification | LDA, QDA, k-NN, kernel, DD-classifier, conformal prediction sets; k-means, fuzzy c-means, GMM |
| Elastic Alignment | SRSF/DP alignment, Karcher mean (1-D/N-D), TSRVF, Bayesian (pCN MCMC), closed curves, transfer alignment, partial matching, multi-resolution, generative models, geodesics, FPNS, lambda CV, peak persistence |
| Elastic Robust | Karcher median, trimmed mean, SRVF outlier detection, elastic depth, shape CIs, diagnostics, warp statistics, phase box plots, shape analysis |
| Elastic Models | Elastic FPCA (vertical/horizontal/joint), jfPCA fit/transform seam (jfpca_fit/JfpcaModel/.transform()), elastic regression, PCR, logistic, scalar-on-shape (ScoSh), changepoint detection, elastic clustering |
| SPM | T²/SPE Phase I/II, EWMA, MEWMA, CUSUM, adaptive EWMA, FRCC, profile monitoring; bootstrap/KDE limits, ARL, partial-domain, elastic SPM, iterative Phase I, Western Electric/Nelson rules |
| Explainability | PDP/ICE, SHAP, ALE, LIME, Sobol, Friedman H, anchors, counterfactuals, prototype/criticism; influence diagnostics, VIF, calibration (ECE, Brier), saliency maps; FpcPredictor trait; VEESA: model-agnostic permutation feature importance (elastic_pfi), principal-direction reconstruction (JfpcaModel::principal_directions), end-to-end veesa_pipeline |
| Inference | Tolerance bands (FPCA, conformal, Degras, exponential, elastic), conformal prediction (split, Jackknife+, CV+), equivalence testing (TOST); inductive elastic conformal anomaly detection (elastic_conformal_anomaly, amplitude/phase/combined NonConformityScore) |
| Time Series | Seasonal detection (FFT, ACF, Autoperiod, SAZED, Lomb-Scargle, SSA, matrix profile), detrending (polynomial, LOESS, STL); wavelet DWT (Haar + Daubechies db2–db10, multi-level Mallat pyramid via decompose/reconstruct) |
| Specialized | Streaming depth (online O(log N)), irregular data (CSR, kernel estimation) |
| Autodiff | Forward-mode differentiable core (Scalar trait + Dual<T> number); soft_dtw_distance_generic and FPCA score projection are differentiable via Dual<f64>; multi-input grad/jacobian API; gradient verified against closed-form and central finite differences |
Installation
Rust (fdars-core)
[dependencies]
fdars-core = "0.47"
Or install from the repository:
[dependencies]
fdars-core = { git = "https://github.com/sipemu/fdars" }
Python (pyfda)
Python bindings are available via sipemu/pyfda:
pip install git+https://github.com/sipemu/pyfda
R (fdars)
⚠️ Note: The R package currently lags behind the Rust core and is outdated at the moment. For the latest capabilities, use
fdars-core(Rust) orpyfda(Python).
install.packages("fdars")
# Development version from GitHub (requires Rust toolchain)
devtools::install_github("sipemu/fdars-r")
Feature Flags
parallel(default): Enable rayon-based parallel processinglinalg: Enable linear algebra features (faer, ridge regression) — requires Rust 1.84+serde: AddSerialize/Deserializeto core types and enable JSON supportjs: Enable WASM support with JS random number generation
For WASM builds, disable default features:
[dependencies]
fdars-core = { version = "0.47", default-features = false }
Data Layout
Functional data is represented using the FdMatrix type, a column-major matrix wrapping a flat Vec<f64> with safe (i, j) indexing and dimension tracking:
- For n observations with m evaluation points:
data[(i, j)]gives observation i at point j - Zero-copy column access via
data.column(j), row gather viadata.row(i) - nalgebra interop via
to_dmatrix()/from_dmatrix()for SVD operations - 2D surfaces (n observations, m1 x m2 grid): stored as n x (m1*m2) matrices
Quick Start
use fdars_core::{FdMatrix, fdata, depth};
// Create sample functional data (3 observations, 10 points each)
let n = 3;
let m = 10;
let data: Vec<f64> = (0..(n * m)).map(|i| (i as f64).sin()).collect();
let mat = FdMatrix::from_column_major(data, n, m).unwrap();
let argvals: Vec<f64> = (0..m).map(|i| i as f64 / (m - 1) as f64).collect();
// Compute mean function
let mean = fdata::mean_1d(&mat);
// Compute Fraiman-Muniz depth
let depths = depth::fraiman_muniz_1d(&mat, &mat, true);
Examples
28 runnable examples in fdars-core/examples/:
| # | Example | Topics |
|---|---|---|
| 01 | Simulation | KL expansion, GP generation |
| 02 | Functional Operations | Mean, derivatives, norms |
| 03 | Smoothing | NW, local polynomial, k-NN |
| 04 | Basis Representation | B-splines, Fourier, P-splines |
| 05 | Depth Measures | 8 depth measures, outlier ranking |
| 06 | Distances | Lp, DTW, elastic, semimetrics |
| 07 | Clustering | K-means, fuzzy c-means |
| 08 | Regression | FPCA, PLS |
| 09 | Outlier Detection | LRT bootstrap |
| 10 | Seasonal Analysis | FFT, Autoperiod, SAZED |
| 11 | Detrending | Polynomial, LOESS, STL |
| 12 | Streaming Depth | Online depth |
| 13 | Irregular Data | CSR storage, kernel estimation |
| 14 | Complete Pipeline | End-to-end workflow |
| 15 | Tolerance Bands | FPCA, conformal, Degras SCB |
| 16 | Elastic Alignment | SRSF, DP, Karcher mean |
| 17 | Equivalence Test | Functional TOST |
| 18 | Landmark Registration | Constrained alignment |
| 19 | TSRVF | Transported SRVF |
| 20 | Scalar-on-Function * |
FPC linear, logistic, kernel |
| 21 | Function-on-Scalar * |
FOSR, FANOVA |
| 22 | GMM Clustering * |
GMM-EM, BIC/ICL |
| 23 | Classification * |
LDA, QDA, k-NN, DD |
| 24 | Mixed Effects * |
FAMM, REML |
| 25 | Explainability * |
SHAP, ALE, PDP, anchors |
| 26 | Elastic Analysis * |
Elastic FPCA, regression, PCR |
| 27 | SPM | Phase I/II, EWMA, CUSUM, rules |
| 28 | Berkeley Growth | Growth-curve case study: P-spline smoothing, GCV/AIC/BIC selection, 10-fold CV, PLS |
* requires --features linalg
Run with cargo run -p fdars-core --example <name> (add --features linalg where marked).
Performance
A single-threaded head-to-head of fdars-core against scikit-fda 0.10.1 and the R FDA ecosystem, on identical seeded inputs, at the largest grid cell (N=500, M=200):
Generated by benchmarks/render_report.py from comparison.csv — do not edit by hand.
| Op | N | M | fdars (ms) | scikit-fda (ms) | R (ms) | fdars vs scikit-fda | fdars vs R |
|---|---|---|---|---|---|---|---|
| fpca | 500 | 200 | 10.152 | 12.357 | 41.017 | 1.22× faster | 4.04× faster |
| basis_smoothing | 500 | 200 | 0.834 | 4.199 | 4.324 | 5.04× faster | 5.19× faster |
| depth | 500 | 200 | 3.511 | 15.591 | 8.855 | 4.44× faster | 2.52× faster |
| functional_boxplot | 500 | 200 | 3.617 | 16.616 | 21.627 | 4.59× faster | 5.98× faster |
| fpcr | 500 | 200 | 10.241 | 12.636 | 1049.904 | 1.23× faster | 102.52× faster |
| elastic | 500 | 200 | 27.470 | 33.542 | 32.517 | 1.22× faster | 1.18× faster |
† fdars measurement failed the noise gate (RSD >= 5% or CI-width >= 5%) — not headlined as significant.
fdars leads scikit-fda and R on every op that passed the noise gate at this cell — none were comparable or slower. The one committed optimization win, face_covariance, is headlined at a pinned, noise-clean 1.19× faster (not the larger but unpinned/noisy 3.45× figure from an earlier phase); elastic alignment and the SVD path were already near-optimal and are reported as such, not as speedups.
See the full performance report for the complete N×M grid, before/after tables, scaling analysis, full methodology, and step-by-step reproduction instructions.
With the parallel feature (enabled by default), computationally intensive operations use rayon for multi-core performance. The library also supports WASM targets with sequential execution.
Documentation
- Rust Crate: https://docs.rs/fdars-core
- Python Package: https://github.com/sipemu/pyfda
- R Package: https://sipemu.github.io/fdars/ (⚠️ outdated — lags the Rust core)
Guides (documentation/)
- Getting Started — install, first program, running the examples
- Architecture —
FdMatrixlayout, module map, error model, parallelism - Configuration — Cargo feature flags, MSRV, build targets
- Development — conventions, adding modules, local gates, CI
- Testing — test layout, run commands, benchmarks, coverage
- Performance — head-to-head vs scikit-fda and R, before/after optimization, N×M scaling, reproduction steps
License
MIT