-
Notifications
You must be signed in to change notification settings - Fork 30
/
trpca_tnn.m
90 lines (83 loc) · 2.82 KB
/
trpca_tnn.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
function [L,S,obj,err,iter] = trpca_tnn(X,lambda,opts)
% Solve the Tensor Robust Principal Component Analysis based on Tensor Nuclear Norm problem by ADMM
%
% min_{L,S} ||L||_*+lambda*||S||_1, s.t. X=L+S
%
% ---------------------------------------------
% Input:
% X - d1*d2*d3 tensor
% lambda - >0, parameter
% opts - Structure value in Matlab. The fields are
% opts.tol - termination tolerance
% opts.max_iter - maximum number of iterations
% opts.mu - stepsize for dual variable updating in ADMM
% opts.max_mu - maximum stepsize
% opts.rho - rho>=1, ratio used to increase mu
% opts.DEBUG - 0 or 1
%
% Output:
% L - d1*d2*d3 tensor
% S - d1*d2*d3 tensor
% obj - objective function value
% err - residual
% iter - number of iterations
%
% version 1.0 - 19/06/2016
%
% Written by Canyi Lu ([email protected])
%
% References:
% [1] Canyi Lu, Jiashi Feng, Yudong Chen, Wei Liu, Zhouchen Lin and Shuicheng
% Yan, Tensor Robust Principal Component Analysis with A New Tensor Nuclear
% Norm, arXiv preprint arXiv:1804.03728, 2018
% [2] Canyi Lu, Jiashi Feng, Yudong Chen, Wei Liu, Zhouchen Lin and Shuicheng
% Yan, Tensor Robust Principal Component Analysis: Exact Recovery of Corrupted
% Low-Rank Tensors via Convex Optimization, arXiv preprint arXiv:1804.03728, 2018
%
tol = 1e-8;
max_iter = 500;
rho = 1.1;
mu = 1e-4;
max_mu = 1e10;
DEBUG = 0;
if ~exist('opts', 'var')
opts = [];
end
if isfield(opts, 'tol'); tol = opts.tol; end
if isfield(opts, 'max_iter'); max_iter = opts.max_iter; end
if isfield(opts, 'rho'); rho = opts.rho; end
if isfield(opts, 'mu'); mu = opts.mu; end
if isfield(opts, 'max_mu'); max_mu = opts.max_mu; end
if isfield(opts, 'DEBUG'); DEBUG = opts.DEBUG; end
dim = size(X);
L = zeros(dim);
S = L;
Y = L;
iter = 0;
for iter = 1 : max_iter
Lk = L;
Sk = S;
% update L
[L,tnnL] = prox_tnn(-S+X-Y/mu,1/mu);
% update S
S = prox_l1(-L+X-Y/mu,lambda/mu);
dY = L+S-X;
chgL = max(abs(Lk(:)-L(:)));
chgS = max(abs(Sk(:)-S(:)));
chg = max([ chgL chgS max(abs(dY(:))) ]);
if DEBUG
if iter == 1 || mod(iter, 10) == 0
obj = tnnL+lambda*norm(S(:),1);
err = norm(dY(:));
disp(['iter ' num2str(iter) ', mu=' num2str(mu) ...
', obj=' num2str(obj) ', err=' num2str(err)]);
end
end
if chg < tol
break;
end
Y = Y + mu*dY;
mu = min(rho*mu,max_mu);
end
obj = tnnL+lambda*norm(S(:),1);
err = norm(dY(:));