-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpt.m
45 lines (44 loc) · 1.43 KB
/
Opt.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
% author: Zihen Chen
% Contact Email:[email protected]
% Optimization algorithm on graph embedding and metric learning
% [U_gras, U_Spd, U_Sgm] = Opt( k_Gras, k_Spd, k_Sgm, Train_lables,dr,k,mute)
% mute : if mute = 1, then mute all fprintf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [U_gras, U_Spd, U_Sgm] = Opt( k_Gras, k_Spd, k_Sgm, Train_lables,dr,k,mute)
D = size(k_Gras,1); % Sets numbers
K_c = {k_Gras,k_Spd,k_Sgm};
U = cell(1,3);
for q = 1:3
if mute ~= 1
fprintf('For %dth embedding:\n',q);
end
kernelMatrix = K_c{q};
%% calculate LLE weights
[w,neighbor_index] = simplex_lle_weights_ADMM(kernelMatrix,k,mute);
weights = zeros(D);
%get 40*40 weights matrix
for ii = 1:D
weights(ii,neighbor_index(:,ii)) = w(:,ii); % transpose and insert to 40 * 40
end
%% calculate qth Graph
G = generate_Graphs(weights,neighbor_index, Train_lables,mute);
%% calculate Fq
F = zeros(D);
for ii = 1:D
temp_G = G(ii,:);
G_diag = diag(temp_G);
tmpkernel = repmat(kernelMatrix(:,ii),1,D) - kernelMatrix;
F = F + tmpkernel * G_diag * tmpkernel' ;
end
F=(F+F')/2;
[V,eigen] = eig(F);
[eigen_sort,index] = sort(diag(eigen),'ascend');
V_sort = V(:,index);
U{q} = V_sort(:,1:dr);
end
U_gras = U{1};
U_Spd = U{2};
U_Sgm = U{3};
if mute~=1
fprintf('Done.\n');
end