How to set first-order optimality value for lsqcurvefit?

3 views (last 30 days)
Lsqcurvefit is stopping the algorithm due to 'local minimum possible' and states that the current step was less than the step size tolerance. The fit is horrible though and the first-order optimality is still over 200. I've been searching for how to set the first-order optimality so that the algorithm cannot stop till it's 0.
options = optimset('FunValCheck', 'on', 'MaxFunEvals',1*10^10, ...
'TolX',1e-15, 'TolFun',1e-30, 'MaxIter', 1*10^10, 'Display', ...
'iter')
[parameters, resnorm, residual,exitflag, output] = lsqcurvefit(@SCD, param, ...
time, Y, lowerbounds, upperbounds, options);

Answers (2)

Matt J
Matt J on 26 Sep 2013
Edited: Matt J on 26 Sep 2013
It sounds like you might simply be stuck at a local min and might just need a better initial guess.
However, you can use the OutputFcn option to set your own stopping criterion on the firstorderopt. It will be passed to your Output Function in the optimValues argument. You would have to deactivate all other default criteria, though, to make sure only your criterion was used and if you set the tolerance on firstorderopt to zero exactly, it will probably never stop.
  2 Comments
Matt J
Matt J on 30 Sep 2013
Brittany Commented:
I would think that but this fit is within what should be reasonable range, but doesn't fit the data at all.
Matt J
Matt J on 30 Sep 2013
Edited: Matt J on 1 Oct 2013
It could be worth normalizing your ydata and F(x,xdata) so that instead of your ydata ranging up to 3*10^5, it only ranges to, say, 3. This should make things respond much better to the default TolFun.
Similarly, because the variations in your xdata are most naturally represented using a semilogx axis, it might help to reformuate your objective F(x,xdata) in terms of log(xdata).
Beyond that, the failure in your fit might simply be due to a bad model function, or a bad implementation of that function in code. You would have to show it to us for us to evaluate that.

Sign in to comment.


Alan Weiss
Alan Weiss on 30 Sep 2013
I don't know what is going on here. But your tolerance settings (options) are not sensible. Please eliminate these options (meaning use the defaults) and try again:
'TolX',1e-15, 'TolFun',1e-30
I also agree that you might want to use different initial values for your solver. It is not hard to get a spurious local optimum, as this example shows. But it is possible that your model equation is not good--I don't know because I haven't seen it. Maybe you squared and added the differences yourself rather than letting the solver do it? Without more detail, we are just guessing.
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!