Skip to main content

project_scores_generic

Function project_scores_generic 

Source
pub fn project_scores_generic<S: Scalar>(
    curve: &[S],
    mean: &[f64],
    rotation: &FdMatrix,
    weights: &[f64],
    ncomp: usize,
) -> Vec<S>
Expand description

Project a single generic curve onto trained FPCA loadings, returning scores.

Differentiable, generic-over-Scalar companion to FpcaResult::project. mean, rotation (m × ncomp, column-major), and weights come from a trained FpcaResult and stay f64; only curve is generic. Instantiated at f64 it reproduces the project scores; at Dual it yields exact forward-mode gradients.

The projection is linear in the curve values: score_k = sum_j (curve[j] - mean[j]) * rotation[(j,k)] * weights[j], so the gradient is the constant d(score_k)/d(curve[j]) = rotation[(j,k)] * weights[j]. The rotation[(j,k)] * weights[j] product is folded into a single f64 before lifting via S::from_f64, so the analytic gradient is exactly that f64 constant.