Skip to content

Commit

Permalink
optimization.py: if the hessian is noninvertable, find a least square…
Browse files Browse the repository at this point in the history
…s solution anyway
  • Loading branch information
mattloper committed Feb 17, 2015
1 parent 435772a commit ae6ca2a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions optimization.py
Expand Up @@ -262,6 +262,7 @@ def _minimize_dogleg(obj, free_variables, on_step=None,
http://www.ics.forth.gr/cvrl/publications/conferences/0201-P0401-lourakis-levenberg.pdf
"""

import warnings
if show_residuals is not None:
import warnings
warnings.warn('minimize_dogleg: show_residuals parm is deprecaed, pass a dict instead.')
Expand Down Expand Up @@ -362,8 +363,17 @@ def call_cb():
A.shape[0],
A.shape[1],
100. * J.nnz / (J.shape[0] * J.shape[1])))

d_gn = col(solve(A, g)) if g.size>1 else np.atleast_1d(g.ravel()[0]/A[0,0])

if g.size > 1:
with warnings.catch_warnings():
warnings.filterwarnings('error')
try:
d_gn = col(solve(A, g))
except:
from scipy.sparse.linalg import lsqr
d_gn = col(lsqr(A, g)[0])
else:
d_gn = np.atleast_1d(g.ravel()[0]/A[0,0])
pif('sparse solve...done in %.2fs' % (time.time() - tm))
else:
pif('dense solve...')
Expand Down

0 comments on commit ae6ca2a

Please sign in to comment.