Skip to main content

fdars_core/
lib.rs

1//! # fdars-core
2//!
3//! Core algorithms for Functional Data Analysis in Rust.
4//!
5//! This crate provides pure Rust implementations of various FDA methods including:
6//! - Functional data operations (mean, derivatives, norms)
7//! - Depth measures (Fraiman-Muniz, modal, band, random projection, etc.)
8//! - Distance metrics (Lp, Hausdorff, DTW, Fourier, etc.)
9//! - Basis representations (B-splines, P-splines, Fourier)
10//! - Clustering (k-means, fuzzy c-means)
11//! - Smoothing (Nadaraya-Watson, local linear/polynomial regression)
12//! - Outlier detection
13//! - Regression (PCA, PLS, ridge)
14//! - Seasonal analysis (period estimation, peak detection, seasonal strength)
15//! - Detrending and decomposition for non-stationary data
16//!
17//! ## Data Layout
18//!
19//! Functional data is represented using the [`FdMatrix`] type, a column-major matrix
20//! wrapping a flat `Vec<f64>` with safe `(i, j)` indexing and dimension tracking:
21//! - For n observations with m evaluation points: `data[(i, j)]` gives observation i at point j
22//! - 2D surfaces (n observations, m1 x m2 grid): stored as n x (m1*m2) matrices
23//! - Zero-copy column access via `data.column(j)`, row gather via `data.row(i)`
24//! - nalgebra interop via `to_dmatrix()` / `from_dmatrix()` for SVD operations
25
26#![allow(clippy::needless_range_loop)]
27#![allow(clippy::too_many_arguments)]
28#![allow(clippy::type_complexity)]
29
30pub mod matrix;
31pub mod parallel;
32
33pub mod alignment;
34pub mod basis;
35pub mod classification;
36pub mod clustering;
37pub mod depth;
38pub mod detrend;
39pub mod famm;
40pub mod fdata;
41pub mod function_on_scalar;
42pub mod gmm;
43pub mod helpers;
44pub mod irreg_fdata;
45pub mod landmark;
46pub mod metric;
47pub mod outliers;
48pub mod regression;
49pub mod scalar_on_function;
50pub mod seasonal;
51pub mod simulation;
52pub mod smoothing;
53pub mod streaming_depth;
54pub mod tolerance;
55pub mod utility;
56pub mod warping;
57
58// Re-export matrix types
59pub use matrix::{FdCurveSet, FdMatrix};
60
61// Re-export alignment types and functions
62pub use alignment::{
63    align_to_target, alignment_quality, amplitude_distance, amplitude_self_distance_matrix,
64    compose_warps, elastic_align_pair, elastic_align_pair_constrained, elastic_align_pair_nd,
65    elastic_align_pair_with_landmarks, elastic_cross_distance_matrix, elastic_decomposition,
66    elastic_distance, elastic_distance_nd, elastic_self_distance_matrix, karcher_mean,
67    pairwise_consistency, phase_distance_pair, phase_self_distance_matrix, reparameterize_curve,
68    srsf_inverse, srsf_inverse_nd, srsf_transform, srsf_transform_nd, tsrvf_from_alignment,
69    tsrvf_from_alignment_with_method, tsrvf_inverse, tsrvf_transform, tsrvf_transform_with_method,
70    warp_complexity, warp_smoothness, AlignmentQuality, AlignmentResult, AlignmentResultNd,
71    AlignmentSetResult, ConstrainedAlignmentResult, DecompositionResult, KarcherMeanResult,
72    TransportMethod, TsrvfResult,
73};
74
75// Re-export commonly used items
76pub use helpers::{
77    cumulative_trapz, extract_curves, gradient_uniform, l2_distance, linear_interp,
78    simpsons_weights, simpsons_weights_2d, trapz, DEFAULT_CONVERGENCE_TOL, NUMERICAL_EPS,
79};
80
81// Re-export warping utilities
82pub use warping::{
83    exp_map_sphere, gam_to_psi, gam_to_psi_smooth, inner_product_l2, inv_exp_map_sphere,
84    invert_gamma, l2_norm_l2, normalize_warp, phase_distance, psi_to_gam,
85};
86
87// Re-export seasonal analysis types
88pub use seasonal::{
89    autoperiod, autoperiod_fdata, cfd_autoperiod, cfd_autoperiod_fdata, hilbert_transform, sazed,
90    sazed_fdata, AutoperiodCandidate, AutoperiodResult, CfdAutoperiodResult, ChangeDetectionResult,
91    ChangePoint, ChangeType, DetectedPeriod, InstantaneousPeriod, Peak, PeakDetectionResult,
92    PeriodEstimate, SazedComponents, SazedResult, StrengthMethod,
93};
94
95// Re-export landmark registration types
96pub use landmark::{
97    detect_and_register, detect_landmarks, landmark_register, Landmark, LandmarkKind,
98    LandmarkResult,
99};
100
101// Re-export detrending types
102pub use detrend::{DecomposeResult, TrendResult};
103
104// Re-export simulation types
105pub use simulation::{EFunType, EValType};
106
107// Re-export irregular fdata types
108pub use irreg_fdata::{IrregFdata, KernelType};
109
110// Re-export tolerance band types
111pub use tolerance::{
112    conformal_prediction_band, elastic_tolerance_band, equivalence_test,
113    equivalence_test_one_sample, exponential_family_tolerance_band, fpca_tolerance_band,
114    scb_mean_degras, BandType, EquivalenceBootstrap, EquivalenceTestResult, ExponentialFamily,
115    MultiplierDistribution, NonConformityScore, ToleranceBand,
116};
117
118// Re-export FAMM types
119pub use famm::{fmm, fmm_predict, fmm_test_fixed, FmmResult, FmmTestResult};
120
121// Re-export function-on-scalar regression types
122pub use function_on_scalar::{
123    fanova, fosr, fosr_fpc, predict_fosr, FanovaResult, FosrFpcResult, FosrResult,
124};
125
126// Re-export scalar-on-function regression types
127pub use scalar_on_function::{
128    fregre_cv, fregre_lm, fregre_np_mixed, functional_logistic, predict_fregre_lm,
129    predict_fregre_np, FregreCvResult, FregreLmResult, FregreNpResult, FunctionalLogisticResult,
130};
131
132// Re-export classification types
133pub use classification::{
134    fclassif_cv, fclassif_dd, fclassif_kernel, fclassif_knn, fclassif_lda, fclassif_qda,
135    ClassifCvResult, ClassifResult,
136};
137
138// Re-export GMM clustering types
139pub use gmm::{gmm_cluster, gmm_em, predict_gmm, CovType, GmmClusterResult, GmmResult};
140
141// Re-export streaming depth types
142pub use streaming_depth::{
143    FullReferenceState, RollingReference, SortedReferenceState, StreamingBd, StreamingDepth,
144    StreamingFraimanMuniz, StreamingMbd,
145};