0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 clear
0012 close all force
0013
0014
0015 mname = mfilename;
0016 mpath = mfilename('fullpath');
0017 mdir = mpath(1:end-length(mname));
0018 cd(mdir);
0019
0020 addpath utils/
0021
0022 disp(['--------------------',datestr(now),'-------------------------'])
0023
0024
0025
0026
0027
0028
0029
0030 rseed = 2012;
0031 rand('state',rseed);
0032 randn('state',rseed);
0033
0034
0035 mType = 'randn';
0036 sType = 'randn';
0037 SNR = 40;
0038
0039 N = 256;
0040 M = round(N/4);
0041 T = round(M/4);
0042
0043
0044 delx_mode = 'mil';
0045 fprintf('Standard LASSO/BPDN homotopy..\n');
0046 str0 = sprintf('mType-%s, sType-%s, SNR = %d, (N,M,T) = %d, %d, %d.', mType, sType, SNR, N, M, T);
0047 disp(str0);
0048
0049 maxsim = 10;
0050 SIM_stack = cell(maxsim,1);
0051
0052
0053 for sim = 1:maxsim
0054
0055
0056 in = []; in.type = sType; in.T = T; in.randgen = 1;
0057 x = genSignal(N,in);
0058 x = abs(x);
0059 [val ind] = sort(abs(x),'descend');
0060 ind_pos = ind(val>1e-1);
0061 gamma_orig = ind_pos(1:min(length(ind_pos),M-1));
0062
0063
0064
0065 in = []; in.type = mType;
0066 A = genAmat(M,N,in);
0067
0068
0069 sigma = sqrt(norm(A*x)^2/10^(SNR/10)/M);
0070 e = randn(M,1)*sigma;
0071 y = A*x+e;
0072
0073
0074
0075
0076
0077
0078
0079 tau = max(1e-4*max(abs(A'*y)),sigma*sqrt(log(N)));
0080
0081 err_fun = @(z) (norm(x-z)/norm(x))^2;
0082 maxiter = 4*N;
0083
0084
0085 in = [];
0086 in.tau = tau;
0087 in.delx_mode = delx_mode;
0088 in.debias = 0;
0089 in.verbose = 0;
0090 in.plots = 0;
0091 in.record = 1;
0092 in.err_fun = err_fun;
0093 out = l1homotopy(A,y,in);
0094 xh = out.x_out;
0095 iter_bpdn = out.iter;
0096 time_bpdn = out.time;
0097 gamma_bpdn = out.gamma;
0098 err_bpdn = out.error_table;
0099
0100
0101 in = [];
0102 in.tau = tau;
0103 in.nonneg = 1;
0104 in.delx_mode = delx_mode;
0105 in.debias = 0;
0106 in.verbose = 0;
0107 in.plots = 0;
0108 in.record = 1;
0109 in.err_fun = err_fun;
0110 out = l1homotopy(A,y,in);
0111 xh_nonneg = out.x_out;
0112 iter_nonneg = out.iter;
0113 time_nonneg = out.time;
0114 gamma_nonneg = out.gamma;
0115 err_nonneg = out.error_table;
0116
0117 SIM_stack{sim} = [sim, tau, ...
0118 norm(x-xh)^2/norm(x)^2, sum(iter_bpdn,2), sum(time_bpdn,2), ...
0119 norm(x-xh_nonneg)^2/norm(x)^2, sum(iter_nonneg,2), sum(time_nonneg,2)];
0120
0121 fprintf('sim %d. tau = %3.4g, (err,iter,time): l1homotopy-%3.4g,%3.4g,%3.4g; nonneg homotopy-%3.4g,%3.4g,%3.4g. \n', ...
0122 SIM_stack{sim});
0123
0124
0125 figure(1); plot([x xh xh_nonneg]);
0126 title('Comparison betweeen the new and nonneg homotopy code')
0127 end
0128 mS = mean(cell2mat(SIM_stack),1);
0129 fprintf('Average results: maxsim %d. tau = %3.4g, (err,iter,time): l1homotopy-%3.4g,%3.4g,%3.4g; nonneg homotopy-%3.4g,%3.4g,%3.4g. \n', maxsim, mS(2:end));