-
Notifications
You must be signed in to change notification settings - Fork 0
/
scc_gaus_ARP_v2.m
170 lines (116 loc) · 3.5 KB
/
scc_gaus_ARP_v2.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
163
164
165
166
167
168
169
170
function [U_output,Z_output] = scc_gaus_ARP_v2(X,Y,w,target_K)
%%% Matrix Update
alpha_X = 1/ norm(X - mean(X,2),'fro')^2;
alpha_Y = 1/ norm(Y - mean(Y,2),'fro')^2;
alpha2 = 0.5;
alpha_scale = min([alpha_X,alpha_Y]);
alpha_X = (1-alpha2) * alpha_X / alpha_scale;
alpha_Y = alpha2 * alpha_Y / alpha_scale;
[p1,n] = size(X);
[p2,n] = size(Y);
[x,y] = meshgrid(1:n, 1:n);
A = [x(:) y(:)];
A = A(y(:)>x(:),:);
A_whole = A;
w_whole = w;
active = find(w~=0);
A = A(active,:);
[len_l,~] = size(A);
% Remove Redundant edges
w = w(w~=0);
l1_mat_org = zeros(len_l,n);
l2_mat_org = zeros(len_l,n);
for i = 1:n
l1_mat_org(:,i) = (A(:,1) == i);
end
for i = 1:n
l2_mat_org(:,i) = (A(:,2) == i);
end
D = l1_mat_org - l2_mat_org;
D = D';
% Stroage of Output
MAX_ITER = 500;
U = zeros(p1,n);
V = zeros(p2,n);
Z1 = zeros(p1,len_l);
Z2 = zeros(p2,len_l);
Z = zeros(p1+p2,len_l);
Lambda1 = zeros(p1,len_l);
Lambda2 = zeros(p2,len_l);
M1 = inv(alpha_X * eye(n) + D * D');
M2 = inv(alpha_Y * eye(n) + D * D');
gamma = 0.1;
pen_t = 1.05;
k = 1;
% U = rand(p,n);
% V = zeros(p,len_l);
% V_tilde = zeros(p,len_l);
% Lambda = zeros(p,len_l);
U_output = rand(p1+p2,n,MAX_ITER);
Z_output = rand(p1+p2,len_l,MAX_ITER);
U_output(:,:,1) = [X ; Y];
Z_output(:,:,1) = rand(p1+p2,len_l);
while norm(Z_output(:,:,k)) ~= 0
Z_output(:,:,1) = zeros(p1+p2,len_l);
if k < 5
MAX_ITER_INNER = 20;
else
MAX_ITER_INNER = 20;
end
for m = 1:MAX_ITER_INNER
% U update
U = (alpha_X * X + (Z1+Lambda1) * D') * M1;
% V update
V = (alpha_Y * Y + (Z2+Lambda2) * D') * M2;
% Z-update and Lambda-update:
for l = 1:len_l
tmp = A(l,1);
tmp2 = A(l,2);
Z1(:,l) = U(:,tmp) - U(:,tmp2) - Lambda1(:,l);
Z2(:,l) = V(:,tmp) - V(:,tmp2) - Lambda2(:,l);
% V(:,l) = soft_threshold(V(:,l), w(l));
Z(:,l) = group_soft_threshold([Z1(:,l);Z2(:,l)], gamma * w(l));
Z1(:,l) = Z(1:p1,l);
Z2(:,l) = Z((p1+1):(p1+p2),l);
Lambda1(:,l) = Lambda1(:,l) + (Z1(:,l) - U(:,tmp) + U(:,tmp2));
Lambda2(:,l) = Lambda2(:,l) + (Z2(:,l) - V(:,tmp) + V(:,tmp2));
end
end
% Get Cluster Assignment
[no_class,class_id] = group_assign_vertice(Z,w_whole,n);
if no_class == target_K
U_output(:,:,k+1) = [U;V];
Z_output(:,:,k+1) = Z;
k = k + 1;
gamma_lower = gamma;
gamma = gamma * pen_t;
target_K = target_K - 1;
Z1_old = Z1;
Z2_old = Z2;
Lambda1_old = Lambda1;
Lambda2_old = Lambda2;
elseif no_class < target_K
gamma = (gamma_lower + gamma)/2;
Z1 = Z1_old;
Z2 = Z2_old;
Lambda1 = Lambda1_old;
Lambda2 = Lambda2_old;
if abs(gamma - gamma_lower) < 1e-3
gamma = gamma * pen_t;
target_K = target_K - 1;
end
elseif no_class > target_K
U_output(:,:,k+1) = [U;V];
Z_output(:,:,k+1) = Z;
k = k + 1;
gamma_lower = gamma;
gamma = gamma * pen_t;
Z1_old = Z1;
Z2_old = Z2;
Lambda1_old = Lambda1;
Lambda2_old = Lambda2;
end
end
U_output = U_output(:,:,1:k);
Z_output = Z_output(:,:,1:k);
end