0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 clear
0015 close all
0016
0017
0018
0019
0020
0021
0022
0023 N = 256;
0024
0025 M = 3*N;
0026
0027
0028 T = round(.2*M);
0029
0030
0031 Orth_mat = randn(M,M);
0032 G = Orth_mat(:,1:N);
0033 A = randn(M,N)/sqrt(M);
0034
0035
0036 AtA = A'*A;
0037 iAtA = inv(AtA);
0038 AiAtA = A*iAtA;
0039 AiAtAAt = AiAtA*A';
0040 Q = eye(M)-AiAtAAt;
0041
0042
0043 x = randn(N,1);
0044
0045
0046 q = randperm(M);
0047 e = zeros(M,1);
0048 e(q(1:T)) = randsrc(T,1);
0049
0050
0051 x0 = randn(N,1);
0052 Ax0 = A*x0;
0053 sigma = median(abs(Ax0))/20;
0054 q_y = randn(M,1)*sigma;
0055
0056
0057 y = A*x+e+q_y;
0058 figure(1); clf; plot([y e q_y]);
0059 title('Codeword, sparse errors and small noise');
0060 legend('Codeword', 'Sparse', 'Noise'); shg
0061
0062
0063 tau = 0.01*max(abs(Q*y));
0064
0065
0066
0067
0068
0069
0070 t1_s = cputime;
0071 Qy = Q*y;
0072 [ep, gamma_e, ep_iter] = BPDN_homotopy_function(Q, Qy, tau, 4*M);
0073 t1_e = cputime;
0074 t1 = t1_e-t1_s;
0075
0076 xp = AiAtA'*(y-ep);
0077
0078 figure(2); clf; plot(ep); hold on; plot(e,'ro');
0079 title(['Estimated and original sparse errors with ', num2str(M),' measurements']);
0080 legend('Estimated', 'Original'); shg
0081
0082
0083
0084
0085
0086
0087 m_u =10;
0088
0089 b = randn(m_u,N)/sqrt(M);
0090 T_new = randint(1,1,m_u/5);
0091 d = zeros(m_u,1);
0092 q_new = randperm(m_u);
0093 d(q_new(1:T_new)) = randsrc(T_new,1);
0094 q_w = randn(m_u,1)*sigma;
0095
0096 w = b*x+d+q_w;
0097 F = [A; b];
0098 s = [y;w];
0099 c = [e; d];
0100 q_yw = [q_y; q_w];
0101
0102 iAtAbt = iAtA*b';
0103 biAtAbt = b*iAtAbt;
0104 S_biAtAbt = inv(eye(m_u)+biAtAbt);
0105 AiAtAbt = AiAtA*b';
0106 iAtAbt_S = (iAtAbt*S_biAtAbt);
0107 AiAtAbt_S = A*iAtAbt_S;
0108
0109 FtF = AtA+b'*b;
0110 iFtF = iAtA - iAtAbt_S*iAtAbt';
0111 FiFtF = [AiAtA - AiAtAbt_S*iAtAbt'; iAtAbt'-biAtAbt*S_biAtAbt*iAtAbt'];
0112 FiFtFFt = [AiAtAAt - AiAtAbt_S*AiAtAbt' AiAtAbt-AiAtAbt_S*biAtAbt; AiAtAbt'-biAtAbt*AiAtAbt_S' biAtAbt-biAtAbt*S_biAtAbt*biAtAbt];
0113 P = eye(M+m_u)-FiFtFFt;
0114
0115 dp = w-b*xp;
0116 z_d = sign(dp);
0117 cp_h = [ep; dp];
0118 gamma_n = M+find(abs(dp)>2*eps);
0119 gamma_n_old = gamma_n;
0120 gamma_h = [gamma_e; gamma_n];
0121 epsilon = 0;
0122 e0 = 0;
0123
0124 QgQ = Q(gamma_e,gamma_e);
0125 PgP = P(gamma_h,gamma_h);
0126 uQ = AiAtAbt_S(gamma_e,:);
0127 vQ = AiAtAbt(gamma_e,:);
0128 QgQ_update = QgQ + uQ*vQ';
0129 PgP_update = [[QgQ_update; P(gamma_n,gamma_e)] P(gamma_h,gamma_n)];
0130 PgP = PgP_update;
0131
0132 iQgQ = inv(QgQ);
0133 iQgQ_update = iQgQ - (iQgQ*uQ)*(inv(eye(m_u)+vQ'*iQgQ*uQ))*(vQ'*iQgQ);
0134
0135 P11 = QgQ_update;
0136 P12 = P(gamma_e,gamma_n);
0137 P21 = P12';
0138 P22 = P(gamma_n,gamma_n);
0139 S_P = inv(P22-P21*iQgQ_update*P12);
0140 iP11_P12 = iQgQ_update*P12;
0141 iPgP_update = [iQgQ_update+(iP11_P12*S_P)*iP11_P12' -iP11_P12*S_P; -S_P*iP11_P12' S_P];
0142 iPgP = iPgP_update;
0143
0144 pk_old = P*(cp_h-s);
0145
0146
0147 [cp_h gamma_h cp_h_iter th] = DynamicSeq_REC_function(P, s, iPgP, cp_h, gamma_h, gamma_n, pk_old, tau, M, m_u, 4*M);
0148 figure(3); clf; plot(cp_h); hold on; plot(c,'ro');
0149 title(['Estimated and original sparse errors after new ', num2str(m_u),' measurements']);
0150 legend('Estimated', 'Original'); shg
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 [cp2, gamma_c2, cp2_iter, t2] = BPDN_homotopy_function(P, P*s, tau, 4*M);
0166
0167
0168 pk2 = P*(cp2-s);
0169 pk_h = P*(cp_h-s);
0170
0171
0172 disp(' ');
0173 disp('old_homotopy , new_homotopy , update_homotopy')
0174 time_table = [t1 t2 th]
0175 iter_table = [ep_iter cp2_iter cp_h_iter]
0176
0177 figure(4); subplot(2,1,1); hold on; plot(cp_h-cp2);
0178 title('Difference between the solution of BPDN homotopy and REC update')
0179 subplot(2,1,2); hold on; plot(pk2-pk_h); drawnow
0180 title('Difference between the primal constraints of BPDN homotopy and REC update')