Skip to main content

Module jfpca_model

Module jfpca_model 

Source
Expand description

Public fit→transform seam for joint functional PCA (jfPCA).

This module exposes a reusable JfpcaModel trained by jfpca_fit that can project out-of-sample curves onto the trained joint-FPCA basis in the trained coordinate system via JfpcaModel::transform.

§Overview

Joint FPCA (Tucker et al.) decomposes functional curves into amplitude (vertical) and phase (horizontal) variability after elastic alignment. This module wraps the existing joint_fpca machinery into a persistent model that stores all state needed for out-of-sample projection.

§Round-trip precision note

model.transform(&training_curves) re-aligns each curve independently to the stored Karcher-mean template via align_to_target. The Karcher-mean algorithm post-centers its stored gammas (via sqrt_mean_inverse), so the re-alignment gammas are not bit-identical to the training-time gammas. The training-time gammas and aligned data are stored in JfpcaModel::training_gammas / JfpcaModel::training_aligned; downstream consumers that need exact training-set reproducibility should use those fields. The scoring formula is verified at < 1e-8 using the stored training alignment; the re-alignment round-trip tolerance is bounded by the Karcher convergence tolerance.

§Example

use fdars_core::{jfpca_fit, JfpcaModel, JfpcaTransform};
use fdars_core::matrix::FdMatrix;
use std::f64::consts::PI;

// Build a small spanning multi-frequency FdMatrix (n=6, m=12)
let n = 6;
let m = 12;
let argvals: Vec<f64> = (0..m).map(|i| i as f64 / (m - 1) as f64).collect();
let mut data = FdMatrix::zeros(n, m);
for i in 0..n {
    for j in 0..m {
        let t = argvals[j];
        let amp1 = 1.0 + 0.3 * i as f64;
        let amp2 = 0.5 - 0.1 * i as f64;
        let amp3 = 0.3 + 0.05 * i as f64;
        data[(i, j)] = amp1 * (2.0 * PI * t).sin()
            + amp2 * (4.0 * PI * t).cos()
            + amp3 * (6.0 * PI * t).sin();
    }
}

let ncomp = 3;
let model = jfpca_fit(&data, &argvals, ncomp, None, 0.0, 20)?;
let transform = model.transform(&data)?;
assert_eq!(transform.scores.shape(), (n, model.ncomp));

Structs§

JfpcaModel
Trained joint-FPCA model that stores the full basis for out-of-sample projection.
JfpcaTransform
Output of JfpcaModel::transform — projections of new curves onto the trained joint-FPCA basis.
PrincipalDirections
Principal-direction curves at μ ± c·σⱼ for a chosen jfPCA component (VEE-04).

Functions§

jfpca_fit
Fit a joint-FPCA model on a set of functional curves.