-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCSC_unconstrained.m
165 lines (143 loc) · 4.29 KB
/
CSC_unconstrained.m
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
function [X, res] = CSC_unconstrained(D, S, lamb, opts)
% Efficient algorithm for unconstrained convolutional sparse coding (CSC)
%
% Inputs:
% D: initial dictionary of K filters of size m1 by m2
% S: P stacked image of size H by W (S is H by W by P)
% lamb: l1-norm regularization parameter
% opt: optional parameters
%
% Outputs:
% X: sparse coefficient maps
% res: results (iterations details)
%
% Optional parameters:
%
% opts.MaxIter: maximum number of iterations (default 500)
% opts.rho: ADMM penalty parameter for csc step (default 10)
% opts.AutoRho: varying penalty parameter (ADMM extention) (default 1 (enabled))
% opts.relaxParam: relaxation parameter (ADMM extention) (default 1.8)
% opts.Xinit: initial sparse codes (default zeros)
% opts.Uinit: initial lagrange variables (default zeros)
% opts.eAbs: absolute tolerance for stopping criteria (deafult 10^-3)
% opts.eRel: relative tolerance for stopping criteria (deafult 10^-3)
%
% reference:
%
% Farsad G. Veshki and Sergiy Vorobyov. Efficient ADMM-based Algorithms for
% Convolutional Sparse Coding, IEEE Signal Processing Letters, 2021
%% parameters
[H,W,P] = size(S);
S = reshape(S,[H W 1 P]);
K = size(D,3);
if nargin < 4
opts = [];
end
if ~isfield(opts,'MaxIter')
opts.MaxIter = 300;
end
if ~isfield(opts,'rho')
opts.rho = 10;
end
if ~isfield(opts,'AutoRho')
opts.AutoRho = 1;
end
if ~isfield(opts,'eAbs')
opts.eAbs = 1e-4;
end
if ~isfield(opts,'eRel')
opts.eRel = 1e-4;
end
if ~isfield(opts,'Xinit')
opts.Xinit = zeros(H,W,K,P);
end
if ~isfield(opts,'Uinit')
opts.Uinit = zeros(H,W,K,P);
end
if ~isfield(opts,'relaxParam')
opts.relaxParam = 1.8;
end
%% initialization
alpha = opts.relaxParam;
Sf = fft2(S);
X = opts.Xinit; % sparse code
U = opts.Uinit; % scaled dual variable
rho = opts.rho;
eAbs = opts.eAbs;
eRel = opts.eRel;
epri = 0;
edua = 0;
rho_flg = 0;
MaxIter = opts.MaxIter;
r = inf; s = inf;
res.iterinf = [];
mu = 5; % varying rho parameter
tau = 1.2; % varying rho parameter
itr = 1;
vec = @(x) x(:);
tsrt = tic;
Df = fft2(D,H,W);
SDD = sum(abs(Df).^2,3);
Cf = conj(Df)./(SDD+rho);
Nx = numel(X);
%% ADMM iterations
while itr <= MaxIter && (r > epri || s > edua)
%_________________________Z update______________________________
[Zf,Cf,rho_flg] = Z_update(fft2(X-U),Cf,Df,Sf,SDD,rho,rho_flg) ;
Z = ifft2(Zf,'symmetric');
Zr = alpha * Z + (1-alpha)*X;
%_________________________X update______________________________
Xprv = X;
X = sfthrsh(Zr+U, lamb/rho);
%_________________________U update______________________________
U = Zr - X + U;
%_______________________________________________________________
%_________________________residuals_____________________________
nX = norm(X(:)); nZ = norm(Z(:)); nU = norm(U(:));
r = norm(vec(X-Z)); % primal residulal
s = rho*norm(vec(Xprv-X)); % dual residual
epri = sqrt(Nx)*eAbs+max(nX,nZ)*eRel;
edua = sqrt(Nx)*eAbs+rho*nU*eRel;
titer = toc(tsrt);
%_________________________progress_______________________________
JL1 = sum(abs(X(:))); % L_1 norm
rPow = sum(vec(abs(sum(Df.*fft2(X),3)-Sf).^2))/(H*W); % residual power
fval = rPow/2 + lamb*JL1; % functional value
res.iterinf = [res.iterinf; [itr fval rPow JL1 r s rho titer]];
res.U = U;
%_________________________rho update_____________________________
if opts.AutoRho && itr ~= 1
[rho,U,rho_flg] = rho_update(rho,r,s,mu,tau,U);
end
res.rho(itr,1) = rho;
%_______________________________________________________________
itr = itr + 1;
end
end
function y = sfthrsh(x, kappa)
y = sign(x).*max(0, abs(x) - kappa);
end
function [Zf,Cf,rho_flg] = Z_update(Wf,Cf,Df,Sf,SDD,rho,rho_flg)
Rf = Sf - sum(Wf.*Df,3); % residual update
if rho_flg == 0
Zf = Wf + Cf.*Rf; % Z update
else
rho_flg = 0;
Cf = conj(Df)./(SDD+rho);
Zf = Wf + Cf.*Rf; % Z update
end
end
function [rho,U,rho_flg] = rho_update(rho,r,s,mu,tau,U)
rsf = 1;
rho_flg = 0;
if r > mu*s, rsf = tau; end
if s > mu*r, rsf = 1/tau; end
if rsf~=1
rhot = rsf*rho;
if rhot>1e-4
rho = rhot;
U = U/rsf;
rho_flg = 1;
end
end
end