Mercurial > hg > smallbox
comparison DL/RLS-DLA/SolveFISTA.m @ 60:ad36f80e2ccf
(none)
author | idamnjanovic |
---|---|
date | Tue, 15 Mar 2011 12:20:59 +0000 |
parents | 6416fc12f2b8 |
children |
comparison
equal
deleted
inserted
replaced
59:23f9dd7b9d78 | 60:ad36f80e2ccf |
---|---|
1 % Copyright ©2010. The Regents of the University of California (Regents). | |
2 % All Rights Reserved. Contact The Office of Technology Licensing, | |
3 % UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, | |
4 % (510) 643-7201, for commercial licensing opportunities. | |
5 | |
6 % Authors: Arvind Ganesh, Allen Y. Yang, Zihan Zhou. | |
7 % Contact: Allen Y. Yang, Department of EECS, University of California, | |
8 % Berkeley. <yang@eecs.berkeley.edu> | |
9 | |
10 % IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
11 % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
12 % ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
13 % REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
14 | |
15 % REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED | |
16 % TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
17 % PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, | |
18 % PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO | |
19 % PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
20 | |
21 %% This function is modified from Matlab code proximal_gradient_bp | |
22 | |
23 function [x_hat,nIter] = SolveFISTA(A,b, varargin) | |
24 | |
25 % b - m x 1 vector of observations/data (required input) | |
26 % A - m x n measurement matrix (required input) | |
27 % | |
28 % tol - tolerance for stopping criterion. | |
29 % - DEFAULT 1e-7 if omitted or -1. | |
30 % maxIter - maxilambdam number of iterations | |
31 % - DEFAULT 10000, if omitted or -1. | |
32 % lineSearchFlag - 1 if line search is to be done every iteration | |
33 % - DEFAULT 0, if omitted or -1. | |
34 % continuationFlag - 1 if a continuation is to be done on the parameter lambda | |
35 % - DEFAULT 1, if omitted or -1. | |
36 % eta - line search parameter, should be in (0,1) | |
37 % - ignored if lineSearchFlag is 0. | |
38 % - DEFAULT 0.9, if omitted or -1. | |
39 % lambda - relaxation parameter | |
40 % - ignored if continuationFlag is 1. | |
41 % - DEFAULT 1e-3, if omitted or -1. | |
42 % outputFileName - Details of each iteration are dumped here, if provided. | |
43 % | |
44 % x_hat - estimate of coeeficient vector | |
45 % numIter - number of iterations until convergence | |
46 % | |
47 % | |
48 % References | |
49 % "Robust PCA: Exact Recovery of Corrupted Low-Rank Matrices via Convex Optimization", J. Wright et al., preprint 2009. | |
50 % "An Accelerated Proximal Gradient Algorithm for Nuclear Norm Regularized Least Squares problems", K.-C. Toh and S. Yun, preprint 2009. | |
51 % | |
52 % Arvind Ganesh, Summer 2009. Questions? abalasu2@illinois.edu | |
53 | |
54 DEBUG = 0 ; | |
55 | |
56 STOPPING_GROUND_TRUTH = -1; | |
57 STOPPING_DUALITY_GAP = 1; | |
58 STOPPING_SPARSE_SUPPORT = 2; | |
59 STOPPING_OBJECTIVE_VALUE = 3; | |
60 STOPPING_SUBGRADIENT = 4; | |
61 STOPPING_DEFAULT = STOPPING_SUBGRADIENT; | |
62 | |
63 stoppingCriterion = STOPPING_DEFAULT; | |
64 maxIter = 1000 ; | |
65 tolerance = 1e-3; | |
66 [m,n] = size(A) ; | |
67 x0 = zeros(n,1) ; | |
68 xG = []; | |
69 | |
70 %% Initializing optimization variables | |
71 t_k = 1 ; | |
72 t_km1 = 1 ; | |
73 L0 = 1 ; | |
74 G = A'*A ; | |
75 nIter = 0 ; | |
76 c = A'*b ; | |
77 lambda0 = 0.99*L0*norm(c,inf) ; | |
78 eta = 0.6 ; | |
79 lambda_bar = 1e-4*lambda0 ; | |
80 xk = zeros(n,1) ; | |
81 lambda = lambda0 ; | |
82 L = L0 ; | |
83 beta = 1.5 ; | |
84 | |
85 % Parse the optional inputs. | |
86 if (mod(length(varargin), 2) ~= 0 ), | |
87 error(['Extra Parameters passed to the function ''' mfilename ''' lambdast be passed in pairs.']); | |
88 end | |
89 parameterCount = length(varargin)/2; | |
90 | |
91 for parameterIndex = 1:parameterCount, | |
92 parameterName = varargin{parameterIndex*2 - 1}; | |
93 parameterValue = varargin{parameterIndex*2}; | |
94 switch lower(parameterName) | |
95 case 'stoppingcriterion' | |
96 stoppingCriterion = parameterValue; | |
97 case 'groundtruth' | |
98 xG = parameterValue; | |
99 case 'tolerance' | |
100 tolerance = parameterValue; | |
101 case 'linesearchflag' | |
102 lineSearchFlag = parameterValue; | |
103 case 'lambda' | |
104 lambda_bar = parameterValue; | |
105 case 'maxiteration' | |
106 maxIter = parameterValue; | |
107 case 'isnonnegative' | |
108 isNonnegative = parameterValue; | |
109 case 'continuationflag' | |
110 continuationFlag = parameterValue; | |
111 case 'initialization' | |
112 xk = parameterValue; | |
113 if ~all(size(xk)==[n,1]) | |
114 error('The dimension of the initial xk does not match.'); | |
115 end | |
116 case 'eta' | |
117 eta = parameterValue; | |
118 if ( eta <= 0 || eta >= 1 ) | |
119 disp('Line search parameter out of bounds, switching to default 0.9') ; | |
120 eta = 0.9 ; | |
121 end | |
122 otherwise | |
123 error(['The parameter ''' parameterName ''' is not recognized by the function ''' mfilename '''.']); | |
124 end | |
125 end | |
126 clear varargin | |
127 | |
128 if stoppingCriterion==STOPPING_GROUND_TRUTH && isempty(xG) | |
129 error('The stopping criterion must provide the ground truth value of x.'); | |
130 end | |
131 | |
132 keep_going = 1 ; | |
133 nz_x = (abs(xk)> eps*10); | |
134 f = 0.5*norm(b-A*xk)^2 + lambda_bar * norm(xk,1); | |
135 xkm1 = xk; | |
136 while keep_going && (nIter < maxIter) | |
137 nIter = nIter + 1 ; | |
138 | |
139 yk = xk + ((t_km1-1)/t_k)*(xk-xkm1) ; | |
140 | |
141 stop_backtrack = 0 ; | |
142 | |
143 temp = G*yk - c ; % gradient of f at yk | |
144 | |
145 while ~stop_backtrack | |
146 | |
147 gk = yk - (1/L)*temp ; | |
148 | |
149 xkp1 = soft(gk,lambda/L) ; | |
150 | |
151 temp1 = 0.5*norm(b-A*xkp1)^2 ; | |
152 temp2 = 0.5*norm(b-A*yk)^2 + (xkp1-yk)'*temp + (L/2)*norm(xkp1-yk)^2 ; | |
153 | |
154 if temp1 <= temp2 | |
155 stop_backtrack = 1 ; | |
156 else | |
157 L = L*beta ; | |
158 end | |
159 | |
160 end | |
161 | |
162 switch stoppingCriterion | |
163 case STOPPING_GROUND_TRUTH | |
164 keep_going = norm(xG-xkp1)>tolerance; | |
165 case STOPPING_SUBGRADIENT | |
166 sk = L*(yk-xkp1) + G*(xkp1-yk) ; | |
167 keep_going = norm(sk) > tolerance*L*max(1,norm(xkp1)); | |
168 case STOPPING_SPARSE_SUPPORT | |
169 % compute the stopping criterion based on the change | |
170 % of the number of non-zero components of the estimate | |
171 nz_x_prev = nz_x; | |
172 nz_x = (abs(xkp1)>eps*10); | |
173 num_nz_x = sum(nz_x(:)); | |
174 num_changes_active = (sum(nz_x(:)~=nz_x_prev(:))); | |
175 if num_nz_x >= 1 | |
176 criterionActiveSet = num_changes_active / num_nz_x; | |
177 keep_going = (criterionActiveSet > tolerance); | |
178 end | |
179 case STOPPING_OBJECTIVE_VALUE | |
180 % compute the stopping criterion based on the relative | |
181 % variation of the objective function. | |
182 prev_f = f; | |
183 f = 0.5*norm(b-A*xkp1)^2 + lambda_bar * norm(xk,1); | |
184 criterionObjective = abs(f-prev_f)/(prev_f); | |
185 keep_going = (criterionObjective > tolerance); | |
186 case STOPPING_DUALITY_GAP | |
187 error('Duality gap is not a valid stopping criterion for PGBP.'); | |
188 otherwise | |
189 error('Undefined stopping criterion.'); | |
190 end | |
191 | |
192 lambda = max(eta*lambda,lambda_bar) ; | |
193 | |
194 | |
195 t_kp1 = 0.5*(1+sqrt(1+4*t_k*t_k)) ; | |
196 | |
197 t_km1 = t_k ; | |
198 t_k = t_kp1 ; | |
199 xkm1 = xk ; | |
200 xk = xkp1 ; | |
201 end | |
202 | |
203 x_hat = xk ; | |
204 | |
205 function y = soft(x,T) | |
206 if sum(abs(T(:)))==0 | |
207 y = x; | |
208 else | |
209 y = max(abs(x) - T, 0); | |
210 y = sign(x).*y; | |
211 end |