MATLAB: Ssm function produced different results in three versions

Econometrics ToolboxMATLABOptimization Toolbox

Why do I obtain different results across releases (2015a, 2016b and 2017a) when trying to use 'ssm' function to perform Maximum likelihood estimation?

Best Answer

The 'estimate' function which uses the output of the 'ssm' function (Econometrics ToolBox) internally makes use of the 'fminunc' function (Optimization ToolBox).
There were no changes made to the functions used in the code ('ssm','estimate','fminunc') between the mentioned releases. However, the reason could be that these functions can exhibit small variations in value as versions are upgraded or internal code is being changed. Small differences in any step can accumulate and therefore affect the results of an iterative solver.
Since we cannot change the underlying libraries to be exactly the same, one can try out the below steps to improve the numerical conditioning of the problem.
  1. Scale the parameters by the number of terms in the sum, bringing it to the order of 1.
  2. Use central finite differences (options.FinDiffType = ‘central’) to get a slightly more accurate gradient estimate.
This is what I tried out using R2015a, R2016b and R2017a and the results were pretty consistent:
       param0=randn(5, 1); 
       mysum = sum(param0.^2); 
       param0 = param0/mysum;
       options = optimoptions('fminunc','Algorithm','quasi- newton','FinDiffType','central')
       model=estimate(model, y(trainset), param0,'Options',options);