Skip to content

Commit b807674

Browse files
authored
feat: inverse pca implement (#312)
1 parent 80a973b commit b807674

File tree

1 file changed

+8
-0
lines changed
  • algorithms/linfa-reduction/src

1 file changed

+8
-0
lines changed

algorithms/linfa-reduction/src/pca.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ impl Pca<f64> {
190190
pub fn singular_values(&self) -> &Array1<f64> {
191191
&self.sigma
192192
}
193+
194+
/// Transform data back to its original space
195+
pub fn inverse_transform(
196+
&self,
197+
prediction: ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 2]>>,
198+
) -> ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 2]>> {
199+
prediction.dot(&self.embedding) + &self.mean
200+
}
193201
}
194202

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

0 commit comments

Comments
 (0)