jjhelmus / leastsqbound-scipy

Constrained multivariate least-squares optimizer for scipy
Other
21 stars 8 forks source link

changing bounds in test_linear.py results in error #5

Closed hanshammel1337 closed 9 years ago

hanshammel1337 commented 9 years ago

if i simple change one bound from the test file from bounds = [(0.0, 2.0), (-10.0, 10.0)] to bounds = [(1.0, 2.0), (-10.0, 10.0)]

it raises warning/error listed below:

/.../Desktop/leastsqbound.py:91: RuntimeWarning: invalid value encountered in arcsin
return lambda x: arcsin((2. * (x - lower) / (upper - lower)) - 1.)
Traceback (most recent call last):
File "example_lstsq_bound.py", line 63, in <module>
bounds = bounds, full_output=True)
File "/.../Desktop/leastsqbound.py", line 360, in leastsqbound
cov_x = inv(dot(transpose(R), R))
File "/usr/local/lib/python2.7/dist-packages/scipy/linalg/basic.py", line 353, in inv
a1 = np.asarray_chkfinite(a)
File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 595, in asarray_chkfinite
 "array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

any ideas what is the problem here?

jjhelmus commented 9 years ago

I'm not able to reproduce this error on my system running Python 2.7.9, NumPy 1.9.1, and SciPy 0.15.0 but I believe the following is causing the issue:

You changed the bounds of the first parameter (1.0) to be very close to the unbounded optimized value (1.016) which results in an infinity or NaN being generated when calculating the jacobian around the solution (cov_x). The try/except block at line 359 catches a LinAlgError on my system so that cov_x is returned as None but does not catch a ValueError. SciPy's leastsq function now also catches ValueError as of 272927b. I'll update leastsqbound to catch this also.