Effacer les filtres
Effacer les filtres

Polynomial Fit from a high Deviation set of feature experiments

1 vue (au cours des 30 derniers jours)
kuku hello
kuku hello le 3 Mai 2022
Modifié(e) : Matt J le 3 Mai 2022
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 commentaires
Matt J
Matt J le 3 Mai 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')
kuku hello
kuku hello le 3 Mai 2022
Thanks, thats ok the solution doesn't have to be unique. If I have the option to see all of the options it would be great.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 3 Mai 2022
Modifié(e) : Matt J le 3 Mai 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')'
AllSolutions = 4×2
8 11 5 7 2 3 -1 -1
  2 commentaires
kuku hello
kuku hello le 3 Mai 2022
Wow thanks it looks like it works but can I have further information about the role of X? I'll admit this code seems to be high level programming :P.
Matt J
Matt J le 3 Mai 2022
Modifié(e) : Matt J le 3 Mai 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by