'lsqnonlin' giving non-identical results from multiple trials considering same data and starting parameter values

Hi
I implemented lsqnonlin for estimating 30 parameters in my Model. My objective function is of the order 18000X22.
My lsqnonlin settings are:
1. I have parameter bounds set
2. I use trust-region-reflective algorithm.
Strangely, I get non-identical values of estimates for the 30 parameters under consideration with multiple trials using the same code, data going into lsqnonlin for estimation and with same starting values.
As far as I know, lsqnonlin is a deterministic optimization algorithm . So, I am supposed to get identical results from these trials.
Any inputs would be helpful in understanding this variability in results from independent estimation trials. using same data and parameter starting values.
Thanks for your time

 Accepted Answer

lsqnonlin is indeed a deterministic solver. If you have the same data in, then you should get the same iterative steps. Since you don't, then there is likely something nondeterministic in your objective function.
Try an experiment. Execute the line
rng default
immediately before running lsqnonlin. Then execute the line and lsqnonlin again. I would be surprised if there is any difference between the two runs, unless your objective function calls an external piece of code that keeps its own state.
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

Hello Alan
Thanks for the suggestion. I will try it.
Checked this link http://www.mathworks.com/matlabcentral/newsreader/view_thread/330918 about using rng default option.
From the code in the link above, I understood that random numbers generated are assigned as starting values of parameters to be estimates using lsqnonlin.
But, I am using a 'constant' set of starting values which I pass into lsqnonlin.
Code: My main program:
valstobepassedin=startingvaluesofparameters{1}; % 30 X 1 cell array containing numerical values.
% Now, call function where lsqnonlin fitting should be done.
[lsqnonlinestimates,Errorconcnumbers]=lsqnonlinfitting(data,valstobepassedinlsqnonlin);
%%%End of Main Program %%%%
%%%My lsqnonlinfitting program file
[lsqnonlinestimates,Errorconcnumbers]=lsqnonlinfitting(data,valstobepassedinlsqnonlin)
r=valstobepassedinlsqnonlin;% Assigned starting values of parameters passed to a variable 'r'
% Code not shown: set lower and upper bounds for parameters to be estimated.
lsqnonlinoptions=optimset('Algorithm','trust-region-reflective','Display','iter-detailed','MaxFunEvals',50000,'MaxIter',1000,'TolX',1e-6,'TolFun',1e-12);
[lsqnonlinkestimates,Errorconcnumbers]= lsqnonlin(@lsqnonlin_fun, r,lb,ub,lsqnonlinoptions); % Here, Errorconcnumbers is the fitness function
function erroracrossallstates= lsqnonlin_fun(r)
%%Code too big to be shown, Construct obj.function%%%%
end % end of lsqnonlin_fun function
end % end of lsqnonlinfitting function
% End of file lsqnonlinfitting
Thanks once again
Harish
That somebody supplied random starting values for an optimization need not make it always a good idea. In that thread, it was the person asking the question who used random starting values. There is no presumption that they knew what they were doing.
In fact, it is often a poor idea since those randomly chosen starting values may send the optimizer to a sub-optimal local solution. Far better is to use a well chosen set of starting values. And if one knows nothing about the parameters to enable one to make a semi-intelligent choice for them, then it is a good idea to think about the model.
It is quite possible that something in your code has a random element inside it. For example, eigs and svds, while they might appear to be deterministic, use a random start point.
Thanks Alan
Using rng default before lsqnonlin worked and is giving me reproducible results.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!