Cody

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

Solution 2962156

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 1.3870 -1.2430 -0.8940 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 -2.0198 2.1022 -6.0576 -1.1349 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: 28.907799 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 59.292319 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 37.599205 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 29.970404 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 26.309412 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 33.444805 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 41.916497 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 26.693344 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 32.639607 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 26.190905 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 54.589742 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 31.388768 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 48.348548 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 51.710705 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 56.808845 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 95.787103 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 111.123692 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 205.375189 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 92.581693 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 93.164552 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 44.593818 -0.0276 2.3350 -4.6174 -3.1252 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 48.235931 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 155.288327 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 120.771811 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 89.501079 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 104.366179 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 19.345553 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 31.757886 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 50.462414 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 25.973962 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 42.810830 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 19.229215 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 15.445822 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 17.667809 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 38.169183 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 37.808548 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 19.721306 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 59.271413 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 97.403410 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 95.269867 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 23.270315 -0.0533 1.0949 3.5857 3.1293 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 64.543639 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 69.928877 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 62.251793 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 59.182562 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 62.950667 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 54.364334 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 52.283874 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 40.245191 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 36.874203 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 54.887663 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 55.706703 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 57.946283 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 63.233124 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 108.979534 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 104.368931 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 114.016802 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 61.073574 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 72.418415 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 56.532939 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 133.081944 0.0145 3.1348 -4.9379 -3.5724 ans = [] Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 140.458673 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 124.925199 Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 112.767148 Exiting: Maximum nu...

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!