lsqcurvefit error: Objective function is returning undefined values at initial point. lsqcurvefit cannot continue.

조회 수: 2 (최근 30일)
Hello dear all, I am fitting a multiple set of measurements to a function (my non-linear model function) and trying to get the parameters that fit the measurement to the data at best. The model consists of two parameters to be fitted. I have around 4000 measurements (these are actually pixels of images, but irrelevant here...), so I call lsqcurvefit 4000 times. I use the lsqcurvefit with options Levenberg-Marquardt, upper and lower bounded, analytical Jacobian provided by me. I give the lsqcurvefit the same initial point for every measurement (i.e. for each call of the lsqcurvefit). For most of the measurement, the algorithm works and returns me proper values for the parameters. But for some measurements, it gives out the error:
"Objective function is returning undefined values at initial point. lsqcurvefit cannot continue."
I check where the error comes from, it is generated by the built-in matlab function 'snls' called by lsqcurvefit. When I monitor the workings in debug mode and look at the values the function has, it indeed has some 'Inf' values in it, so the error is correctly generated. However, I don't understand why I get 'Inf' for some values of the function, the model function never becomes infinity inside the boundaries I provide the lsqcurvefit with. Plus, I always give the same initialization to each call of lsqcurvefit and most of the times it works, sometimes not. Another plus, when I look at the values of the function in the debug mode, I see different values each time, which is wrong, because the model is the same and the initialization is the same, thus the evaluation of the model at the initialization has to yield the exact same result. Any help or comment will be appreciated. Thanks, Kerem

채택된 답변

Matt J
Matt J 2014년 5월 2일
편집: Matt J 2014년 5월 2일
I use the lsqcurvefit with options LevenbergMarquardt, upper and lower bounded.
Levenberg Marquardt does not support bound constraints. lsqcurvefit should have warned you about this. It's probably ignoring the bounds.
Plus, I always give the same initialization to each call of lsqcurvefit and most of the times it works, sometimes not.
You are fitting different data every time, so the least squares function is different every time.
  댓글 수: 2
Matt J
Matt J 2014년 5월 5일
Kerem tezcan Commented:
Thanks Matt J, 1.Yeah, you're right LM does not accept boundaries, so it is just changing the algorithm to trust-region internally somewhere in the code. But it does not matter for my application for now, just gave it for clarity. 2. You are right again, the objective function is different, however it is sth of the form |model-data|||^2. And the reason that this becomes infinite is that the evaluation of the model with the given parameters has an infinite value in it. Otherwise, the data has to be infinite, which is not the case. So the function evaluation is giving infinity at some value, but this is also incorrect. I hope you will give me another reply. Thanks a lot,
Matt J
Matt J 2014년 5월 5일
Kerem tezcan Commented:
Dear Matt J, I have spotted the problem, thanks to your comment directing me to the objective function. This was the problem: The model function I have is an exponential function, thus it can never be equal to zero. The data also has to follow this, however due to noise, it takes the value zero at some points. Of course the fitting algorithm cannot work, if the model cannot possibly explain the data, whatever the parameters are, and the objective function goes to infinity at that data point. I will fix this zero problem and it should be fine. Thanks again, Kerem

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by