문제

I have this MATLAB code and I´m trying to implement the method explained in top answer of this question: https://stats.stackexchange.com/questions/12546/software-package-to-solve-l-infinity-norm-linear-regression Here is the code that I´m using that starts with the data points:

x = [
    0
    0.101010101010101
    0.202020202020202
    0.303030303030303
    0.404040404040404
    0.505050505050505
    0.606060606060606
    0.707070707070707
    0.808080808080808
    0.909090909090909
    ];
y = [
    0.052993311292562
    14.923120014175920
    1.974502763975613
    -2.205773310050583
    -0.052548781318830
    2.935428041987883
    0.134606520161892
    0.146742215922384
    -0.418386565682831
    1.702041272689124
    ];
A1 = [x,ones(length(y),1),-ones(length(y),1)];
A2 = [-x,-ones(length(y),1),-ones(length(y),1)];
A = [A1;A2];
f = [0;0;1];
linprog(f,A,[y;-y])

The point is to find the the parameters (slope and intersection) of the best fit, i.e. a line, by minimizing the L-infinity norm of the residuals between the line and data points. I have made the same problem work for ordinary least squares (minimizing the L-2 norm) as well as for the L-1 fit. The line plotted from those methods fit really nicely between the data points. But can't seem to make this L-infinity fit work no matter what I do so I come to you for help, any tips appreciated.

도움이 되었습니까?

해결책

The sign of t in your inequalities is wrong. Try

A1 = [x,ones(length(y),1),-ones(length(y),1)];
A2 = [-x,-ones(length(y),1),-ones(length(y),1)];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top