-
Notifications
You must be signed in to change notification settings - Fork 3
/
multikernelLatefusionclustering.asv
74 lines (65 loc) · 2.08 KB
/
multikernelLatefusionclustering.asv
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
function [Hstar,Wstar,WP,gamma,obj] = multikernelLatefusionAlignmentclustering(K,k,lambda,tau)
num = size(K, 2); %the number of samples
numker = size(K, 3); %m represents the number of kernels
maxIter = 100; %the number of iterations
%construct r_p,wp
gamma = ones(numker,1)/numker;
HP = zeros(num,k,numker);
WP = zeros(k,k,numker);
opt.disp = 0;
KH = zeros(num,num,numker);
for p=1:numker % m - kernels
KH(:,:,p) = myLocalKernel(K,tau,p);
KH(:,:,p) = (KH(:,:,p)+KH(:,:,p)')/2;
[Hp, ~] = eigs(KH(:,:,p), k, 'la', opt);
HP(:,:,p) = Hp;
WP(:,:,p) = eye(k);
end
Wstar = eye(k);
RpHpwp = zeros(num,k); % k - clusters, N - samples
for p=1:numker
% Rp2Hpwp = Rp2Hpwp + gamma(p)^2*Hp(:,:,p)*wp(:,:,p);
RpHpwp = RpHpwp + gamma(p)*(HP(:,:,p)*WP(:,:,p));
end
flag = 1;
iter = 0;
while flag
iter = iter +1;
%the first step-- optimize H_star, given Rp,wp
%equivalent to maximize(sum(rp2*tr(H_star'*Hp*wp)))
%SVD of Hp'*H_star
UU = RpHpwp*Wstar';
[Uh,Sh,Vh] = svd(UU,'econ');
Hstar = Uh*Vh';
% Hstar = zeros(num,k);
% for ipk =1:num
% [val, indx] = max(UU(ipk,:));
% Hstar(ipk,indx) = 1;
% end
%the second step-- optimizing wp, given Rp,H_star equivalent to maximize(sum(2*tr(wp'*Hp'*H_star)))
%SVD of Hp'*H_star, we will get one wp for each for_loop as follows
for p=1:numker
if gamma(p)>1e-4
TP = gamma(p)*(Hstar)'*HP(:,:,p);
% WP0 = zeros(k);
% for ipk =1:k
% [val, indx] = max(TP(:,ipk));
% e00 = zeros(k,1);
% e00(indx) =1;
% WP0(:,ipk) = e00;
% end
% WP(:,:,p) = WP0;
[Up,Sp,Vp] = svd(TP,'econ');
WP(:,:,p) = Up*Vp';
end
end
coef = zeros(1,numker);
for p=1:numker
coef(1,p) = trace(*(Hstar)'*HP(:,:,p))
end
gamma = ones(numker,1)/numker;
obj(iter) = trace((Hstar*Wstar-RpHpwp)'*(Hstar*Wstar-RpHpwp));
if (iter>2) && (abs((obj(iter-1)-obj(iter))/(obj(iter-1)))<1e-4 || iter>maxIter)
flag =0;
end
end