annotate toolboxes/alps/ALPS/zero_ALPS.m @ 154:0de08f68256b ivand_dev

ALPS toolbox - Algebraic Pursuit added to smallbox
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Fri, 12 Aug 2011 11:17:47 +0100
parents
children
rev   line source
ivan@154 1 function [x_hat, numiter, x_path] = zero_ALPS(y, Phi, K, params)
ivan@154 2 % =========================================================================
ivan@154 3 % 0-ALPS(#) algorithm - Beta Version
ivan@154 4 % =========================================================================
ivan@154 5 % Algebraic Pursuit (ALPS) algorithm with memoryless acceleration.
ivan@154 6 %
ivan@154 7 % Detailed discussion on the algorithm can be found in
ivan@154 8 % [1] "On Accelerated Hard Thresholding Methods for Sparse Approximation", written
ivan@154 9 % by Volkan Cevher, Technical Report, 2011.
ivan@154 10 % =========================================================================
ivan@154 11 % INPUT ARGUMENTS:
ivan@154 12 % y M x 1 undersampled measurement vector.
ivan@154 13 % Phi M x N regression matrix.
ivan@154 14 % K Sparsity of underlying vector x* or desired
ivan@154 15 % sparsity of solution.
ivan@154 16 % params Structure of parameters. These are:
ivan@154 17 %
ivan@154 18 % tol,... Early stopping tolerance. Default value: tol =
ivan@154 19 % 1-e5
ivan@154 20 % ALPSiters,... Maximum number of algorithm iterations. Default
ivan@154 21 % value: 300.
ivan@154 22 % mode, ... According to [1], possible values are
ivan@154 23 % [0,1,2,4,5,6]. This value comes from the binary
ivan@154 24 % representation of the parameters:
ivan@154 25 % (solveNewtob, gradientDescentx, solveNewtonx),
ivan@154 26 % which are explained next. Default value = 0.
ivan@154 27 % solveNewtonb,... If solveNewtonb == 1: Corresponds to solving a
ivan@154 28 % Newton system restricted to a sparse support.
ivan@154 29 % It is implemented via conjugate gradients.
ivan@154 30 % If solveNewtonb == 0: Step size selection as described
ivan@154 31 % in eqs. (12) and (13) in [1].
ivan@154 32 % Default value: solveNewtonb = 0.
ivan@154 33 % gradientDescentx,... If gradientDescentx == 1: single gradient
ivan@154 34 % update of x_{i+1} restricted ot its support with
ivan@154 35 % line search. Default value: gradientDescentx =
ivan@154 36 % 1.
ivan@154 37 % solveNewtonx,... If solveNewtonx == 1: Akin to Hard Thresholding Pursuit
ivan@154 38 % (c.f. Simon Foucart, "Hard Thresholding Pursuit,"
ivan@154 39 % preprint, 2010). Default vale: solveNewtonx = 0
ivan@154 40 % mu,... Variable that controls the step size selection.
ivan@154 41 % When mu = 0, step size is computed adaptively
ivan@154 42 % per iteration. Default value: mu = 0.
ivan@154 43 % cg_maxiter,... Maximum iterations for Conjugate-Gradients method.
ivan@154 44 % cg_tol Tolerance variable for Conjugate-Gradients method.
ivan@154 45 % =========================================================================
ivan@154 46 % OUTPUT ARGUMENTS:
ivan@154 47 % x_hat N x 1 recovered K-sparse vector.
ivan@154 48 % numiter Number of iterations executed.
ivan@154 49 % x_path Keeps a series of computed N x 1 K-sparse vectors
ivan@154 50 % until the end of the iterative process.
ivan@154 51 % =========================================================================
ivan@154 52 % 01/04/2011, by Anastasios Kyrillidis. anastasios.kyrillidis@epfl.ch, EPFL.
ivan@154 53 % =========================================================================
ivan@154 54 % cgsolve.m is written by Justin Romberg, Caltech, Oct. 2005.
ivan@154 55 % Email: jrom@acm.caltech.edu
ivan@154 56 % =========================================================================
ivan@154 57 % This work was supported in part by the European Commission under Grant
ivan@154 58 % MIRG-268398 and DARPA KeCoM program #11-DARPA-1055. VC also would like
ivan@154 59 % to acknowledge Rice University for his Faculty Fellowship.
ivan@154 60 % =========================================================================
ivan@154 61
ivan@154 62 [tmpArg, N] = size(Phi);
ivan@154 63
ivan@154 64 %% Initialize transpose of measurement matrix
ivan@154 65
ivan@154 66 Phi_t = Phi';
ivan@154 67
ivan@154 68 %% Initialize to zero vector
ivan@154 69 x_cur = zeros(N,1);
ivan@154 70 X_i = [];
ivan@154 71
ivan@154 72 x_path = zeros(N, params.ALPSiters);
ivan@154 73
ivan@154 74 %% CG params
ivan@154 75 if (params.mode == 1 || params.mode == 4 || params.mode == 5 || params.mode == 6)
ivan@154 76 cg_verbose = 0;
ivan@154 77 cg_A = Phi_t*Phi;
ivan@154 78 cg_b = Phi_t*y;
ivan@154 79 end;
ivan@154 80
ivan@154 81 %% Determine step size selection strategy
ivan@154 82 function_mu = 0;
ivan@154 83 adaptive_mu = 0;
ivan@154 84
ivan@154 85 if (isa(params.mu,'float'))
ivan@154 86 function_mu = 0;
ivan@154 87 if (params.mu == 0)
ivan@154 88 adaptive_mu = 1;
ivan@154 89 else
ivan@154 90 adaptive_mu = 0;
ivan@154 91 end;
ivan@154 92 elseif (isa(params.mu,'function_handle'))
ivan@154 93 function_mu = 1;
ivan@154 94 end;
ivan@154 95
ivan@154 96 %% Help variables
ivan@154 97 complementary_Xi = ones(N,1);
ivan@154 98
ivan@154 99 i = 1;
ivan@154 100 %% 0-ALPS(#)
ivan@154 101 while (i <= params.ALPSiters)
ivan@154 102 x_path(:,i) = x_cur;
ivan@154 103 x_prev = x_cur;
ivan@154 104
ivan@154 105 % Compute the residual
ivan@154 106 if (i == 1)
ivan@154 107 res = y;
ivan@154 108 else
ivan@154 109 Phi_x_cur = Phi(:,X_i)*x_cur(X_i);
ivan@154 110 res = y - Phi_x_cur;
ivan@154 111 end;
ivan@154 112
ivan@154 113 % Compute the derivative
ivan@154 114 der = Phi_t*res;
ivan@154 115
ivan@154 116 % Determine S_i set via eq. (11)
ivan@154 117 complementary_Xi(X_i) = 0;
ivan@154 118 [tmpArg, ind_der] = sort(abs(der).*complementary_Xi, 'descend');
ivan@154 119 complementary_Xi(X_i) = 1;
ivan@154 120 S_i = [X_i; ind_der(1:K)];
ivan@154 121
ivan@154 122 ider = der(S_i);
ivan@154 123 if (params.solveNewtonb == 1)
ivan@154 124 % Compute least squares solution of the system A*y = (A*A)x using CG
ivan@154 125 if (params.useCG == 1)
ivan@154 126 [b, tmpArg, tmpArg] = cgsolve(cg_A(S_i, S_i), cg_b(S_i), params.cg_tol, params.cg_maxiter, cg_verbose);
ivan@154 127 else
ivan@154 128 b = cg_A(S_i,S_i)\cg_b(S_i);
ivan@154 129 end;
ivan@154 130 else
ivan@154 131 % Step size selection via eq. (12) and eq. (13)
ivan@154 132 if (adaptive_mu)
ivan@154 133 Pder = Phi(:,S_i)*ider;
ivan@154 134 mu_bar = ider'*ider/(Pder'*Pder);
ivan@154 135 b = x_cur(S_i) + (mu_bar)*ider;
ivan@154 136 elseif (function_mu)
ivan@154 137 b = x_cur(S_i) + params.mu(i)*ider;
ivan@154 138 else
ivan@154 139 b = x_cur(S_i) + params.mu*ider;
ivan@154 140 end;
ivan@154 141 end;
ivan@154 142
ivan@154 143 % Hard-threshold b and compute X_{i+1}
ivan@154 144 [tmpArg, ind_b] = sort(abs(b), 'descend');
ivan@154 145 x_cur = zeros(N,1);
ivan@154 146 x_cur(S_i(ind_b(1:K))) = b(ind_b(1:K));
ivan@154 147 X_i = S_i(ind_b(1:K));
ivan@154 148
ivan@154 149 if (params.gradientDescentx == 1)
ivan@154 150 % Calculate gradient of estimated vector x_cur
ivan@154 151 Phi_x_cur = Phi(:,X_i)*x_cur(X_i);
ivan@154 152 res = y - Phi_x_cur;
ivan@154 153 der = Phi_t*res;
ivan@154 154 ider = der(X_i);
ivan@154 155
ivan@154 156 if (adaptive_mu)
ivan@154 157 Pder = Phi(:,X_i)*ider;
ivan@154 158 mu_bar = ider'*ider/(Pder'*Pder);
ivan@154 159 x_cur(X_i) = x_cur(X_i) + mu_bar*ider;
ivan@154 160 elseif (function_mu)
ivan@154 161 x_cur(X_i) = x_cur(X_i) + params.mu(i)*ider;
ivan@154 162 else x_cur(X_i) = x_cur(X_i) + params.mu*ider;
ivan@154 163 end;
ivan@154 164 elseif (params.solveNewtonx == 1)
ivan@154 165 % Similar to HTP
ivan@154 166 if (params.useCG == 1)
ivan@154 167 [v, tmpArg, tmpArg] = cgsolve(cg_A(X_i, X_i), cg_b(X_i), params.cg_tol, params.cg_maxiter, cg_verbose);
ivan@154 168 else
ivan@154 169 v = cg_A(X_i,X_i)\cg_b(X_i);
ivan@154 170 end;
ivan@154 171 x_cur(X_i) = v;
ivan@154 172 end;
ivan@154 173
ivan@154 174 % Test stopping criterion
ivan@154 175 if (i > 1) && (norm(x_cur - x_prev) < params.tol*norm(x_cur))
ivan@154 176 break;
ivan@154 177 end;
ivan@154 178 i = i + 1;
ivan@154 179
ivan@154 180 end;
ivan@154 181
ivan@154 182 x_hat = x_cur;
ivan@154 183 numiter = i;
ivan@154 184
ivan@154 185 if (i > params.ALPSiters)
ivan@154 186 x_path = x_path(:,1:numiter-1);
ivan@154 187 else
ivan@154 188 x_path = x_path(:,1:numiter);
ivan@154 189 end;