Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

BUG: nonlinear solvers are not confused by lucky guess #3390

Merged
merged 1 commit into from

5 participants

@argriffing
Collaborator

closes #3227

@coveralls

Coverage Status

Coverage remained the same when pulling e48effc on argriffing:broyden-lucky-guess into 77a7e48 on scipy:master.

@ev-br
Collaborator

with Travis-CI being happy, I'll hit the green button. Thanks!

@ev-br ev-br merged commit 0523f0e into scipy:master
@pv pv added this to the 0.14.0 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 4 deletions.
  1. +7 −2 scipy/optimize/nonlin.py
  2. +8 −2 scipy/optimize/tests/test_nonlin.py
View
9 scipy/optimize/nonlin.py
@@ -668,8 +668,13 @@ def setup(self, x0, f0, func):
self.last_x = x0
if hasattr(self, 'alpha') and self.alpha is None:
- # autoscale the initial Jacobian parameter
- self.alpha = 0.5*max(norm(x0), 1) / norm(f0)
+ # Autoscale the initial Jacobian parameter
+ # unless we have already guessed the solution.
+ normf0 = norm(f0)
+ if normf0:
+ self.alpha = 0.5*max(norm(x0), 1) / normf0
+ else:
+ self.alpha = 1.0
def _update(self, x, f, dx, df, dx_norm, df_norm):
raise NotImplementedError
View
10 scipy/optimize/tests/test_nonlin.py
@@ -42,6 +42,11 @@ def F2(x):
F2.KNOWN_BAD = {'linearmixing': nonlin.linearmixing,
'excitingmixing': nonlin.excitingmixing}
+def F2_lucky(x):
+ return x
+F2_lucky.xin = [0,0,0,0,0,0]
+F2_lucky.KNOWN_BAD = {}
+
def F3(x):
A = np.mat('-2 1 0; 1 -2 1; 0 1 -2')
@@ -80,6 +85,7 @@ def F6(x):
'linearmixing': nonlin.linearmixing,
'diagbroyden': nonlin.diagbroyden}
+
#-------------------------------------------------------------------------------
# Tests
#-------------------------------------------------------------------------------
@@ -109,7 +115,7 @@ def _check_func_fail(self, *a, **kw):
def test_problem_nonlin(self):
""" Tests for nonlin functions """
- for f in [F, F2, F3, F4_powell, F5, F6]:
+ for f in [F, F2, F2_lucky, F3, F4_powell, F5, F6]:
for func in SOLVERS.values():
if func in f.KNOWN_BAD.values():
if func in MUST_WORK.values():
@@ -119,7 +125,7 @@ def test_problem_nonlin(self):
def test_problem_root(self):
""" Tests for root """
- for f in [F, F2, F3, F4_powell, F5, F6]:
+ for f in [F, F2, F2_lucky, F3, F4_powell, F5, F6]:
for meth in SOLVERS:
if meth in f.KNOWN_BAD:
if meth in MUST_WORK:
Something went wrong with that request. Please try again.