The difference of SSE and MAE curve fitting and optimization

24 views (last 30 days)
I am trying to fit some series of data taken at different frequencies to a custom model. But it doen't get reasonable result and fit for some of data series. The data I have is a nonlinear system with multiple distinct peaks. And the fitting function is essentially a fraction where I do have multiplication of two exponential functions in both nominator and denominator and one of the exponential functions are an exponential function of a series of Gaussian functions where the fitting parameters are the amplitude and width of each Gaussian and the distance between the Gaussians and the last fitting parameter is the argument of the other one of the two exponential functions.
I have tried curve fitting tool matlab (used both Trust-region and levenberg-marquardt algorithms) and also optimization tool (along with multistart and globalsearch) where I tried to minimize the SSE between the actual data and the predicted value from the model. But none of them helped.
I am wondering is minimizing SSE a good measure for optimization in my case? Also, in curve fitting tool sse is one of the measures of the goosness of fit.
I know about another measure MAE (minimum of absolute errors) but I am not sure how it is defined properly and if minimizing it is more helpful than minimizing sse or not or essentially I will see the same things that I see for SSE.
I appreciate your comments and suggestions!

Accepted Answer

William Rose
William Rose on 9 May 2022
In most curve-fitting problems, you will not see a big difference when you minimize SSE versus minmize sum of absolute errors (SAE). Minimization of SSE has the nice property that, if the errors are normally distributed, then minimizing the SSE produces a maximum likelihood estimate. Which is nice from a statistical viewpoint. Minimizing SAE has the advantage that it is more robust, that is, it is less skewed by outliers.
You can minimize SAE by defining a function that returns the SAE, then using fmincon() to find the parameters that minimize the SAE function.
I am attaching an example script that fits three parameters, by minimizing SSE and by minimizing SAE. The script includes an SSE function and an SAE function. fmincon() is used two times: first to find the parameters that minimize SSE, then to find the parameters that minimize SAE. Both sets of fitted parameters are displayed, along with the true parameter values. Here is an example of the console output produced by the script:
>> fitdata1Dexample
Fitting results:
Minimize SSE: Fitted a,b,c = -1.904 5.036 0.424
Minimize SAE: Fitted a,b,c = -1.855 5.043 0.373
True values: a,b,c = -2.000 5.000 0.500
You will get different results each time you run it, since the random noise is different every time.
The function to compute SAE is
%% SAE function
function SAE = sumabserr1D(params)
%SUMABSERR1D Sum of absolute error between data and model prediction
% y=vector of data
% a,b,c = model parameters
% x = locations at which the function model1D() should be evaluated
% model1D() = function describing the model
% Function sumabserr1D() is to be minimized in a model fitting routine
% WCRose 2022-05-08
global x y;
a=params(1);
b=params(2);
c=params(3);
SAE=sum(abs(y-model1D(x,a,b,c)));
end
where model1d() is defined in the script.
Good luck.
  8 Comments

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 9 May 2022
I think using MSE or SSe would tend to find a fit to minimize real outliers and get closer to the outliers, while MAE (mean absolute error or median absolute error) would tend to fit better overall but may be way off at the outlier points. This is because if you square the difference, outliers far away from the fit have a much greater influence. But I could be wrong about that. If you don't have any really bad outliers, the fits may be really close to each other.

Community Treasure Hunt

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

Start Hunting!