lsqcurvefit cost/optimization function
15 ビュー (過去 30 日間)
古いコメントを表示
In the lsqcurvefit function, is there a way to change the output 'resnorm' to be a different cost or optimization function, such as the absolute value of the difference, or the log of that (instead of the square of the difference)?
0 件のコメント
回答 (2 件)
Star Strider
2016 年 7 月 13 日
The residual (the ‘raw’ difference between the fitted regression and the data) is the third output from lsqcurvefit. You can do whatever operations on it you want.
For example:
[x,resnorm,residual,exitflag,output] = lsqcurvefit(___);
abs_rsd = abs(residual);
log_abs_rsd = log(abs(residual));
2 件のコメント
Star Strider
2016 年 7 月 15 日
My pleasure.
Not to my knowledge.
If it’s not among the available options in the options structure, you can’t change it without hacking the code. I don’t recommend that even if it’s possible.
You can always write your own nonlinear curve-fitting routines. Having done that myself in FORTRAN back in the early 1980s, I don’t recommend it.
John D'Errico
2016 年 7 月 15 日
No. There is no way to change the lsqcurvefit code to use a different measure of error. Ok, no way except for rewriting lsqcurvefit.
The point is, lsqcurvefit uses algorithms that are specific to a sum of SQUARES of residuals. lsqcurvefit is not a general optimizer, that you could somehow just tell it to use a different metric.
If that is your goal, you could in theory use a different tool, perhaps fminunc or some other totally general optimizer. Even that is subject to significant problems however. For example, a sum of absolute values would result in a non-differentiable objective function. That could result in a failure to converge for fminunc.
So IF you truly needed to use a different objective, then you would be best off using an optimizer that would not be subject to such a failure. That might mean fminsearch, or perhaps a genetic algorithm, or some other stochastic scheme like a particle swarm method.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!