Polynomial Fit from a high Deviation set of feature experiments
1 view (last 30 days)
Show older comments
I am doing a number of experiments to evaluate a feature in different points in time, the result of each experiment have a high error value or a big standard deviation. I know that by taking a point from each experiment I should be able to create a linear fit. So I need to create an algorithm which is able to pick the right feature evaluations in order to form a linear fit with minimum error (with the least mean square error from the line as possible).
For example I have the following experiments:
exp1 = [10,9,11,8];
exp2 = [5,7,5,9];
exp3 = [2,4,3,2];
exp4 = [-4,-2,-3,-1];
I want to pick one point (single feature evaluation) from each experiment, and from the points taken from every experiment, to make a linear fit with minimum deviation as possible.
So in the example case In order to create a line without any deviation I will choose the set of points [8,5,2,-1]. Each point is measured in different experiment and doing a linear fit I can make a perfect line of feature vs experiment number. If I'll choose point 11 from exp1 and -4 from exp4 the line would have a higher deviation (MSE) from the line chosen above.
Any help?
Thanks in advance.
2 Comments
Matt J
on 3 May 2022
So in the example case In order to create a line without any deviation I will choose the set of points [8,5,2,-1].
I hope you know that the solution is not unique. Another solution here is [11,7,3,-1],
plot([11,7,3,-1],'-o')
Accepted Answer
Matt J
on 3 May 2022
Edited: Matt J
on 3 May 2022
expData = {[10,9,11,8];
[5,7,5,9];
[2,4,3,2];
[-4,-2,-3,-1]};
[Y{1:4}]=ndgrid(expData{:});
N=numel(Y);
Y=reshape( cat(N+1,Y{:}) ,[],N)';
X=[1:N;ones(1,N)]';
SE=vecnorm(X*(X\Y)-Y,2,1);%L2 error
minSE=min( SE ); %min. L2 error
AllSolutions=unique(Y(:,abs(SE-minSE)<=1e-10*minSE)','rows')'
2 Comments
Matt J
on 3 May 2022
Edited: Matt J
on 3 May 2022
The equation for a line is y=m*x+b, which can be written in matrix multiplication form,
[x,1]*[m;b]=y
If you have many x(i) and y(i), this becomes,
[x1,1;
x2,1;
...
xN,1]*[m;b]=[y1;y2;y3;...;yN]
The Nx2 matrix on the left hand side is X, the Nx1 vector on the right hand side is Y, and the solution for [m;b] is X\Y.
More Answers (0)
See Also
Categories
Find more on Polynomials 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!