📄 twist.m
字号:
function [x,x_debias,objective,times,debias_start,mses,max_svd] = ... TwIST(y,A,tau,varargin)%% Usage:% [x,x_debias,objective,times,debias_start,mses] = TwIST(y,A,tau,varargin)%% This function solves the regularization problem %% arg min_x = 0.5*|| y - A x ||_2^2 + tau phi( x ), %% where A is a generic matrix and phi(.) is a regularizarion % function such that the solution of the denoising problem %% Psi_tau(y) = arg min_x = 0.5*|| y - x ||_2^2 + tau \phi( x ), %% is known. % % For further details about the TwIST algorithm, see the paper:%% J. Bioucas-Dias and M. Figueiredo, "A New TwIST: Two-Step% Iterative Shrinkage/Thresholding Algorithms for Image % Restoration", IEEE Transactions on Image processing, 2007.% % and% % J. Bioucas-Dias and M. Figueiredo, "A Monotonic Two-Step % Algorithm for Compressive Sensing and Other Ill-Posed % Inverse Problems", submitted, 2007.%% Authors: Jose Bioucas-Dias and Mario Figueiredo, October, 2007.% % Please check for the latest version of the code and papers at% www.lx.it.pt/~bioucas/TwIST%% -----------------------------------------------------------------------% Copyright (2007): Jose Bioucas-Dias and Mario Figueiredo% % TwIST 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."% ----------------------------------------------------------------------% % ===== 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: regularization parameter, usually a non-negative real % parameter of the objective function (see above). % %% ===== Optional inputs =============% % 'Psi' = denoising function handle; handle to denoising function% Default = soft threshold.%% 'Phi' = function handle to regularizer needed to compute the objective% function.% Default = ||x||_1%% 'lambda' = lam1 parameters of the TwIST algorithm:% Optimal choice: lam1 = min eigenvalue of A'*A.% If min eigenvalue of A'*A == 0, or unknwon, % set lam1 to a value much smaller than 1.%% Rule of Thumb: % lam1=1e-4 for severyly ill-conditioned problems% lam1=1e-2 for mildly ill-conditioned problems% lam1=1 for A unitary direct operators%% Default: lam1 = 0.04.%% Important Note: If (max eigenvalue of A'*A) > 1,% the algorithm may diverge. This is be avoided % by taking one of the follwoing measures:% % 1) Set 'Monontone' = 1 (default)% % 2) Solve the equivalenve minimization problem%% min_x = 0.5*|| (y/c) - (A/c) x ||_2^2 + (tau/c^2) \phi( x ), %% where c > 0 ensures that max eigenvalue of (A'A/c^2) <= 1.%% 'alpha' = parameter alpha of TwIST (see ex. (22) of the paper) % Default alpha = alpha(lamN=1, lam1)% % 'beta' = parameter beta of twist (see ex. (23) of the paper)% Default beta = beta(lamN=1, lam1) % % '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 relative norm of the difference between % two consecutive estimates falls below toleranceA% 3 = stop when the objective function % becomes equal or less than toleranceA.% Default = 1.%% 'ToleranceA' = stopping threshold; Default = 0.01% % 'Debias' = debiasing option: 1 = yes, 0 = no.% Default = 0.% % Note: Debiasing is an operation aimed at the % computing the solution of the LS problem %% arg min_x = 0.5*|| y - A' x' ||_2^2 %% where A' is the submatrix of A obatained by% deleting the columns of A corresponding of components% of x set to zero by the TwIST algorithm% %% '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 = 1000%% '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. % any nonzero -> enforce monotonicity% 0 -> don't enforce monotonicity.% Default = 1;%% 'Sparse' = {0,1} accelarates the convergence rate when the regularizer % Phi(x) is sparse inducing, such as ||x||_1.% Default = 1% % % 'True_x' = if the true underlying x is passed in % this argument, MSE evolution is computed%%% '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 = [].%% max_svd = inverse of the scaling factor, determined by TwIST,% applied to the direct operator (A/max_svd) such that% every IST step is increasing.% ========================================================%--------------------------------------------------------------% test for number of required parametres%--------------------------------------------------------------if (nargin-length(varargin)) ~= 3 error('Wrong number of required parameters');end%--------------------------------------------------------------% Set the defaults for the optional parameters%--------------------------------------------------------------stopCriterion = 1;tolA = 0.01;debias = 0;maxiter = 1000;maxiter_debias = 200;miniter = 5;miniter_debias = 5;init = 0;enforceMonotone = 1;compute_mse = 0;plot_ISNR = 0;AT = 0;verbose = 1;alpha = 0;beta = 0;sparse = 1;tolD = 0.001;phi_l1 = 0;psi_ok = 0;% default eigenvalues lam1=1e-4; lamN=1;% % constants ans internal variablesfor_ever = 1;% maj_max_sv: majorizer for the maximum singular value of operator Amax_svd = 1;% Set the defaults for outputs that may not be computeddebias_start = 0;x_debias = [];mses = [];%--------------------------------------------------------------% Read the optional parameters%--------------------------------------------------------------if (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 'LAMBDA' lam1 = varargin{i+1}; case 'ALPHA' alpha = varargin{i+1}; case 'BETA' beta = varargin{i+1}; case 'PSI' psi_function = varargin{i+1}; case 'PHI' phi_function = varargin{i+1}; 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 'MAXIRERD' 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 % we have an initial x init = 33333; % some flag to be used below x = varargin{i+1}; else init = varargin{i+1}; end case 'MONOTONE' enforceMonotone = varargin{i+1}; case 'SPARSE' sparse = varargin{i+1}; case 'TRUE_X' compute_mse = 1; true = varargin{i+1}; if prod(double((size(true) == size(y)))) plot_ISNR = 1; end 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%%%%%%%%%%%%%%% twist parameters rho0 = (1-lam1/lamN)/(1+lam1/lamN);if alpha == 0 alpha = 2/(1+sqrt(1-rho0^2));endif beta == 0 beta = alpha*2/(lam1+lamN);endif (sum(stopCriterion == [0 1 2 3])==0) error(['Unknwon 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);% if phi was given, check to see if it is a handle and that it % accepts two argumentsif exist('psi_function','var') if isa(psi_function,'function_handle') try % check if phi can be used, using Aty, which we know has % same size as x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -