Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds can cause fitting to fail #18

Closed
tBuLi opened this issue Feb 14, 2015 · 5 comments
Closed

Bounds can cause fitting to fail #18

tBuLi opened this issue Feb 14, 2015 · 5 comments
Labels

Comments

@tBuLi
Copy link
Owner

tBuLi commented Feb 14, 2015

In some cases, supplying symfit with bounds to parameters makes the fitting converge to a non-solution, whereas without it finds the solution just fine. Since all bounds are handled by leastsqbound I think the bug is in that program.

It would therefore be prudent to reintroduce the Minimize facilities and use them to handle all fitting.

@tBuLi tBuLi added the bug label Feb 14, 2015
@tBuLi
Copy link
Owner Author

tBuLi commented Mar 22, 2015

As an update, Minimize has now been reintroduced, wrapping scipy.optimize.minimize. This can now be used to take over fitting in the near feature, although the option for MINPACK should still be there given it's popularity. Potentially use MINPACK when no bounds are given, and Minimize when there are.

@pckroon
Copy link
Collaborator

pckroon commented Dec 7, 2016

Referencing #67, #86, #75.

@Jhsmit
Copy link
Collaborator

Jhsmit commented Mar 24, 2017

I'm setting up my model in the following way (python 2.7):

a1 = Parameter(name='a1', value=200, min=0, max=1000)
a2 = Parameter(name='a2', value=300, min=0, max=2000)
a3 = Parameter(name='a3', value=400, min=0, max=2000)

b = Parameter(name='b', value=200, min=0, max=500)

t1 = Parameter(name='t1', value=0.0001, min=0)
t2 = Parameter(name='t2', value=0.07, min=0)
t3 = Parameter(name='t3', value=1., min=0)

t = Variable(name='t')

model = a1*exp(-t/t1) + a2*exp(-t/t2) + a3*exp(-t/t3) + b

This gives some warnings:

C:\Python27\lib\site-packages\symfit\core\fit.py:45: RuntimeWarning: invalid value encountered in sqrt
  stdevs = np.sqrt(np.diagonal(pcov))

I didnt get the warning in symfit 0.2.5, i do in 0.3.5. The warning goes away when adding upper bounds to the tx parameters. Is it no longer allowed to specify only left bound?

@tBuLi
Copy link
Owner Author

tBuLi commented Mar 27, 2017

Could you try to run your fitting with the NumericalLeastSquares and ConstrainedNumericalLeastSquares objects directly? My prediction: you have this problem only with the latter, which is used by Fit by default for bounded problems since 0.3.5.

If true, could you explicitely set your upper bound to None for ConstrainedNumericalLeastSquares ?

t1 = Parameter(name='t1', value=0.0001, min=0, max=None)

I guess there might be a difference in syntax between the two wrapped scipy methods.

@Jhsmit
Copy link
Collaborator

Jhsmit commented Mar 28, 2017

Your prediction is correcct, when I use NumericalLeastSquares directly I don't get warnings or error message in the fit result report. I do get a warning when I sueConstraintNumericalLeastSquares;

C:\Python27\lib\site-packages\scipy\optimize\slsqp.py:338: RuntimeWarning: invalid value encountered in greater
  bnderr = where(bnds[:, 0] > bnds[:, 1])[0]

Fitting error: Fitting status message: Inequality constraints incompatible. This is a different error than I originally reported. I might have changed something, cant find what it is. Setting max=None doenst fix anything.

When I configure the parameters in the following way:

a1 = Parameter(name='a1', value=200, min=0, max=1000)
a2 = Parameter(name='a2', value=300, min=0, max=2000)
a3 = Parameter(name='a3', value=400, min=0, max=2000)

b = Parameter(name='b', value=200, min=0, max=500)

t1 = Parameter(name='t1', value=0.0001, min=0, max=1000)
t2 = Parameter(name='t2', value=0.07, min=0, max=1000)
t3 = Parameter(name='t3', value=1., min=0, max=100)

I dont get the warning, but I do get Fitting status message: Inequality constraints incompatible. Either I'm stupid and I've chose the guess outside of the bounds (but I dont see where) or its not related to only specifing left bound. No bounds = No problems. The fitting acutally works quite well even with mediocre guesses, and works but slow with poor guesses.

@tBuLi tBuLi closed this as completed Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants