Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
8 changes: 7 additions & 1 deletion doc/whats_new/v1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Fixed models
between sparse and dense input. :pr:`21195`
by :user:`Jérémie du Boisberranger <jeremiedbb>`.

:mod:`sklearn.linear_model`
...........................

- |Fix| Improves stability of :class:`linear_model.LassoLars` for different
versions of openblas. :pr:`21340` by `Thomas Fan`_.

:mod:`sklearn.neighbors`
........................

Expand Down Expand Up @@ -677,7 +683,7 @@ Changelog
Dupre la Tour`_.

- |Fix| Decrease the numerical default tolerance in the lobpcg call
in :func:`manifold.spectral_embedding` to prevent numerical instability.
in :func:`manifold.spectral_embedding` to prevent numerical instability.
:pr:`21194` by :user:`Andrew Knyazev <lobpcg>`.

:mod:`sklearn.metrics`
Expand Down
5 changes: 5 additions & 0 deletions sklearn/linear_model/_least_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def _lars_path_solver(
sys.stdout.flush()

tiny32 = np.finfo(np.float32).tiny # to avoid division by 0 warning
cov_precision = np.finfo(Cov.dtype).precision
equality_tolerance = np.finfo(np.float32).eps

if Gram is not None:
Expand Down Expand Up @@ -726,6 +727,10 @@ def _lars_path_solver(
# orthogonal (QR) decomposition of X
corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares)

# Explicit rounding can be necessary to avoid `np.argmax(Cov)` yielding
# unstable results because of rounding errors.
np.around(corr_eq_dir, decimals=cov_precision, out=corr_eq_dir)
Copy link
Member Author

@thomasjpfan thomasjpfan Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels more like symmetry breaking. Without this fix and on openblas 0.3.18, Cov gets updated to:

Cov = [2.3809523809523814, 2.3809523809523814] 

When g1 is computed (with min_pos), it returns FLT_MAX because C - Cov is zero.

On openblas 0.3.17, Cov is:

Cov = [2.380952380952385, 2.3809523809523814]

which is not symmetric, leading to a non FLT_MAX value for g1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this what @lesteve and @glemaitre discovered just before leaving for the WE ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was the case. Then, the wrong dimension will be picked and everything goes sideways.


g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32))
if positive:
gamma_ = min(g1, C / AA)
Expand Down