0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 clear
0018 close all force
0019
0020
0021
0022
0023
0024 mname = mfilename;
0025 mpath = mfilename('fullpath');
0026 mdir = mpath(1:end-length(mname));
0027 cd(mdir);
0028
0029 addpath utils/
0030 addpath utils/qr/
0031
0032 disp(['--------------------',datestr(now),'-------------------------'])
0033
0034
0035
0036 rseed = 2012;
0037 rand('state',rseed);
0038 randn('state',rseed);
0039
0040
0041 mType = 'randn';
0042 sType = 'randn';
0043 SNR = inf;
0044
0045
0046 rwt = 5;
0047
0048 N = 512;
0049 M = round(N/2);
0050 T = round(M/4);
0051 Tn = 0;
0052
0053
0054 delx_mode = 'mil';
0055 fprintf('Replace matrix A and/or signal x..\n');
0056 str0 = sprintf('mType-%s, sType-%s, SNR = %d, (N,M,T) = %d, %d, %d.', mType, sType, SNR, N, M, T);
0057 disp(str0);
0058
0059 maxsim = 10;
0060 SIM_stack = cell(maxsim,1);
0061 SIM_memory = cell(maxsim,1);
0062
0063
0064 for sim = 1:maxsim
0065
0066
0067 in = []; in.type = sType; in.T = T; in.randgen = 1;
0068 x = genSignal(N,in);
0069 [val ind] = sort(abs(x),'descend');
0070 ind_pos = ind(val>1e-1);
0071 gamma_orig = ind_pos(1:min(length(ind_pos),M-1));
0072
0073
0074 in = []; in.type = mType;
0075 A = genAmat(M,N,in);
0076
0077
0078 sigma = sqrt(norm(A*x)^2/10^(SNR/10)/M);
0079 e = randn(M,1)*sigma;
0080 y = A*x+e;
0081
0082
0083
0084
0085
0086
0087
0088 tau = max(1e-4*max(abs(A'*y)),sigma*sqrt(log(N)));
0089
0090 maxiter = 4*N;
0091 err_fun = @(z) (norm(x-z)/norm(x))^2;
0092
0093
0094 in = [];
0095 in.tau = tau;
0096 in.delx_mode = delx_mode;
0097 in.debias = 0;
0098 in.verbose = 0;
0099 in.plots = 0;
0100 in.record = 1;
0101 in.err_fun = err_fun;
0102 tic
0103 out = l1homotopy(A,y,in);
0104 xh = out.x_out;
0105 iter_bpdn = out.iter;
0106 time_bpdn = toc;
0107 gamma_bpdn = out.gamma;
0108 err_bpdn = out.error_table;
0109
0110
0111
0112
0113 xh_old = xh; tau_old = tau;
0114 x_old = x; y_old = y; A_old = A;
0115
0116
0117 in = []; in.type = mType;
0118 B = genAmat(M,N,in);
0119
0120 A = A_old+1/5*B;
0121
0122
0123 in = []; in.type = sType; in.T = Tn; in.randgen = 1;
0124 dx = genSignal(N,in);
0125 x = x_old + dx;
0126
0127 y = A*x+e;
0128
0129
0130
0131 tau = max(1e-4*max(abs(A'*y)),sigma*sqrt(log(N)));
0132
0133 homotopy_mode = 'dummy';
0134 switch homotopy_mode
0135 case 'dummy'
0136
0137
0138
0139
0140 W = tau;
0141 W_old = tau_old;
0142
0143
0144
0145 yh = A*xh_old;
0146 Atr = A'*(A*xh_old-y);
0147 u = -W.*sign(xh_old)-Atr;
0148 pk_old = Atr+u;
0149 otherwise
0150 didp('Go back ... no escape');
0151 end
0152
0153 in = out;
0154 gamma_old = in.gamma;
0155 switch delx_mode
0156 case 'mil';
0157
0158
0159
0160
0161 AtAgx = A(:,gamma_old)'*A(:,gamma_old);
0162 iAtAgx = inv(AtAgx);
0163 in.iAtA = iAtAgx;
0164 case {'qr','chol'};
0165
0166 [Q R] = qr(A(:,gamma_old),0);
0167 in.Q = Q; in.R = R;
0168 case 'qrM'
0169
0170 [Q0 R0] = qr(A(:,gamma_old));
0171 in.Q0 = Q0; in.R0 = R0;
0172 end
0173
0174 in.xh_old = xh_old;
0175 in.pk_old = pk_old;
0176
0177 in.u = u;
0178 in.W = W;
0179 in.W_old = W_old;
0180 in.delx_mode = delx_mode;
0181 in.debias = 0;
0182 in.verbose = 0;
0183 in.plots = 0;
0184 in.record = 1;
0185 in.err_fun = @(z) (norm(x-z)/norm(x))^2;
0186 tic
0187 out = l1homotopy(A,y,in);
0188 xh_dynDict = out.x_out;
0189 gamma_dynDict = out.gamma;
0190 iter_dynDict = out.iter;
0191 time_dynDict = toc;
0192
0193 SIM_stack{sim} = [sim, tau, ...
0194 norm(x_old-xh)^2/norm(x)^2, sum(iter_bpdn,2), sum(time_bpdn,2), ...
0195 norm(x-xh_dynDict)^2/norm(x)^2, sum(iter_dynDict,2), sum(time_dynDict,2)];
0196
0197 fprintf('sim %d. tau = %3.4g, (err,iter,time): l1homotopy from scratch-%3.4g,%3.4g,%3.4g; dynDict l1homotopy-%3.4g,%3.4g,%3.4g. \n', ...
0198 SIM_stack{sim});
0199
0200
0201 figure(1); plot([x xh xh_dynDict]);
0202 title('Comparison betweeen the new and old homotopy code')
0203 end
0204 mS = mean(cell2mat(SIM_stack),1);
0205 fprintf('Average results: maxsim %d. tau = %3.4g, (err,iter,time): l1homotopy from scratch-%3.4g,%3.4g,%3.4g; dynDict l1homotopy-%3.4g,%3.4g,%3.4g. \n', maxsim, mS(2:end));