- Your data may be pure crap, insufficient to fit the model you desperately need to use. (And, no, I'm not insulting you or your data. But it is often the case that people have wildly insufficient data, and have no idea this is the case.) I don't know that, since I've not seen any data from you. But it is very often the case. A rank deficiency warning may well be a good hint of that possibility though. The answer is to get better data that will indeed support that model.
- On the other end, your data may be reasonable, but you may have simply chosen a model that has no possibility of being fit, thus an insane choice of model for this data. Again, I've seen no model, so I can only hazard a wild guess. But too often people try to fit high order polynomial models, or sums of many exponential terms. In either case it is trivially easy to generate problems that will see rank deficiencies, and there are many other poor choices of model one can make. The answer is probably to choose a better model.
- You may have serious scaling issues. So if some of your parameters are scaled to be on the order of 1e10, and others on the order of 1, then expect to see issues in the numerical linear algebra. This is easily fixable of course, by a simple scaling. Just use a better choice of units, thus perhaps kilometers versus nanometers.
- You may have chosen poor starting values, that cause the optimizer to diverge into limbo, to get lost. The answer to this is to choose better starting values.
How to optimize a fit with nlinfit
10 次查看(过去 30 天)
显示 更早的评论
I wrote a model (with 7 ode) and want to fit it to experimental data. Most of the parameters values were taken from scientific literature. When I run the non-linear fit (using nlinfit), I get:
(1) lot of warnings like:
Warning: Rank deficient, rank = 10, tol = 2.103668e+005.
> In nlinfit>LMfit at 327
In nlinfit at 162
In main at 37
(2) some non physical parameter values (like a negative value for size), or extremely different estimation comparing to the literature measurement.
(3) when I slightly change my parameter guess, I get either a different curve, or errors (like: Error using nlinfit>checkFunVals (line 362) The function you provided as the MODELFUN input has returned Inf or NaN values, or: Failure at t=2.403593e+00...), or even no output at all.
Does anyone no what to do to get a good and reasonable fit?
Attached is my code.
Thanks
0 个评论
回答(2 个)
John D'Errico
2015-7-19
编辑:Walter Roberson
2015-7-19
Too often people think that there is some magic salve they can apply to a nonlinear optimization to make it work. I suppose this is because others seem to make them work with no apparent problems. So what is wrong here? Where is the disconnect? There may be several reasons for failure. I'll just guess at a couple of them.
It is not always easy to get better data. You may have what you have and cannot get more. Or you may be forced to use a specific model. And better starting values are often difficult to guess. Sorry, but not all things are trivial to do. The easy problems are already solved anyway.
Of course, one reason why some people manage to make their optimization work more easily is they know these things already. Throwing a different optimizer at the problem usually won't help. It will still probably see problems.
SOMETIMES a constrained optimizer might help IF you can find an intelligent set of constraints. That is, keep the problem from going to the bad place.
Another thing that often can help is to use a partitioned nonlinear least squares estimation scheme, since the reduces the effective nonlinear dimensionality of the problem. It makes the search space smaller, and thus easier to search. You can find tools for this in my own fminspleas, or in the pleas code I posted with my optimization tips and tricks submission.)
Abhishek Pandey
2015-7-16
编辑:Abhishek Pandey
2015-7-16
Hello,
I understand that you want to fit a model to experimental data.
I tried running your code, and to find the line where the warning is generated, I executed the following command on MATLAB Command Window before running your code:
dbstop if warning
This stops execution of the code at the line wherever a warning is generated.
This showed that the warning is generated in line 574 of “nlinfit.m”. Here, I saw that the rank of the matrix used for the solution is 9, whereas the number of unknowns is 11 which results in an ill-conditioned matrix.
You could consider using the “ fmincon ” function. If your problem can be formulated as an optimization problem, the function would be able to find a solution. You would have to set up the objective function and define the error (for example least square, weighted least square, maximum likelihood and so on) to be used with this formulation. Please note that if there are multiple solutions, “fmincon” function may provide different solutions for different initial conditions.
I hope that helps!
- Abhishek
2 个评论
John D'Errico
2015-7-19
Reformulating it as an fmincon problem will probably NOT help here.
The problem will still be that the data is inadequate to estimate the parameters.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!