[e6709d]: frames / franagrouplasso.m Maximize Restore History

Download this file

franagrouplasso.m    182 lines (152 with data), 5.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
function [tc,relres,iter,xrec] = franagrouplasso(F,insig,lambda,varargin)
%FRANAGROUPLASSO Group LASSO regression in the TF-domain
% Usage: [tc,xrec] = franagrouplasso(F,x,group,lambda,C,maxit,tol)
%
% Input parameters:
% F : Frame definition
% x : Input signal
% lambda : Regularization parameter, controls sparsity of the
% solution
% Output parameters:
% tc : Thresholded coefficients
% relres : Vector of residuals.
% iter : Number of iterations done.
% xrec : Reconstructed signal
%
% `franagrouplasso(F,x)` solves the group LASSO regression problem in the
% time-frequency domain: minimize a functional of the synthesis
% coefficients defined as the sum of half the $l^2$ norm of the
% approximation error and the mixed $l^1$ / $l^2$ norm of the coefficient
% sequence, with a penalization coefficient lambda.
%
% The matrix of time-frequency coefficients is labelled in terms of groups
% and members. By default, the obtained expansion is sparse in terms of
% groups, no sparsity being imposed to the members of a given group. This
% is achieved by a regularization term composed of $l^2$ norm within a
% group, and $l^1$ norm with respect to groups. See the help on
% |groupthresh| for more information.
%
% `[tc,relres,iter] = franagrouplasso(...)` returns the residuals *relres* in
% a vector and the number of iteration steps done, *maxit*.
%
% `[tc,relres,iter,xrec] = franagrouplasso(...)` returns the reconstructed
% signal from the coefficients, *xrec*. Note that this requires additional
% computations.
%
% The function takes the following optional parameters at the end of
% the line of input arguments:
%
% 'freq' Group in frequency (search for tonal components). This is the
% default.
%
% 'time' Group in time (search for transient components).
%
% 'C',cval Landweber iteration parameter: must be larger than
% square of upper frame bound. Default value is the upper
% frame bound.
%
% 'maxit',maxit
% Stopping criterion: maximal number of iterations.
% Default value is 100.
%
% 'tol',tol Stopping criterion: minimum relative difference between
% norms in two consecutive iterations. Default value is
% 1e-2.
%
% 'print' Display the progress.
%
% 'quiet' Don't print anything, this is the default.
%
% 'printstep',p
% If 'print' is specified, then print every p'th
% iteration. Default value is 10;
%
% In addition to these parameters, this function accepts all flags from
% the |groupthresh| and |thresh| functions. This makes it possible to
% switch the grouping mechanism or inner thresholding type.
%
% The parameters *C*, *maxit* and *tol* may also be specified on the
% command line in that order: `franagrouplasso(F,x,lambda,C,tol,maxit)`.
%
% The solution is obtained via an iterative procedure, called Landweber
% iteration, involving iterative group thresholdings.
%
% The relationship between the output coefficients is given by ::
%
% xrec = frsyn(F,tc);
%
% See also: franalasso, framebounds
if nargin<2
error('%s: Too few input parameters.',upper(mfilename));
end;
if ~isvector(insig)
error('Input signal must be a vector.');
end
% Define initial value for flags and key/value pairs.
definput.import={'thresh','groupthresh'};
definput.flags.group={'freq','time'};
definput.keyvals.C=[];
definput.keyvals.maxit=100;
definput.keyvals.tol=1e-2;
definput.keyvals.printstep=10;
definput.flags.print={'quiet','print'};
[flags,kv]=ltfatarghelper({'C','tol','maxit'},definput,varargin);
L=framelength(F,length(insig));
F=frameaccel(F,L);
if isempty(kv.C)
[A_dummy,kv.C] = framebounds(F,L);
end;
% Initialization of thresholded coefficients
c0 = frana(F,insig);
% We have to convert the coefficients to time-frequency layout to
% discover their size
tc = framecoef2tf(F,c0);
[M,N]=size(tc);
% Normalization to turn lambda to a value comparable to lasso
if flags.do_time
lambda = lambda*sqrt(N);
else
lambda = lambda*sqrt(M);
end
% Various parameter initializations
threshold = lambda/kv.C;
tc0 = c0;
relres = 1e16;
iter = 0;
% Choose the dimension to group along
if flags.do_freq
kv.dim=2;
else
kv.dim=1;
end;
kv.dim
if F.red==1
% ------------ Convert to TF-plane ---------
tc = groupthresh(tc,threshold,'argimport',flags,kv);
% Convert back from TF-plane
tc=frametf2coef(F,tc);
else
% Main loop
while ((iter < kv.maxit)&&(relres >= kv.tol))
tc = c0 - frana(F,frsyn(F,tc0));
tc = tc0 + tc/kv.C;
% ------------ Convert to TF-plane ---------
tc = framecoef2tf(F,tc);
tc = groupthresh(tc,threshold,'argimport',flags,kv);
% Convert back from TF-plane
tc=frametf2coef(F,tc);
% -------------------------------------------
relres = norm(tc(:)-tc0(:))/norm(tc0(:));
tc0 = tc;
iter = iter + 1;
if flags.do_print
if mod(iter,kv.printstep)==0
fprintf('Iteration %d: relative error = %f\n',iter,relres);
end;
end;
end
end;
% Reconstruction
if nargout>3
xrec = frsyn(F,tc);
end;