forked from ZW-ZHANG/DHPE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed_update.m
95 lines (89 loc) · 1.72 KB
/
embed_update.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
function [nU nS nV nA nB] = embed_update(detA , U, S, V, mA, mB)
%U,V n*k
%S k*k
%A = I-b*A
%B = b*A
%l*A*U = BU
%detA = the changed edges
%detB = -detA
%mA = Fa in paper
%mB = Fb in paper
%get eigenvalues
%calc l = sign * S
if (sum(isnan(S)) > 0)
error('bug S');
end
K = size(S,1);
N = size(U,1);
nU = U;
SN = ones(K,1);
for i=1:K
for j = 1:N
if (V(j,i) ~= 0)
SN(i) = sign(U(j,i)/V(j,i));
break;
end
end
end
l = diag(S) .* SN;
if (sum(isnan(l)) > 0)
error('bug l');
end
%calc detl
dA = U'*detA*U;
detl = zeros(K,1);
%fm1 = diag(mA)
%fm2 = diag(dA)
for i = 1:K
detl(i) = -(l(i)+1)*dA(i,i)/(mA(i,i)+dA(i,i));
end
%detl
%diag(mA)
%calc new U
%tB=U'*U-mA;
%errB = sum(sum((mB - tB).^2))
F = zeros(K,K);
for i =1:K
S = zeros(K,K);
B = zeros(K,1);
for p = 1:K
if (p ~= i)
B(p) = -(l(i)+detl(i)+1)*dA(p,i)-(detl(i)*mA(p,i));
for q = 1:K
S(p,q) = (l(i)+detl(i)+1)*dA(p,q) + (l(i)+detl(i))*mA(p,q) - mB(p,q);
end
else
B(p) = 0;
S(p,p) = 1;
end
end
%g = S\B;
g = pinv(S)*B;
for j = 1:K
nU(:,i) = nU(:,i) + g(j)*U(:,j);
F(j,i) = g(j);
end
F(i,i) = F(i,i) + 1;
end
for i = 1:K
xs = sqrt(sum(nU(:,i).^2));
nU(:,i) = nU(:,i) / xs;
F(:,i) = F(:,i) / xs;
end
nA = zeros(K,K);
nB = zeros(K,K);
%calc new X'MaX (new Fa and Fb in paper)
for i =1:K
for j =1:K
for p =1:K
for q =1:K
nA(i,j) = nA(i,j) + F(p,i)*F(q,j)*mA(p,q);
nB(i,j) = nB(i,j) + F(p,i)*F(q,j)*mB(p,q);
end
end
end
end
nS = diag(abs(l+detl));
%diag(sign(l+detl))
nV = nU * diag(sign(l+detl));
end