function [s, err_mse, iter_time]=greed_nomp(x,A,m,varargin)
% greed_nomp: Nearly Orthogonal Matching Pursuit or Approximate Conjugate
% Gradient Pursuit algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Usage
% [s, err_mse, iter_time]=greed_nomp(x,P,m,'option_name','option_value')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% Mandatory:
% x Observation vector to be decomposed
% P Either:
% 1) An nxm matrix (n must be dimension of x)
% 2) A function handle (type "help function_format"
% for more information)
% Also requires specification of P_trans option.
% 3) An object handle (type "help object_format" for
% more information)
% m length of s
%
% Possible additional options:
% (specify as many as you want using 'option_name','option_value' pairs)
% See below for explanation of options:
%__________________________________________________________________________
% option_name | available option_values | default
%--------------------------------------------------------------------------
% stopCrit | M, corr, mse, mse_change | M
% stopTol | number (see below) | n/4
% P_trans | function_handle (see below) |
% maxIter | positive integer (see below) | n
% verbose | true, false | false
% start_val | vector of length m | zeros
% GradSteps | 'auto' or integer | 'auto'
% wf | weaknes factor [1 0) | 1
%
% Available stopping criteria :
% M - Extracts exactly M = stopTol elements.
% corr - Stops when maximum correlation between
% residual and atoms is below stopTol value.
% mse - Stops when mean squared error of residual
% is below stopTol value.
% mse_change - Stops when the change in the mean squared
% error falls below stopTol value.
%
% stopTol: Value for stopping criterion.
%
% P_trans: If P is a function handle, then P_trans has to be specified and
% must be a function handle.
%
% maxIter: Maximum number of allowed iterations.
%
% verbose: Logical value to allow algorithm progress to be displayed.
%
% start_val: Allows algorithms to start from partial solution.
%
% GradSteps: Number of gradient optimisation steps per iteration.
% 'auto' uses inner products to decide if more gradient steps
% are required.
%
% wf: weakness factor alpha (see [2] and [3]). Algorithm will select all
% elements fror which |P_trans residual| >= alpha max(|P_trans residual|)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Outputs
% s Solution vector
% err_mse Vector containing mse of approximation error for each
% iteration
% iter_time Vector containing computation times for each iteration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Description
% greed_nomp performs a greedy signal decomposition.
% In each iteration a new element is selected depending on the inner
% product between the current residual and columns in P.
% A directional update is used that is conjuagte to the previously used
% direction.
%
% THIS ALGORITHM IS AN ALTERNATIVE TO OMP IF OMP IS NOT FEASIBLE DUE TO
% COMPUTATION TIME OR STORAGE REQUIREMENTS! IT IS IN GENERAL BETTER THAN
% greed_gp
%
% References
% [1] T. Blumensath and M.E. Davies, "Gradient Pursuits", to appear in
% IEEE Transactions on Signal Processing
% [2] M.E. Davies and T. Blumensath; "Faster & Greedier: algorithms for
% sparse reconstruction of large datasets ", invited paper to the
% third IEEE International Symposium on Communications, Control, and
% Signal Processing, St Julians, Malta, March 2008.
% [3] T. Blumensath, M. E. Davies; "Fast greedy algorithms for large
% sparse inverse problems", submitted to EUSIPCO, 2008
% See Also
% greed_omp, greed_ols, greed_mp, greed_gp, greed_pcgp
%
% Copyright (c) 2007 Thomas Blumensath
%
% The University of Edinburgh
% Email: [email protected]
% Comments and bug reports welcome
%
% This file is part of sparsity Version 0.3
% Created: April 2007
%
% Part of this toolbox was developed with the support of EPSRC Grant
% D000246/1
%
% Please read COPYRIGHT.m for terms and conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Default values and initialisation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[n1 n2]=size(x);
if n2 == 1
n=n1;
elseif n1 == 1
x=x';
n=n2;
else
error('x must be a vector.');
end
sigsize = x'*x/n;
initial_given=0;
err_mse = [];
iter_time = [];
STOPCRIT = 'M';
STOPTOL = ceil(n/4);
MAXITER = n;
verbose = false;
s_initial = zeros(m,1);
GradSteps = 'auto';
alpha = 1;
weakness = 1;
if verbose
display('Initialising...')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Output variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch nargout
case 3
comp_err=true;
comp_time=true;
case 2
comp_err=true;
comp_time=false;
case 1
comp_err=false;
comp_time=false;
case 0
error('Please assign output variable.')
otherwise
error('Too many output arguments specified')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Look through options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Put option into nice format
Options={};
OS=nargin-3;
c=1;
for i=1:OS
if isa(varargin{i},'cell')
CellSize=length(varargin{i});
ThisCell=varargin{i};
for j=1:CellSize
Options{c}=ThisCell{j};
c=c+1;
end
else
Options{c}=varargin{i};
c=c+1;
end
end
OS=length(Options);
if rem(OS,2)
error('Something is wrong with argument name and argument value pairs.')
end
for i=1:2:OS
switch Options{i}
case {'stopCrit'}
if (strmatch(Options{i+1},{'M'; 'corr'; 'mse'; 'mse_change'},'exact'));
STOPCRIT = Options{i+1};
else error('stopCrit must be char string [M, corr, mse, mse_change]. Exiting.'); end
case {'stopTol'}
if isa(Options{i+1},'numeric') ; STOPTOL = Options{i+1};
else error('stopTol must be number. Exiting.'); end
case {'P_trans'}
if isa(Options{i+1},'function_handle'); Pt = Options{i+1};
else error('P_trans must be function _handle. Exiting.'); end
case {'maxIter'}
if isa(Options{i+1},'numeric'); MAXITER = Options{i+1};
else error('maxIter must be a number. Exiting.'); end
case {'wf'}
if isa(Options{i+1},'numeric'); alpha = Options{i+1};
if alpha <1 weakness =0; else alpha =1; weakness = 1; end
else error('wf must be a number. Exiting.'); end
case {'verbose'}
if isa(Options{i+1},'logical'); verbose = Options{i+1};
else error('verbose must be a logical. Exiting.'); end
case {'start_v
Gradientpursuit.rar_Gradientpursuit_梯度追踪_梯度追踪matlab
版权申诉
5星 · 超过95%的资源 166 浏览量
2022-07-14
01:15:47
上传
评论
收藏 28KB RAR 举报
御道御小黑
- 粉丝: 61
- 资源: 1万+