Skip to content

Commit

Permalink
Ensure determinism of SVD output in dict_learning
Browse files Browse the repository at this point in the history
  • Loading branch information
brcharron committed Sep 20, 2020
1 parent 8b68ea1 commit 759593e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sklearn/decomposition/_dict_learning.py
Expand Up @@ -17,7 +17,7 @@
from ..utils import deprecated
from ..utils import (check_array, check_random_state, gen_even_slices,
gen_batches)
from ..utils.extmath import randomized_svd, row_norms
from ..utils.extmath import randomized_svd, row_norms, svd_flip
from ..utils.validation import check_is_fitted, _deprecate_positional_args
from ..linear_model import Lasso, orthogonal_mp_gram, LassoLars, Lars

Expand Down Expand Up @@ -563,6 +563,7 @@ def dict_learning(X, n_components, *, alpha, max_iter=100, tol=1e-8,
dictionary = dict_init
else:
code, S, dictionary = linalg.svd(X, full_matrices=False)
code, dictionary = svd_flip(code, dictionary)
dictionary = S[:, np.newaxis] * dictionary
r = len(dictionary)
if n_components <= r: # True even if n_components=None
Expand Down

0 comments on commit 759593e

Please sign in to comment.