Excluding data points from optimization process using createOptimProblem function
Show older comments
I have a objective function which produces a 2x13 vector output based on a mathematical model. I'm using 'createOptimProblem' function with 'lsqcurvefit' to compare this output to experimental data of same size, producing a theoretical fit to my experimental data. The problem is that some of my experimental datapoints have huge error, and because of that I would like to exclude them from the optimization process. I would still like to have the fit based on my model to cover the full range of 2x13 points, but I would like the 'lsqcurvefit' function to exclude the experimental datapoints of my choosing when it's calculating the residual error. The attached image shows an example of fit where the experimental datapoints highlighted with green circles are ones I would like to exclude from the residual error calculation. Is there a way to do this using the createOptimProblem function or could you think better ways to do this?

Answers (1)
Instead of using lsqcurvefit's calculation of the residual error, why not do your own cusotmized calculation after the optimization is complete? The thing you want to do has nothing to do with the optimization process that I can see.
4 Comments
Ville Tiainen
on 12 Aug 2021
You said in your initial post "I would still like to have the fit based on my model to cover the full range of 2x13 points", which sounds like you don't want the optimization process to exclude the defective data.
If you do want the optimization process to exclude defective data, you must simply
(1) remove that data from your ydata input.
(2) modify your model function so that it does not generate predictions of those ydata values.
Ville Tiainen
on 12 Aug 2021
There's no reason your ydata needs to be organized as a 2xN matrix. Discard the undesired values using a logical index keep and arrange ydata as a vector. Here's how you might wrap your current model fuction mdl(x,xdata) to accomplish this:
ydata_new=ydata(keep); %new ydata
mdl_new=@(x,xdata) wrapper(x,xdata,keep); %new objective function
function [ypred,varargout]=wrapper(x,xdata,keep)
[ypred,varargout(1:nargout-1)]=mdl(x,xdata);
ypred=ypred(keep);
end
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!