function test2(mu,tol,sigma) % Test script for caam335 matlab project % % It solves the sparse component separation problem: % min 0.5||XY + Z - M||^2 + mu*||Z(:)||_1 % where X and Y are low-rank, and Z ia sparse. % % 2009, Yin Zhang if nargin < 1; mu = 1e-7; end if nargin < 2; tol = 1e-6; end if nargin < 3; sigma = 0; end % problem specification load mri; [m,n] = size(B); r = rank(B); density = 0.05; Z0 = zeros(m,n); p = randperm(m*n); L = round(density*m*n); Z0(p(1:L)) = 1; fprintf('\n[m n r] = [%i, %i, %i]\n',m,n,r); fprintf(' mu %6.2e\n',mu); fprintf(' tol %6.2e\n',tol); fprintf('sigma %6.2e\n',sigma); % error calculation function ferr = @(U,V) norm(U-V,'fro')/norm(V,'fro'); % data matrix X0Y0 = B; M = X0Y0 + Z0; M = M + sigma*randn(m,n); for j = 1:3 if j == 1 && exist('YZcode','file') || ... j == 2 && exist('YZbase','file') || ... j == 3 && exist('MYcode','file'); % call solver tic; switch j case 1; fprintf('\n... YZcode ...\n') MU = 2.^(18:-1:0)*mu; [X,Y,Z] = YZcode(M,r,MU,tol); case 2; fprintf('\n... YZbase ...\n') [X,Y,Z] = YZbase(M,r,mu,tol); case 3; fprintf('\n... MYcode ...\n') [X,Y,Z] = MYcode(M,r,mu,tol); end solve_time = toc; toc; % information output XY = X*Y; Mc = XY + Z; fprintf('XY RelErr = %8.3e\n',ferr(XY,X0Y0)); fprintf('Z RelErr = %8.3e\n',ferr(Z,Z0)); fprintf('M RelErr = %8.3e\n',ferr(Mc,M)); % plotting plot_images(X,Y,Z,M,solve_time,density,j) end end