Skip to content

Commit 539dfd4

Browse files
committed
format editing added local lobpcg temporarily
1 parent e73729e commit 539dfd4

4 files changed

Lines changed: 597 additions & 15 deletions

File tree

sklearn/decomposition/pca.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,17 @@ class PCA(_BasePCA):
185185
.. versionadded:: 0.18.0
186186
187187
iterated_power : int >= 0, or 'auto', (default 'auto')
188-
Number of iterations of svd_solver = 'lobpcg' or for the power method computed by
189-
svd_solver == 'randomized'.
188+
Number of iterations of svd_solver = 'lobpcg' or for the power method
189+
computed by svd_solver == 'randomized'.
190190
191191
.. versionadded:: 0.18.0
192192
193193
random_state : int, RandomState instance or None, optional (default None)
194194
If int, random_state is the seed used by the random number generator;
195195
If RandomState instance, random_state is the random number generator;
196196
If None, the random number generator is the RandomState instance used
197-
by `np.random`. Used when ``svd_solver`` == 'arpack', 'lobpcg', or 'randomized'.
197+
by `np.random` in
198+
``svd_solver`` == 'arpack', 'lobpcg', or 'randomized'.
198199
199200
.. versionadded:: 0.18.0
200201

sklearn/decomposition/truncated_svd.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from ..base import BaseEstimator, TransformerMixin
1515
from ..utils import check_array, check_random_state
16-
from ..utils.extmath import randomized_svd, lobpcg_svd, safe_sparse_dot, svd_flip
16+
from ..utils.extmath import randomized_svd, lobpcg_svd,\
17+
safe_sparse_dot, svd_flip
1718
from ..utils.sparsefuncs import mean_variance_axis
1819

1920
__all__ = ["TruncatedSVD"]
@@ -33,8 +34,8 @@ class TruncatedSVD(BaseEstimator, TransformerMixin):
3334
context, it is known as latent semantic analysis (LSA).
3435
3536
This estimator supports 3 algorithms: a fast randomized SVD solver, and
36-
a "naive" algorithm that uses ARPACK or LOBPCG as an eigensolver on (X * X.T) or
37-
(X.T * X), whichever is more efficient.
37+
a "naive" algorithm that uses ARPACK or LOBPCG as an eigensolver
38+
on the normal matrix (X * X.T) or (X.T * X), whichever is more efficient.
3839
3940
Read more in the :ref:`User Guide <LSA>`.
4041
@@ -48,11 +49,13 @@ class TruncatedSVD(BaseEstimator, TransformerMixin):
4849
4950
algorithm : string, default = "randomized"
5051
SVD solver to use. Either "arpack" for the ARPACK wrapper in SciPy
51-
(scipy.sparse.linalg.svds), or "lobpcg" for LOBPCG (scipy.sparse.linalg.lobpcg),
52-
or "randomized" for the randomized algorithm due to Halko (2009).
52+
(scipy.sparse.linalg.svds), or
53+
"lobpcg" for LOBPCG (scipy.sparse.linalg.lobpcg) Knyazev (2001), or
54+
"randomized" for the randomized algorithm due to Halko (2009).
5355
5456
n_iter : int, optional (default 5)
55-
Number of iterations for randomized or LOBPCG SVD solver. Not used by ARPACK.
57+
Number of iterations for randomized or LOBPCG SVD solver.
58+
Not used by ARPACK.
5659
The default is larger than the default in `randomized_svd` to handle
5760
sparse matrices that may have large slowly decaying spectrum.
5861

sklearn/utils/extmath.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from ..externals.six.moves import xrange
2626
from .sparsefuncs_fast import csr_row_norms
2727
from .validation import check_array
28-
from scipy.sparse.linalg import lobpcg
28+
from . import lobpcg
29+
# from scipy.sparse.linalg import lobpcg
2930

3031

3132
@deprecated("sklearn.utils.extmath.norm was deprecated in version 0.19 "
@@ -381,9 +382,9 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iter='auto',
381382

382383

383384
def lobpcg_svd(M, n_components, n_oversamples=10, n_iter='auto',
384-
transpose='auto',
385+
transpose='auto',
385386
flip_sign=True, random_state=0):
386-
"""Computes a truncated SVD using LOBPCG mimicking the randomized SVD setup
387+
"""Computes a truncated SVD using LOBPCG mimicking the randomized SVD
387388
388389
Parameters
389390
----------
@@ -475,12 +476,12 @@ def lobpcg_svd(M, n_components, n_oversamples=10, n_iter='auto',
475476
Q = Q.astype(M.dtype, copy=False)
476477

477478
A = - safe_sparse_dot(M, M.T)
478-
# 1. LOBPCG default option largest=True is currently broken, so we
479+
# 1. LOBPCG default option largest=True is currently broken, so we
479480
# go the smallest (negative) of the negative normal matrix A
480481
# 2. In contrast to randomised, lobpcg allows setting up useful
481-
# tol=lobpcg_tol but adding it below currently results in
482+
# tol=lobpcg_tol but adding it below currently results in
482483
# Docstring Error:
483-
# sklearn.cluster.spectral.discretize arg mismatch.
484+
# sklearn.cluster.spectral.discretize arg mismatch.
484485
_, Q = lobpcg(A, Q, maxiter=n_iter, largest=False)
485486

486487
# project M to the (k + p) dimensional space using the basis vectors

0 commit comments

Comments
 (0)