Skip to content

Commit

Permalink
BUG: fix convergence check in OMP
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelVaroquaux authored and dengemann committed Nov 29, 2013
1 parent d8ad680 commit dc8a03e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sklearn/linear_model/omp.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ def _gram_omp(Gram, Xy, n_nonzero_coefs, tol_0=None, tol=None,
lam = np.argmax(np.abs(alpha))
if lam < n_active or alpha[lam] ** 2 < min_float:
# selected same atom twice, or inner product too small
warnings.warn(premature, RuntimeWarning, stacklevel=2)
warnings.warn(premature, RuntimeWarning, stacklevel=3)
break
if n_active > 0:
L[n_active, :n_active] = Gram[lam, :n_active]
solve_triangular(L[:n_active, :n_active], L[n_active, :n_active])
v = nrm2(L[n_active, :n_active]) ** 2
if 1 - v <= min_float: # selected atoms are dependent
warnings.warn(premature, RuntimeWarning, stacklevel=2)
warnings.warn(premature, RuntimeWarning, stacklevel=3)
break
L[n_active, n_active] = np.sqrt(1 - v)
Gram[n_active], Gram[lam] = swap(Gram[n_active], Gram[lam])
Expand All @@ -225,7 +225,7 @@ def _gram_omp(Gram, Xy, n_nonzero_coefs, tol_0=None, tol=None,
tol_curr += delta
delta = np.inner(gamma, beta[:n_active])
tol_curr -= delta
if tol_curr <= tol:
if abs(tol_curr) <= tol:
break
elif n_active == max_features:
break
Expand Down

0 comments on commit dc8a03e

Please sign in to comment.