-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSNMF_BPG.m
More file actions
72 lines (68 loc) · 1.86 KB
/
Copy pathSNMF_BPG.m
File metadata and controls
72 lines (68 loc) · 1.86 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
function [ Aout, xt, error, time] = SNMF_BPG(y,n_epochs, tau01,tau02, r, Ain, xin)
% Implement BPSG-SARAH for sparse non-negative matrix factorization
% argmin_{A,X} \|Y - AX\|_F^2
% s.t. \|A_k\|_0 <= tau \|X_k\|_0 <= tau \forall k, A_{i,j} >=0, X_{i,j} >= 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[n , d] = size(y);
error = zeros(n_epochs,1);
A_old = Ain;
pn=5;
xi_old = xin;
norm_y = norm(y,'fro');
t = 1;
pp=0.9;
time = zeros(n_epochs, 1);
t_total = 0;
e0 = 0.5 * ( norm( A_old * xi_old - y ,'fro') )^2;
md = zeros(1,r);
u_old=10000;
uy_old=10000;
for k = 1 : n_epochs
tic;
t=t+1;
tpp=t^pp;
L_A = power_method(A_old, pn);
u = 1/L_A;
u = min(u_old, u);
coeff = 3*(norm(A_old,'fro')^2+norm(xi_old,'fro')^2)+norm_y;
grad01 = A_old'*(A_old*xi_old - y)*u;
grad = grad01 -coeff*xi_old;
xi = -grad;
xi(xi < 0) = 0;
xi = xi';
B = sort(abs(xi), 1, 'descend');
md = B(tau01,:);
for q = 1:r
xi(:,q) = wthresh(xi(:,q),'h',md(q));
end
xi=xi';
L_x = power_method(xi_old, pn);
uy = 1/L_x;
uy = min(uy_old, uy);
grad2 = (xi_old*(A_old*xi_old - y)')'*uy-coeff*A_old;
A = -grad2;
A(A<0) = 0;
B = sort(abs(A), 1, 'descend');
md = B(tau02,:);
for q = 1:r
A(:,q) = wthresh(A(:,q),'h',md(q));
end
xi_norm = norm(xi,'fro')^2;
cor_r_3 = 3*(norm(A,'fro')^2+xi_norm);
r_sol = solve_eq_3(cor_r_3, 0, norm_y, -1);
xi = r_sol*xi;
A = r_sol*A;
xi_old = xi;
A_old = A;
u_old = u;
uy_old = uy;
t1 = toc;
t_total = t_total + 2.1*t1;
time(k) = t_total;
error(k) = 0.5 * ( norm( A * xi - y ,'fro') )^2 ;
end
Aout = A;
xt = xi;
error = [e0; error];
end