Skip to content

Commit

Permalink
Changed to safe_sqr and corrected an import bug in test_svd.
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Click <tcthepoet@yahoo.com>
  • Loading branch information
Timothy Click authored and Timothy Click committed Feb 26, 2019
1 parent 6ebe40f commit dd68aa3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/fluctmatch/decomposition/svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from scipy import linalg
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.decomposition.base import _BasePCA
from sklearn.utils import check_array
from sklearn.utils import check_array, safe_sqr
from sklearn.utils.validation import check_is_fitted
from sklearn.utils.extmath import fast_logdet, svd_flip

Expand Down Expand Up @@ -135,7 +135,7 @@ def _fit(self, X: np.ndarray):
U, Vt = svd_flip(U, Vt)

# Get variance explained by singular values
explained_variance_: np.ndarray = (S ** 2) / (n_samples - 1)
explained_variance_: np.ndarray = safe_sqr(S) / (n_samples - 1)
total_var: float = explained_variance_.sum()
explained_variance_ratio_: np.ndarray = explained_variance_ / total_var
singular_values_: np.ndarray = S.copy() # Store the singular values.
Expand Down
8 changes: 4 additions & 4 deletions tests/decomposition/test_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
# These tests were taken from the scikit-learn tests for PCA.

import numpy as np
from numpy.testing import assert_almost_equal
from numpy.testing import assert_array_almost_equal
from numpy.testing import assert_greater
from numpy.testing import assert_no_warnings
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import assert_no_warnings

from sklearn import datasets
from fluctmatch.decomposition.svd import SVD
Expand Down

0 comments on commit dd68aa3

Please sign in to comment.