Skip to content

FIX: spectral_embedding.py initial eigenvector approximations for LOBPCG and AMG solvers should be randn not rand #21565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/whats_new/v1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ random sampling procedures.
same solution, up to numerical rounding errors, but in general Lloyd's
algorithm uses much less memory, and it is often faster.

- |Fix| The eigenvectors initialization for :class:`cluster.SpectralClustering`
and :class:`manifold.SpectralEmbedding` now samples from a Gaussian when
using the `'amg'` or `'lobpcg'` solver. This change improves numerical
stability of the solver, but may result in a different model.

Changelog
---------
Expand Down Expand Up @@ -240,6 +244,11 @@ Changelog
preserve this dtype.
:pr:`21534` by :user:`Andrew Knyazev <lobpcg>`.

- |Fix| :func:`manifold.spectral_embedding` now uses Gaussian instead of
the previous uniform on [0, 1] random initial approximations to eigenvectors
in eigen_solvers `lobpcg` and `amg` to improve their numerical stability.
:pr:`21565` by :user:`Andrew Knyazev <lobpcg>`.

:mod:`sklearn.model_selection`
..............................

Expand Down
4 changes: 2 additions & 2 deletions sklearn/manifold/_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def spectral_embedding(

M = ml.aspreconditioner()
# Create initial approximation X to eigenvectors
X = random_state.rand(laplacian.shape[0], n_components + 1)
X = random_state.randn(laplacian.shape[0], n_components + 1)
X[:, 0] = dd.ravel()
X = X.astype(laplacian.dtype)
_, diffusion_map = lobpcg(laplacian, X, M=M, tol=1.0e-5, largest=False)
Expand Down Expand Up @@ -367,7 +367,7 @@ def spectral_embedding(
# We increase the number of eigenvectors requested, as lobpcg
# doesn't behave well in low dimension and create initial
# approximation X to eigenvectors
X = random_state.rand(laplacian.shape[0], n_components + 1)
X = random_state.randn(laplacian.shape[0], n_components + 1)
X[:, 0] = dd.ravel()
X = X.astype(laplacian.dtype)
_, diffusion_map = lobpcg(
Expand Down