lsqcurvefit cost/optimization function
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Star Strider
el 13 de Jul. de 2016
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 comentarios
Star Strider
el 15 de Jul. de 2016
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
el 15 de Jul. de 2016
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 comentarios
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!