comparison toolboxes/alps/ALPS/AlgebraicPursuit.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
comparison
equal deleted inserted replaced
153:af307f247ac7 154:0de08f68256b
1 function [x_hat, numiter, time, x_path] = AlgebraicPursuit(y, Phi, K, varargin)
2 % =========================================================================
3 % Algebraic Pursuit algorithms - Beta Version
4 % =========================================================================
5 % Algebraic Pursuit (ALPS) algorithms are accelerated hard thresholding methods
6 % on sparse recovery of linear inverse systems. In particular, let
7 % Phi : M x N real matrix (M < N)
8 % x* : N x 1 K-sparse data vector
9 % n : N x 1 additive noise vector
10 % then, y = Phi x* + n is the undersampled M x 1 measurement vector. ALPS
11 % solve the following minimization problem
12 % minimize ||y - Phi x||^2 subject to x is K-sparse vector.
13 %
14 % Detailed discussion on the algorithm can be found in
15 % [1] "On Accelerated Hard Thresholding Methods for Sparse Approximation", written
16 % by Volkan Cevher, Technical Report, 2011.
17 % =========================================================================
18 % INPUT ARGUMENTS:
19 % y M x 1 undersampled measurement vector.
20 % Phi M x N regression matrix.
21 % K Sparsity of underlying vector x* or desired
22 % sparsity of solution.
23 % varargin Set of parameters. These are:
24 %
25 % memory,... Memory (momentum) of proposed algorithm.
26 % Possible values are 0,1,'infty' for memoryless,
27 % one memory and infinity memory ALPS,
28 % respectively. Default value: memory = 0.
29 % tol,... Early stopping tolerance. Default value: tol =
30 % 1-e5.
31 % ALPSiters,... Maximum number of algorithm iterations. Default
32 % value: 300.
33 % mode, ... According to [1], possible values are
34 % [0,1,2,4,5,6]. This value comes from the binary
35 % representation of the parameters:
36 % (solveNewtob, gradientDescentx, solveNewtonx),
37 % which are explained next. Default value = 0.
38 % mu,... Variable that controls the step size selection.
39 % When mu = 0, step size is computed adaptively
40 % per iteration. Default value: mu = 0.
41 % tau,... Variable that controls the momentum in
42 % non-memoryless case. Ignored in memoryless
43 % case. User can insert as value a function handle on tau.
44 % Description given below. Default value: tau = -1.
45 % CGiters,... Maximum iterations for Conjugate-Gradients method.
46 % CGtol,... Tolerance variable for Conjugate-Gradients method.
47 % verbose verbose = 1 prints out execution infromation.
48 % =========================================================================
49 % DESCRIPTION OF MODE VARIABLE:
50 % solveNewtonb,... If solveNewtonb == 1: Corresponds to solving a
51 % Newton system restricted to a sparse support.
52 % It is implemented via conjugate gradients. If
53 % solveNewtonb == 0: Step size selection as
54 % described in eqs. (12) and (13) in [1]. Default
55 % value: solveNewtonb = 0. For infty memory case,
56 % solveNewtonb = 0.
57 % gradientDescentx,... If gradientDescentx == 1: single gradient
58 % update of x_{i+1} restricted ot its support
59 % with line search. Default value:
60 % gradientDescentx = 1.
61 % solveNewtonx,... If solveNewtonx == 1: Akin to Hard Thresholding
62 % Pursuit (c.f. Simon Foucart, "Hard Thresholding
63 % Pursuit," preprint, 2010). Default vale:
64 % solveNewtonx = 0.
65 % =========================================================================
66 % DESCRIPTION OF SPECIAL TAU VALUES:
67 % tau = -1,... Tau computed as the minimized of the objective
68 % function:
69 %
70 % <u - Ax_i, Phi(x_i - x_{i-1})>
71 % tau = -----------------------------.
72 % <u - Ax_i, Phi(x_i - x_{i-1})>
73 %
74 % tau = 0,... Follows FISTA weight configuration at each
75 % iteration. For more information, please read "A
76 % Fast Iterative Shrinkage-Thresholding Algorithm
77 % for Linear Inverse Problems", written by A.
78 % Beck and M. Teboulle, SIAM J. Imaging Sciences,
79 % vol. 2, no. 1, 2009.
80 % =========================================================================
81 % OUTPUT ARGUMENTS:
82 % x_hat N x 1 recovered K-sparse vector.
83 % numiter Number of iterations executed.
84 % time Execution time in seconds.
85 % x_path Keeps a series of computed N x 1 K-sparse vectors
86 % until the end of the iterative process.
87 % =========================================================================
88 % 01/04/2011, by Anastasios Kyrillidis. anastasios.kyrillidis@epfl.ch, EPFL.
89 % =========================================================================
90 % cgsolve.m is written by Justin Romberg, Caltech, Oct. 2005.
91 % Email: jrom@acm.caltech.edu
92 % =========================================================================
93 % This work was supported in part by the European Commission under Grant
94 % MIRG-268398 and DARPA KeCoM program #11-DARPA-1055. VC also would like
95 % to acknowledge Rice University for his Faculty Fellowship.
96 % =========================================================================
97
98 x_hat = 0;
99 time = 0;
100 x_path = 0;
101
102 params.memory = 0;
103 params.tol = 1e-5;
104 params.ALPSiters = 300;
105 params.mode = 0;
106 params.tau = 1/2;
107 params.memory = 0;
108 params.cg_maxiter = 50;
109 params.cg_tol = 1e-8;
110 params.useCG = 0;
111 params.verbose = 0;
112 params.mu = 0;
113
114 for in_arg = 1:2:length(varargin)
115 if (strcmp(varargin{in_arg}, 'memory'))
116 params.memory = varargin{in_arg+1};
117 end
118 if (strcmp(varargin{in_arg}, 'mode'))
119 params.mode = varargin{in_arg+1};
120 end
121 if (strcmp(varargin{in_arg}, 'tolerance'))
122 params.tol = varargin{in_arg+1};
123 end
124 if (strcmp(varargin{in_arg}, 'ALPSiterations'))
125 params.ALPSiters = varargin{in_arg+1};
126 end
127 if (strcmp(varargin{in_arg}, 'tau'))
128 params.tau = varargin{in_arg+1};
129 end
130 if (strcmp(varargin{in_arg}, 'mu'))
131 params.mu = varargin{in_arg+1};
132 end
133 if (strcmp(varargin{in_arg}, 'useCG'))
134 params.useCG = varargin{in_arg+1};
135 end
136 if (strcmp(varargin{in_arg}, 'CGiters'))
137 params.cg_maxiter = varargin{in_arg+1};
138 end
139 if (strcmp(varargin{in_arg}, 'CGtol'))
140 params.cg_tol = varargin{in_arg+1};
141 end
142 if (strcmp(varargin{in_arg}, 'verbose'))
143 params.verbose = varargin{in_arg+1};
144 end;
145 end;
146
147 %% Check input
148
149 if (ischar(params.memory))
150 if ~(sum(params.memory == 'infty') == 5)
151 disp('ERROR: Memory variable takes positive integer values or "infty" value.');
152 numiter = -1;
153 return;
154 end;
155 elseif (params.memory < 0 || ~isinteger(uint8(params.memory)))
156 disp('ERROR: Memory variable takes positive integer values or "infty" value.');
157 numiter = -1;
158 return;
159 end;
160
161 if (params.mode ~= 0 && params.mode ~= 1 && params.mode ~= 2 && params.mode ~= 4 && params.mode ~= 5 && params.mode ~= 6)
162 disp('ERROR: Mode variable takes values from range [0,1,2,4,5,6].');
163 numiter = -1;
164 return;
165 end;
166
167 if (params.tol < 0 || ~isnumeric(params.tol))
168 disp('ERROR: tolerance variable must be positive.');
169 numiter = -1;
170 return;
171 end;
172
173
174 if (params.mode == 0 || params.mode == 2)
175 params.useCG = 0;
176 end;
177
178 y = y(:);
179
180 M_y = length(y);
181 [M_Phi, tmpArg] = size(Phi);
182
183 if (params.mode == 4 || params.mode == 5 || params.mode == 6)
184 if (M_Phi < 2*K)
185 disp('WARNING: Newton system may be ill-conditioned... Press any key to continue');
186 pause;
187 end;
188 end;
189
190 [params.solveNewtonb, params.gradientDescentx, params.solveNewtonx] = configuration(params.mode);
191
192 if (M_y ~= M_Phi)
193 error('Inconsistent sampling matrix...');
194 end;
195
196 switch params.memory
197 case 0,
198 tic;
199 [x_hat, numiter, x_path] = zero_ALPS(y, Phi, K, params);
200 time = toc;
201 if (params.verbose == 1)
202 str = sprintf('%d-ALPS(%d) time: %s', params.memory, params.mode, num2str(time));
203 disp(str);
204 str = sprintf('Number of iterations: %d', numiter);
205 disp(str);
206 end;
207 case 1,
208 tic;
209 [x_hat, numiter, x_path] = one_ALPS(y, Phi, K, params);
210 time = toc;
211 if (params.verbose == 1)
212 if (isa(params.tau,'float'))
213 if (params.tau == 0)
214 str = sprintf('%d-ALPS(%d) - fista tau - time: %s', params.memory, params.mode, num2str(time));
215 elseif (params.tau == -1)
216 str = sprintf('%d-ALPS(%d) - optimized tau - time: %s', params.memory, params.mode, num2str(time));
217 else
218 str = sprintf('%d-ALPS(%d) - tau = %.3f - time: %s', params.memory, params.mode, params.tau, num2str(time));
219 end;
220 elseif (isa(params.tau, 'function_handle'))
221 str = sprintf('%d-ALPS(%d) - user derfined tau - time: %s', params.memory, params.mode, num2str(time));
222 end;
223 disp(str);
224 str = sprintf('Number of iterations: %d', numiter);
225 disp(str);
226 end;
227 case 'infty',
228 tic;
229 [x_hat, numiter, x_path] = infty_ALPS(y, Phi, K, params);
230 time = toc;
231 if (params.verbose == 1)
232 if (isa(params.tau,'float'))
233 if (params.tau == -1)
234 str = sprintf('infty-ALPS(%d) - optimized tau - time: %s', params.mode, num2str(time));
235 else
236 str = sprintf('infty-ALPS(%d) - tau = %.3f - time: %s', params.mode, params.tau, num2str(time));
237 end;
238 elseif (isa(params.tau,'function_handle'))
239 str = sprintf('infty-ALPS(%d) - user derfined tau - time: %s', params.mode, num2str(time));
240 end;
241 disp(str);
242 str = sprintf('Number of iterations: %d', numiter);
243 disp(str);
244 end;
245 otherwise
246 tic;
247 [x_hat, numiter, x_path] = l_ALPS(y, Phi, K, params);
248 time = toc;
249 if (params.verbose == 1)
250 if (isa(params.tau,'float'))
251 if (params.tau == -1)
252 str = sprintf('%d-ALPS(%d) - optimized tau - time: %s', params.memory, params.mode, num2str(time));
253 else
254 str = sprintf('%d-ALPS(%d) - tau = %.3f - time: %s', params.memory, params.mode, params.tau, num2str(time));
255 end;
256 elseif (isa(params.tau,'function_handle'))
257 str = sprintf('%d-ALPS(%d) - user derfined tau - time: %s', params.memory, params.mode, num2str(time));
258 end;
259 disp(str);
260 str = sprintf('Number of iterations: %d', numiter);
261 disp(str);
262 end;
263 end;
264