-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIMG.m
162 lines (126 loc) · 3.71 KB
/
IMG.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function [U1,U2,P2,P1,P3,A] = IMG(X2,Y2,X1,Y3,option)
% by handong Zhao
% contact handong.zhao@gmail.com if you have any questions
% Zhao, et al., Incomplete Multi-modal Visual Data Grouping, IJCAI'16
warning off;
lamda = option.lamda;
beta = option.beta;
gamma = option.gamma;
k = option.latentdim;
numClust = option.option;
truth = option.truth;
[numInst1,Featx]=size(X1);
[numInst2,Featx]=size(X2);
[numInst3,Featy]=size(Y3);
P1init=rand(numInst1,k);
P2init=rand(numInst2,k);
P3init=rand(numInst3,k);
Uxinit=rand(k,Featx);
Uyinit=rand(k,Featy);
P1=P1init;
P2=P2init;
P3=P3init;
Q1=P1init;
Q2=P2init;
Q3=P3init;
U1=Uxinit;
U2=Uyinit;
tol = 1e-8;
maxIter = 200;
mu = 1e-1;
rho = 1.1;
mu_bar = 1e10;
% initialize Y
L1 = zeros(size(P1));
L2 = zeros(size(P2));
L3 = zeros(size(P3));
I = eye(k);
numInst = numInst1+ numInst2+ numInst3;
OneN = ones(numInst,1);
In = eye(numInst);
La = rand(numInst,numInst);
oldA = zeros(size(numInst,numInst));
for ii = 1: maxIter
% update U1 ------------------------
U1 = (P2'*P2+lamda*I)\(P2'*X2);
% update U2 ------------------------
U2 = (P2'*P2+lamda*I)\(P2'*Y2);
% update P2
tmpA = 2*X2*U1'+2*Y2*U2'-L2+mu*Q2;
tmpB = 2*U1*U1'+2*U2*U2'+mu*I;
P2 = tmpA/(tmpB);
% update P1 ------------------------
tmpA = 2*X1*U1'-L1+mu*Q1;
tmpB = 2*U1*U1'+mu*I;
P1 = tmpA/(tmpB);
% update P3 ------------------------
tmpA = 2*Y3*U2'-L3+mu*Q3;
tmpB = 2*U2*U2'+mu*I;
P3 = tmpA/(tmpB);
% update Q = [Q2; Q1; Q3]
L = [L2; L1; L3];
P = [P2; P1; P3];
Q = pinv(beta*(La'+La)+mu*In)*(L+mu*P);
Q2 = Q(1:numInst2,:);
Q1 = Q(numInst2+1:numInst1+numInst2,:);
Q3 = Q(numInst1+numInst2+1:end,:);
% update A
for iSamp = 1:size(Q,1),
tmpVal = 0;
Qi = Q(iSamp,:);
di = zeros(numInst,1);
for jSamp = 1:size(Q,1),
Qj = Q(jSamp,:);
tmpVal = tmpVal + beta/(4*gamma)*norm((Qi-Qj),'fro')^2;
di(jSamp) = beta/(4*gamma)*norm((Qi-Qj),'fro')^2;
end
A(:,iSamp) = ((1+ tmpVal)/numInst)*OneN - di;
A = max(A,0);
end
A = (A+A')/2;
if ii==1,
resA = zeros(size(A));
else
resA = (A - oldA);
end
oldA = A;
La = diag(sum(A,2))- A;
leq1 = P1-Q1;
leq2 = P2-Q2;
leq3 = P3-Q3;
L1 = L1 + mu * leq1;
L2 = L2 + mu * leq2;
L3 = L3 + mu * leq3;
mu = min(mu*rho, mu_bar);
% convergence criterion
stopCriterion = max(max(max(abs(leq1))),max(max(abs(leq2))));
stopCriterion = max(stopCriterion,max(max(abs(leq3))));
if mod(ii, 10) == 0
C = clu_ncut(A,numClust);
C = C';
[~, nmi_sc, ~] = compute_nmi(truth,C);
UPI=[P2;P1;P3];
if (1)
norm_mat = repmat(sqrt(sum(UPI.*UPI,2)),1,size(UPI,2));
%%avoid divide by zero
for i=1:size(norm_mat,1)
if (norm_mat(i,1)==0)
norm_mat(i,:) = 1;
end
end
PIn = UPI./norm_mat;
end
for i=1: 20
C = kmeans(PIn,numClust,'EmptyAction','drop');
[~, nmii(i), ~] = compute_nmi(truth,C);
end
nmi_kmeans = mean(nmii);
disp(['iter ' num2str(ii) ', para ' num2str(lamda) '/' num2str(beta) '/' num2str(gamma)...
', stopC ' num2str(stopCriterion) ', NMI_SC ' num2str(nmi_sc)...
', NMI_kmeans ' num2str(nmi_kmeans)]);
end
if stopCriterion < tol
break;
end
end
end