0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 clear
0014 close all force
0015
0016
0017 mname = mfilename;
0018 mpath = mfilename('fullpath');
0019 mdir = mpath(1:end-length(mname));
0020 cd(mdir);
0021
0022 addpath utils/
0023 addpath utils/qr/
0024
0025 disp(['--------------------',datestr(now),'-------------------------'])
0026
0027
0028
0029 rseed = 2012;
0030 rand('state',rseed);
0031 randn('state',rseed);
0032
0033
0034 mType = 'randn';
0035 sType = 'randn';
0036 SNR = inf;
0037
0038
0039 rwt = 5;
0040
0041 N = 512;
0042 M = round(N/2);
0043 T = round(M/5);
0044 Tn = round(T/20);
0045
0046
0047 delx_mode = 'mil';
0048 fprintf('Update time-varying signal..\n');
0049 str0 = sprintf('mType-%s, sType-%s, SNR = %d, (N,M,T) = %d, %d, %d; Tn = %d.', mType, sType, SNR, N, M, T,Tn);
0050 disp(str0);
0051
0052 maxsim = 10;
0053 SIM_stack = cell(maxsim,1);
0054 SIM_memory = cell(maxsim,1);
0055
0056 for sim = 1:maxsim
0057
0058
0059 in = []; in.type = sType; in.T = T; in.randgen = 1;
0060 x = genSignal(N,in);
0061 [val ind] = sort(abs(x),'descend');
0062 ind_pos = ind(val>1e-1);
0063 gamma_orig = ind_pos(1:min(length(ind_pos),M-1));
0064
0065
0066 in = []; in.type = mType;
0067 A = genAmat(M,N,in);
0068
0069
0070 sigma = sqrt(norm(A*x)^2/10^(SNR/10)/M);
0071 e = randn(M,1)*sigma;
0072 y = A*x+e;
0073
0074
0075
0076
0077
0078
0079
0080 tau = max(1e-4*max(abs(A'*y)),sigma*sqrt(log(N)));
0081
0082 maxiter = 4*N;
0083 err_fun = @(z) (norm(x-z)/norm(x))^2;
0084
0085
0086 in = [];
0087 in.tau = tau;
0088 in.delx_mode = delx_mode;
0089 in.debias = 0;
0090 in.verbose = 0;
0091 in.plots = 0;
0092 in.record = 1;
0093 in.err_fun = err_fun;
0094 tic
0095 out = l1homotopy(A,y,in);
0096 xh = out.x_out;
0097 iter_bpdn = out.iter;
0098 time_bpdn = toc;
0099 gamma_bpdn = out.gamma;
0100 err_bpdn = out.error_table;
0101
0102
0103 xh_old = xh; tau_old = tau;
0104 x_old = x; y_old = y;
0105
0106
0107 in = []; in.type = sType; in.T = Tn; in.randgen = 1;
0108 dx = genSignal(N,in);
0109 x = x_old + dx;
0110 e = randn(M,1)*sigma;
0111 y = A*x+e;
0112
0113
0114
0115 tau = max(1e-4*max(abs(A'*y)),sigma*sqrt(log(N)));
0116
0117
0118
0119
0120
0121
0122 W = tau;
0123 Atr = A'*(A*xh_old-y);
0124 u = -W.*sign(xh_old)-Atr;
0125 pk_old = Atr+u;
0126
0127 in = out;
0128 in.xh_old = xh_old;
0129 in.pk_old = pk_old;
0130 in.u = u;
0131 in.W = W;
0132 in.delx_mode = delx_mode;
0133 in.debias = 0;
0134 in.verbose = 0;
0135 in.plots = 0;
0136 in.record = 1;
0137 in.err_fun = @(z) (norm(x-z)/norm(x))^2;
0138 tic
0139 out = l1homotopy(A,y,in);
0140 xh_dynX = out.x_out;
0141 gamma_dynX = out.gamma;
0142 iter_dynX = out.iter;
0143 time_dynX = toc;
0144
0145
0146 SIM_stack{sim} = [sim, tau, ...
0147 norm(x_old-xh)^2/norm(x)^2, sum(iter_bpdn,2), sum(time_bpdn,2), ...
0148 norm(x-xh_dynX)^2/norm(x)^2, sum(iter_dynX,2), sum(time_dynX,2)];
0149
0150 fprintf('sim %d. tau = %3.4g, (err,iter,time): l1homotopy from scratch-%3.4g,%3.4g,%3.4g; dynX l1homotopy-%3.4g,%3.4g,%3.4g. \n', ...
0151 SIM_stack{sim});
0152
0153
0154 figure(1); plot([x xh xh_dynX]);
0155 title('Comparison betweeen the new and old homotopy code')
0156 end
0157 mS = mean(cell2mat(SIM_stack),1);
0158 fprintf('Average results: maxsim %d. tau = %3.4g, (err,iter,time): l1homotopy from scratch-%3.4g,%3.4g,%3.4g; dynX l1homotopy-%3.4g,%3.4g,%3.4g. \n', maxsim, mS(2:end));