📄 gpsr_bb.m
字号:
function [x,x_debias,objective,times,debias_start,mses]= ... GPSR_BB(y,A,tau,varargin)%% GPSR_BB version 5.0, December 4, 2007%% This function solves the convex problem % arg min_x = 0.5*|| y - A x ||_2^2 + tau || x ||_1% using the algorithm GPSR-BB, described in the following paper%% "Gradient Projection for Sparse Reconstruction: Application% to Compressed Sensing and Other Inverse Problems"% by Mario A. T. Figueiredo, Robert D. Nowak, Stephen J. Wright,% Journal of Selected Topics on Signal Processing, December 2007% (to appear).%% % -----------------------------------------------------------------------% Copyright (2007): Mario Figueiredo, Robert Nowak, Stephen Wright% % GPSR is distributed under the terms% of the GNU General Public License 2.0.% % Permission to use, copy, modify, and distribute this software for% any purpose without fee is hereby granted, provided that this entire% notice is included in all copies of any software which is or includes% a copy or modification of this software and in all copies of the% supporting documentation for such software.% This software is being provided "as is", without any express or% implied warranty. In particular, the authors do not make any% representation or warranty of any kind concerning the merchantability% of this software or its fitness for any particular purpose."% ----------------------------------------------------------------------% % % Please check for the latest version of the code and paper at% www.lx.it.pt/~mtf/GPSR%% ===== Required inputs =============%% y: 1D vector or 2D array (image) of observations% % A: if y and x are both 1D vectors, A can be a % k*n (where k is the size of y and n the size of x)% matrix or a handle to a function that computes% products of the form A*v, for some vector v.% In any other case (if y and/or x are 2D arrays), % A has to be passed as a handle to a function which computes % products of the form A*x; another handle to a function % AT which computes products of the form A'*x is also required % in this case. The size of x is determined as the size% of the result of applying AT.%% tau: usually, a non-negative real parameter of the objective % function (see above). It can also be an array, the same % size as x, with non-negative entries; in this case,% the objective function weights differently each element % of x, that is, it becomes% 0.5*|| y - A x ||_2^2 + tau^T * abs(x)%% ===== Optional inputs =============%% % 'AT' = function handle for the function that implements% the multiplication by the conjugate of A, when A% is a function handle. If A is an array, AT is ignored.%% 'StopCriterion' = type of stopping criterion to use% 0 = algorithm stops when the relative % change in the number of non-zero % components of the estimate falls % below 'ToleranceA'% 1 = stop when the relative % change in the objective function % falls below 'ToleranceA'% 2 = stop when the norm of the difference between % two consecutive estimates, divided by the norm% of one of them falls below toleranceA% 3 = stop when LCP estimate of relative% distance to solution% falls below 'ToleranceA'% 4 = stop when the objective function % becomes equal or less than toleranceA.% Default = 3.%% 'ToleranceA' = stopping threshold; Default = 0.01% % 'Debias' = debiasing option: 1 = yes, 0 = no.% Default = 0.%% 'ToleranceD' = stopping threshold for the debiasing phase:% Default = 0.0001.% If no debiasing takes place, this parameter,% if present, is ignored.%% 'MaxiterA' = maximum number of iterations allowed in the% main phase of the algorithm.% Default = 10000%% 'MiniterA' = minimum number of iterations performed in the% main phase of the algorithm.% Default = 5%% 'MaxiterD' = maximum number of iterations allowed in the% debising phase of the algorithm.% Default = 200%% 'MiniterD' = minimum number of iterations to perform in the% debiasing phase of the algorithm.% Default = 5%% 'Initialization' must be one of {0,1,2,array}% 0 -> Initialization at zero. % 1 -> Random initialization.% 2 -> initialization with A'*y.% array -> initialization provided by the user.% Default = 0;%% 'Monotone' = enforce monotonic decrease in f, or not? % any nonzero -> enforce monotonicity% 0 -> don't enforce monotonicity.% Default = 1;%% 'Continuation' = Continuation or not (1 or 0) % Specifies the choice for a continuation scheme,% in which we start with a large value of tau, and% then decrease tau until the desired value is % reached. At each value, the solution obtained% with the previous values is used as initialization.% Default = 0%% 'ContinuationSteps' = Number of steps in the continuation procedure;% ignored if 'Continuation' equals zero.% Default = 5.% % 'FirstTauFactor' = Initial tau value, if using continuation, is% obtained by multiplying the given tau by % this factor. This parameter is ignored if % 'Continuation' equals zero.% Default = such that the first tau is equal to% 0.5*max(abs(AT(y))).% % 'True_x' = if the true underlying x is passed in % this argument, MSE evolution is computed%% 'AlphaMin' = the alphamin parameter of the BB method.% (See the paper for details)% Default = 1e-30;%% 'AlphaMax' = the alphamax parameter of the BB method.% (See the paper for details)% Default = 1e30;%% 'Verbose' = work silently (0) or verbosely (1)%% =================================================== % ============ Outputs ==============================% x = solution of the main algorithm%% x_debias = solution after the debiasing phase;% if no debiasing phase took place, this% variable is empty, x_debias = [].%% objective = sequence of values of the objective function%% times = CPU time after each iteration%% debias_start = iteration number at which the debiasing % phase started. If no debiasing took place,% this variable is returned as zero.%% mses = sequence of MSE values, with respect to True_x,% if it was given; if it was not given, mses is empty,% mses = [].% ========================================================% test for number of required parametresif (nargin-length(varargin)) ~= 3 error('Wrong number of required parameters');end% flag for initial x (can take any values except 0,1,2)Initial_X_supplied = 3333;% Set the defaults for the optional parametersstopCriterion = 3;tolA = 0.01;tolD = 0.0001;debias = 0;maxiter = 10000;maxiter_debias = 500;miniter = 5;miniter_debias = 5;init = 0;enforceMonotone = 1;alphamin = 1e-30;alphamax = 1e30;compute_mse = 0;AT = 0;verbose = 1;continuation = 0;cont_steps = 5;firstTauFactorGiven = 0;% Set the defaults for outputs that may not be computeddebias_start = 0;x_debias = [];mses = [];% Read the optional parametersif (rem(length(varargin),2)==1) error('Optional parameters should always go by pairs');else for i=1:2:(length(varargin)-1) switch upper(varargin{i}) case 'STOPCRITERION' stopCriterion = varargin{i+1}; case 'TOLERANCEA' tolA = varargin{i+1}; case 'TOLERANCED' tolD = varargin{i+1}; case 'DEBIAS' debias = varargin{i+1}; case 'MAXITERA' maxiter = varargin{i+1}; case 'MAXITERD' maxiter_debias = varargin{i+1}; case 'MINITERA' miniter = varargin{i+1}; case 'MINITERD' miniter_debias = varargin{i+1}; case 'INITIALIZATION' if prod(size(varargin{i+1})) > 1 % initial x supplied as array init = Initial_X_supplied; % flag to be used below x = varargin{i+1}; else init = varargin{i+1}; end case 'MONOTONE' enforceMonotone = varargin{i+1}; case 'CONTINUATION' continuation = varargin{i+1}; case 'CONTINUATIONSTEPS' cont_steps = varargin{i+1}; case 'FIRSTTAUFACTOR' firstTauFactor = varargin{i+1}; firstTauFactorGiven = 1; case 'TRUE_X' compute_mse = 1; true = varargin{i+1}; case 'ALPHAMIN' alphamin = varargin{i+1}; case 'ALPHAMAX' alphamax = varargin{i+1}; case 'AT' AT = varargin{i+1}; case 'VERBOSE' verbose = varargin{i+1}; otherwise % Hmmm, something wrong with the parameter string error(['Unrecognized option: ''' varargin{i} '''']); end; end;end%%%%%%%%%%%%%%if (sum(stopCriterion == [0 1 2 3 4])==0) error(['Unknown stopping criterion']);end% if A is a function handle, we have to check presence of AT,if isa(A, 'function_handle') & ~isa(AT,'function_handle') error(['The function handle for transpose of A is missing']);end % if A is a matrix, we find out dimensions of y and x,% and create function handles for multiplication by A and A',% so that the code below doesn't have to distinguish between% the handle/not-handle casesif ~isa(A, 'function_handle') AT = @(x) A'*x; A = @(x) A*x;end% from this point down, A and AT are always function handles.% Precompute A'*y since it'll be used a lotAty = AT(y);% Initializationswitch init case 0 % initialize at zero, using AT to find the size of x x = AT(zeros(size(y))); case 1 % initialize randomly, using AT to find the size of x x = randn(size(AT(zeros(size(y))))); case 2 % initialize x0 = A'*y x = Aty; case Initial_X_supplied % initial x was given as a function argument; just check size if size(A(x)) ~= size(y) error(['Size of initial x is not compatible with A']); end otherwise error(['Unknown ''Initialization'' option']);end% now check if tau is an array; if it is, it has to % have the same size as xif prod(size(tau)) > 1 try, dummy = x.*tau; catch, error(['Parameter tau has wrong dimensions; it should be scalar or size(x)']), endend % if the true x was given, check its sizeif compute_mse & (size(true) ~= size(x)) error(['Initial x has incompatible size']); end% if tau is scalar, we check its value; if it's large enough,% the optimal solution is the zero vectorif prod(size(tau)) == 1 aux = AT(y); max_tau = max(abs(aux(:))); if tau >= max_tau x = zeros(size(aux)); objective(1) = 0.5*(y(:)'*y(:)); times(1) = 0; if compute_mse mses(1) = sum(true(:).^2); end return end end% initialize u and vu = x.*(x >= 0);v = -x.*(x < 0);% define the indicator vector or matrix of nonzeros in xnz_x = (x ~= 0.0);num_nz_x = sum(nz_x(:));% start the clockt0 = cputime;% store given tau, because we're going to change it in the% continuation procedurefinal_tau = tau;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -