pub fn fdata_to_pc(
data: &FdMatrix,
ncomp: usize,
argvals: &[f64],
) -> Result<FpcaResult, FdarError>Expand description
Perform functional PCA via SVD on centered data with integration weights.
Uses Simpson’s-rule weights derived from argvals so that the resulting
scores represent functional inner products and are invariant to grid
density.
§Arguments
data- Matrix (n x m): n observations, m evaluation pointsncomp- Number of components to extractargvals- Evaluation grid points (length m)
§Errors
Returns FdarError::InvalidDimension if data has zero rows or zero
columns, or if argvals.len() != m.
Returns FdarError::InvalidParameter if ncomp is zero.
Returns FdarError::ComputationFailed if the SVD decomposition fails to
produce U or V_t matrices.
§Examples
use fdars_core::matrix::FdMatrix;
use fdars_core::regression::fdata_to_pc;
// 5 curves, each evaluated at 10 points
let data = FdMatrix::from_column_major(
(0..50).map(|i| (i as f64 * 0.1).sin()).collect(),
5, 10,
).unwrap();
let argvals: Vec<f64> = (0..10).map(|i| i as f64 / 9.0).collect();
let result = fdata_to_pc(&data, 3, &argvals).unwrap();
assert_eq!(result.scores.shape(), (5, 3));
assert_eq!(result.rotation.shape(), (10, 3));
assert_eq!(result.mean.len(), 10);