pub struct FpcaResult {
pub singular_values: Vec<f64>,
pub rotation: FdMatrix,
pub scores: FdMatrix,
pub mean: Vec<f64>,
pub centered: FdMatrix,
}Expand description
Result of functional PCA.
Fields§
§singular_values: Vec<f64>Singular values
rotation: FdMatrixRotation matrix (loadings), m x ncomp
scores: FdMatrixScores matrix, n x ncomp
mean: Vec<f64>Mean function
centered: FdMatrixCentered data, n x m
Implementations§
Source§impl FpcaResult
impl FpcaResult
Sourcepub fn project(&self, data: &FdMatrix) -> Result<FdMatrix, FdarError>
pub fn project(&self, data: &FdMatrix) -> Result<FdMatrix, FdarError>
Project new functional data onto the FPC score space.
Centers the input data by subtracting the mean function estimated during FPCA, then multiplies by the rotation (loadings) matrix to obtain FPC scores for the new observations.
§Arguments
data- Matrix (n_new x m) of new observations
§Errors
Returns FdarError::InvalidDimension if the number of columns in
data does not match the length of the mean vector (i.e. the number
of evaluation points used during FPCA).
§Examples
use fdars_core::matrix::FdMatrix;
use fdars_core::regression::fdata_to_pc_1d;
let data = FdMatrix::from_column_major(
(0..50).map(|i| (i as f64 * 0.1).sin()).collect(),
5, 10,
).unwrap();
let fpca = fdata_to_pc_1d(&data, 3).unwrap();
// Project the original data (scores should match)
let scores = fpca.project(&data).unwrap();
assert_eq!(scores.shape(), (5, 3));
// Project new data
let new_data = FdMatrix::from_column_major(
(0..20).map(|i| (i as f64 * 0.2).cos()).collect(),
2, 10,
).unwrap();
let new_scores = fpca.project(&new_data).unwrap();
assert_eq!(new_scores.shape(), (2, 3));Sourcepub fn reconstruct(
&self,
scores: &FdMatrix,
ncomp: usize,
) -> Result<FdMatrix, FdarError>
pub fn reconstruct( &self, scores: &FdMatrix, ncomp: usize, ) -> Result<FdMatrix, FdarError>
Reconstruct functional data from FPC scores.
Computes the approximation of functional data using the first
ncomp principal components:
data[i, j] = mean[j] + sum_k scores[i, k] * rotation[j, k]
§Arguments
scores- Score matrix (n x p) where p >=ncompncomp- Number of components to use for reconstruction
§Errors
Returns FdarError::InvalidParameter if ncomp is zero or exceeds
the number of columns in scores or the number of available components
in the rotation matrix.
§Examples
use fdars_core::matrix::FdMatrix;
use fdars_core::regression::fdata_to_pc_1d;
let data = FdMatrix::from_column_major(
(0..100).map(|i| (i as f64 * 0.1).sin()).collect(),
10, 10,
).unwrap();
let fpca = fdata_to_pc_1d(&data, 5).unwrap();
// Reconstruct using all 5 components
let recon = fpca.reconstruct(&fpca.scores, 5).unwrap();
assert_eq!(recon.shape(), (10, 10));
// Reconstruct using fewer components
let recon2 = fpca.reconstruct(&fpca.scores, 2).unwrap();
assert_eq!(recon2.shape(), (10, 10));Trait Implementations§
Source§impl Clone for FpcaResult
impl Clone for FpcaResult
Source§fn clone(&self) -> FpcaResult
fn clone(&self) -> FpcaResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FpcaResult
impl Debug for FpcaResult
Source§impl PartialEq for FpcaResult
impl PartialEq for FpcaResult
impl StructuralPartialEq for FpcaResult
Auto Trait Implementations§
impl Freeze for FpcaResult
impl RefUnwindSafe for FpcaResult
impl Send for FpcaResult
impl Sync for FpcaResult
impl Unpin for FpcaResult
impl UnsafeUnpin for FpcaResult
impl UnwindSafe for FpcaResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.