-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCrNMF.m
98 lines (82 loc) · 2.41 KB
/
CrNMF.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
function [B,H,F]=NNMF(W,Iter,k,beta,gamma)
% --Input
% --W is a [n,n,T] matrix, n is node number, T is the total time
% --k represents dimension we select default 100
% --beta is a parameter default 1
% --gama is a parameter default 1
% --Iter is a parameter represents the iteration times default 300
% author: Xiaoke Ma ([email protected])
% --Output
% --B is a [n,k,T] matrix
% --H is a [k,k,T] matrix
% --F is a [k,n,T] matrix
if nargin>5
error('parameter is too much,the max number of parameter is 5');
end
switch nargin
case 1
Iter=300;
k=300;
beta=1;
gamma=1;
case 2
k=300;
beta=0.2;
gamma=1;
case 3
beta=1;
gamma=1;
case 4
gamma=0.2;
end
[n,~,T]=size(W);
We=zeros(n,n,T);
%Get the degree matrix D
D=zeros(n,n,T);
for i=1:T
D(:,:,i)=diag(sum(W(:,:,i),2));
end
%Get the degree matrix De
De=zeros(n,n,T);
%Initialization B H F with SVD method
B=zeros(n,k,T);
H=zeros(k,k,T);
F=zeros(k,n,T);
for o=1:T
[b,h,f]=svds(W(:,:,o),k);
B(:,:,o)=abs(b);
H(:,:,o)=abs(h);
F(:,:,o)=abs(f');
end
A=B;
G=H;
E=F;
%Updata Rules
for i=1:T
if i==1
B(:,:,i)=A(:,:,i).*((W(:,:,i)*E(:,:,i)'*G(:,:,i)') ./ (A(:,:,i)*G(:,:,i)*E(:,:,i)*E(:,:,i)'*G(:,:,i)'+eps));
F(:,:,i)=E(:,:,i).*((G(:,:,i)'*A(:,:,i)'*W(:,:,i)) ./ (G(:,:,i)'*A(:,:,i)'*A(:,:,i)*G(:,:,i)*E(:,:,i)+eps));
H(:,:,i)=G(:,:,i).*((A(:,:,i)'*W(:,:,i)*E(:,:,i)') ./ (A(:,:,i)'*A(:,:,i)*G(:,:,i)*E(:,:,i)*E(:,:,i)'+eps));
M = abs(corr(B(:,:,i)'));
We(:,:,i) = M;
De(:,:,i) = diag(sum(We(:,:,i),2));
else
for o=1:Iter
B(:,:,i)=A(:,:,i).*((W(:,:,i)*E(:,:,i)'*G(:,:,i)'+beta*W(:,:,i-1)*A(:,:,i)) ./ (A(:,:,i)*G(:,:,i)*E(:,:,i)*E(:,:,i)'*G(:,:,i)'+beta*D(:,:,i-1)*A(:,:,i)+eps));
F(:,:,i)=E(:,:,i).*((G(:,:,i)'*A(:,:,i)'*W(:,:,i)+gamma*E(:,:,i)*We(:,:,i-1)) ./ (G(:,:,i)'*A(:,:,i)'*A(:,:,i)*G(:,:,i)*E(:,:,i)+gamma*E(:,:,i)*De(:,:,i-1)+eps));
H(:,:,i)=G(:,:,i).*((A(:,:,i)'*W(:,:,i)*E(:,:,i)') ./ (A(:,:,i)'*A(:,:,i)*G(:,:,i)*E(:,:,i)*E(:,:,i)'+eps));
if norm(W(:,:,i)-B(:,:,i)*H(:,:,i)*F(:,:,i),'fro')<0.01
break
else
A(:,:,i)=B(:,:,i);
G(:,:,i)=H(:,:,i);
E(:,:,i)=F(:,:,i);
end
end
%Using the current time base matrix to constract the We
M = abs(corr(B(:,:,i)'));
We(:,:,i) = M;
De(:,:,i) = diag(sum(We(:,:,i),2));
end
end
end