Skip to content

Commit

Permalink
feat: inverse pca implement (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
tc-mateus authored Jul 3, 2024
1 parent 80a973b commit b807674
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions algorithms/linfa-reduction/src/pca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ impl Pca<f64> {
pub fn singular_values(&self) -> &Array1<f64> {
&self.sigma
}

/// Transform data back to its original space
pub fn inverse_transform(
&self,
prediction: ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 2]>>,
) -> ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 2]>> {
prediction.dot(&self.embedding) + &self.mean
}
}

impl<F: Float, D: Data<Elem = F>> PredictInplace<ArrayBase<D, Ix2>, Array2<F>> for Pca<F> {
Expand Down

0 comments on commit b807674

Please sign in to comment.