fminsearch: improving optimization of parameters over wide scale of y values

13 views (last 30 days)
Hello,
I am currently trying to solve the problem of fitting a known function to a given dataset of x, y, with y spanning a high range of values. Here's the snippet of code that needs consideration:
fit_params0= [35 1.11 1.7 RL0array(i_temp)];
LB=[10 0.1 0.1 1000];
UP=[1e+6 2 10 1e+12];
fun=@(fit_params) norm (abs( ( A_const.*T(i_temp).*T(i_temp).*exp( -q_electron.*fit_params(2)./(k.*T(i_temp)) ).*S ).*( exp( q_electron.*(tempU2-tempI2.*fit_params(1))./( fit_params(3).*k.*T(i_temp) )) -1 ) ) + tempU2./fit_params(4) - tempI2 );
fit_params=fminsearchbnd(fun,fit_params0, LB, UP, options);
x is tempU2 and y is tempI2.
fminsearchbnd is a modified version of fminsearch that enforces upper and lower bounds of variation parameters. fun calculates the absolute difference between the fitted y data and the given y data tempI2, takes the absolute values, then uses norm() to get a scalar from the resultant matrix.
Attached is a plot of the given data (blue line) compared to the plot of the fitted equation (blue dots):
Note that this is a logy graph. As you can see, the fit works great for high values of y... However, my y data ranges from 1E-3 to values as low as 1E-12.
My question, then, is how would I go about making fun() sensitive to scale after the difference between fitted y and given y is calculated? I do not want fminsearch to waste time looking at too many significant digits on high y scales.
I imagine something like multiplying matrix elements by their own scale during a second iteration of fminsearch would mitigate this problem? By that I mean, for example, if some calculated fun value would be 3.5E-5, it would then be multiplied by its own scale (E-5), to result in 3.5, giving the optimization problem equal weight on all scales.

Accepted Answer

John D'Errico
John D'Errico on 4 Aug 2019
Edited: John D'Errico on 4 Aug 2019
This is not a question of the optimizer you use. It is a question of scale, and your objective function. ANY optimizer will fail, when posed the problem that you have posed.
But what did you do? You plotted it on a LOG scale axis!!!!!! What does that tell you? It tells you that you want to LOG your data. Log your model. Now minimize the differences of those logs.
By logging the process, this automatically allows it to work on data that varies over large scale differences. Logs turn the problem into a proportional error problem.
  1 Comment
Edvinas Gvozdiovas
Edvinas Gvozdiovas on 4 Aug 2019
Edited: Edvinas Gvozdiovas on 4 Aug 2019
I hope this post won't be a highlight of some 'top epic matlab central fails 2019' youtube video. Thank you!

Sign in to comment.

More Answers (0)

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!