Cody

Problem 45854. Least Absolute Deviations (L1-norm) line fit - degree n

Solution 2962159

Submitted on 18 Sep 2020 by Rafael S.T. Vieira
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
d=2; X=[-2 -1 0 1 2 3]'; Y=[7.14 -1.87 -0.89 -0.75 2.08 7.86]'; P=LADfit(X,Y,d); % P_correct = [1.387 -1.243 -0.894] res=sum(abs(Y-polyval(P_lad,X))); % Optimal residual = 3.698 assert(res<4.0)

Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.715401 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 5.563974 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.954702 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698145 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 3.698000 ans = []

2   Pass
d=3; X=[-4 -3 -2 -1 0 1 2 3 4]'; Y=[186 408 21 8 2 -4 -21 -57 -121]'; P=LADfit(X,Y,d); % P_correct = [-2.0431 2.1486 -5.6861 -1.8778] res=sum(abs(Y-polyval(P_lad,X))); % Optimal residual = 341.23 assert(res<350)

Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 365.066608 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 360.613211 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 344.140816 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 364.210624 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 341.420639 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 347.227020 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 349.672006 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 343.783050 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 344.384457 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 357.230254 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 360.931033 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 346.752534 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 380.832007 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 369.588197 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 405.141332 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 432.453038 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 389.519112 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 456.227572 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 444.818698 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 421.271475 ans = []

3   Pass
d=3; n=10; % Nr of points no=2; % Nr of outliers max_res = 0; max_ratio = 0; for cycle=1:10 rng('shuffle'); P=(rand(d,1)-0.5)*10; % Generate model X=(rand(n,1)-0.5)*10; % Generate X Y=polyval(P,X)+(rand(n,1)-0.5)*2; % Generate Y and add noise Y(1:no)=Y(1:no)+(rand(no,1)-0.5)*50; % Add outliers P_lad=LADfit(X,Y); P_lin=polyfit(X,Y,1); Y_lad=polyval(P_lad,X); res_lad=sum(abs(Y-Y_lad)); Y_lin=polyval(P_lin,X); res_lin=sum(abs(Y-Y_lin)); max_res=max(max_res,res_lad); max_ratio=max(max_ratio,res_lad/res_lin); end assert(max_res<50.0 & max_ratio<0.98); % Should be always better than L-2 and under 50

Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 44.860180 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 137.660279 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 93.852705 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 84.325602 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 86.464980 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 54.957897 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 44.993461 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 36.162027 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 50.571549 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 126.504481 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 52.401430 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 48.535797 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 51.922687 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 51.435022 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 63.533537 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 109.325495 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 131.383590 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 158.442727 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 165.132378 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 181.861613 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 174.705882 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 111.942679 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 168.869132 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 71.340744 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 84.485166 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 83.093670 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 62.347358 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 81.395617 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 46.421714 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 60.455566 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 45.717331 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 45.149934 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 79.745779 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 72.288628 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 108.937159 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 94.150256 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 42.387072 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 77.227831 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 462.968202 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 214.438154 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 77.838629 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 71.704183 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 70.526963 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 39.431730 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 147.905176 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 31.106084 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 94.521629 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 89.281411 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 75.784590 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 30.883638 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 29.262449 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 49.295279 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 30.113470 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 27.423837 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 22.815029 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 22.995499 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 36.713944 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 62.698242 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 39.887779 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 30.027418 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 51.171400 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 39.379598 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 95.051648 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 98.588514 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 183....

Suggested Problems

More from this Author10

Community Treasure Hunt

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

Start Hunting!