pub fn select_ncomp(
eigenvalues: &[f64],
method: &NcompMethod,
) -> Result<usize, FdarError>Expand description
Select the number of principal components from an eigenvalue spectrum.
§Arguments
eigenvalues- Eigenvalues in decreasing order (e.g. from FPCA)method- Selection method
§Example
use fdars_core::spm::ncomp::{select_ncomp, NcompMethod};
let eigenvalues = vec![10.0, 5.0, 1.0, 0.1, 0.01];
let k = select_ncomp(&eigenvalues, &NcompMethod::CumulativeVariance(0.95)).unwrap();
assert!(k >= 2 && k <= 4);
let k_fixed = select_ncomp(&eigenvalues, &NcompMethod::Fixed(3)).unwrap();
assert_eq!(k_fixed, 3);§Errors
Returns FdarError::InvalidDimension if eigenvalues is empty.
Returns FdarError::InvalidParameter if any eigenvalue is NaN or
negative, or if CumulativeVariance threshold is not in (0, 1].