forked from corehello/RPCA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGP.m
58 lines (48 loc) · 1.44 KB
/
AGP.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
function [L,S] = AGP(M,lamda)
%-------------------------------------------------------------------------------%
% l : low-rank matrix, principle component %
% S : spare matrix, noise or special feature %
% M : origin matrix, can decompose to L + S %
% Author : corehello %
% Email : [email protected] %
%-------------------------------------------------------------------------------%
% paer : Rubost principal component analysis? 2009 stanford tech
% reporit
% data init
[m,n] = size(M);
L = zeros(m,n,3);
S = zeros(m,n,3);
t = ones(1,3);
miu = 0.001;
yita = 0.1;
k = 0;
while norm(M-L(:,:,mod(k+1,3)+1)-S(:,:,mod(k+1,3)+1),2) > 10^-7*norm(M,2)
norm(M-L(:,:,mod(k+1,3)+1)-S(:,:,mod(k+1,3)+1),2) - 10^-7*norm(M,2)
pause(0.1)
YL = L(:,:,mod(k+1,3)+1)+((t(mod(k,3)+1)-1)/t(mod(k+1,3)+1))*(L(:,:,mod(k+1,3)+1)-L(:,:,mod(k,3)+1));
YS = S(:,:,mod(k+1,3)+1)+((t(mod(k,3)+1)-1)/t(mod(k+1,3)+1))*(S(:,:,mod(k+1,3)+1)-S(:,:,mod(k,3)+1));
GL = YL - (1/2)*(YL+YS-M);
[U,X,V] = svd(GL);
L(:,:,mod(k+2,3)+1) = U*stao(X,miu/2)*V';
GS = YS - (1/2)*(YL+YS-M);
S(:,:,mod(k+2,3)+1) = stao(GS,lamda*miu/2);
t(mod(k+2,3)+1) = (1+sqrt(4*t(mod(k+1,2)+1)^2+1))/2;
miu = max(yita*miu,miu);
k=k+1;
end
L = L(:,:,mod(k,3)+1);
S = S(:,:,mod(k,3)+1);
function MA = stao(X,tao)
[m,n] = size(X);
MA = zeros(m,n);
for i=1:m
for j=1:n
MA(i,j)=sgn(X(i,j))*max(abs(X(i,j))-tao, 0);
end
end
function s = sgn(x)
if (x-0)>=0
s=1;
else
s=-1;
end