⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig6_5.m

📁 斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱
💻 M
字号:
% Example 6.2: Robust regression using the Huber penalty% Section 6.1.2, Figure 6.5% Boyd & Vandenberghe "Convex Optimization"% Original by Lieven Vandenberghe% Adapted for CVX by Joelle Skaf - 09/07/05%% Compares the solution of regular Least-squares:%           minimize    sum(y_i - alpha - beta*t_i)^2% to the solution of the following:%           minimize    sum( phi_h (y_i - alpha - beta*t_i)^2 )% where phi_h is the Huber penalty function, (t_i,y_i) are data points in a% plane.cvx_quiet(true);% Input datarandn('seed',1);rand('seed',1);m=40;  n=2;    A = randn(m,n);xex = [5;1];pts = -10+20*rand(m,1);A = [ones(m,1) pts];b = A*xex + .5*randn(m,1);outliers = [-9.5; 9];  outvals = [20; -15];A = [A; ones(length(outliers),1), outliers];b = [b; outvals];m = size(A,1);pts = [pts;outliers];% Least Squaresfprintf(1,'Computing the solution of the least-squares problem...');xls =  A\b;fprintf(1,'Done! \n');% Huberfprintf(1,'Computing the solution of the huber-penalized problem...');cvx_begin    variable xhub(n)    minimize(sum(huber(A*xhub-b)))cvx_endfprintf(1,'Done! \n');% Plotsfigure(1);  hold offplot(pts,b,'o', [-11; 11], [1 -11; 1 11]*xhub, '-', ...     [-11; 11], [1 -11; 1 11]*xls, '--');axis([-11 11 -20 25])title('Least-square fit vs robust least-squares fit (Huber-penalized)');xlabel('x');ylabel('y');legend('Data points','Huber penalty','Regular LS','Location','Best');%print -deps robustls.eps

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -