-
Notifications
You must be signed in to change notification settings - Fork 2
/
optimizeZ_PI.m
91 lines (72 loc) · 2.29 KB
/
optimizeZ_PI.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
function [matrix,value,NcutDiscrete,t] = optimizeZ_PI(att_matrix1,mp_matrix,constraints,K,alpha,gamma,lambda,A)
% % The function optimizes z.
% Input:
% att_matrix1: att_num*n*n, where att_num is the number of attributes.
% mp_matrix: P*n*n, where P is the number of meta paths used and n is the number of objects.
% Each mp_matrix(i,:,:) is a meta path based similarity matrix.
% constraints: the constraint matrix of n*n.
% K: the number of clusters.
% alpha: the balance parameter.
% lambda: the meta path parameter vector.
% A: the attribute paramter vector.
%
% Output:
% NcutDiscrete: n*1, is the clustering result of z.
%
P = size(mp_matrix,1);
att_num = size(att_matrix1,1);
n = size(mp_matrix,2);
matrix = zeros(n,n);
% lambda = ones(P,1);
% A = ones(att_num,1);
% alpha = 100000;
% beta = 10;
% gamma = 0.1; % gamma is regularization parameter
% for meta path similarity
for i = 1:P
matrix = matrix + lambda(i) * squeeze(mp_matrix(i,:,:));
end
matrix = alpha(1) * matrix;
for j = 1:att_num
matrix = matrix + alpha(2) * A(j) * squeeze(att_matrix1(j,:,:));
end
matrix_new = matrix + constraints .* matrix;
% [NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(matrix,K,constraints,beta);
%
% clusters = zeros(n,1);
%
% %get cluster index
% for i = 1:n
% for j = 1:K
% if NcutDiscrete(i,j) == 1
% clusters(i) = j;
% break;
% end;
% end;
% end;
% NcutDiscrete = clusters;
[NcutDiscrete,t] = PICk(matrix,matrix_new,K);
% [NcutDiscrete,t] = NJW(matrix,matrix_new,K);
% [NcutDiscrete,t] = NJW_IRAM(matrix,matrix_new,K);
clusters = NcutDiscrete;
sum_S = zeros(K,1);
sum_D = zeros(K,1);
D = sum(matrix,2);
for i = 1:n
sum_D(clusters(i)) = sum_D(clusters(i)) + D(i);
for j = 1:n
if clusters(i) == clusters(j)
sum_S(clusters(i)) = sum_S(clusters(i)) + matrix(i,j);
if constraints(i,j) == 1
sum_S(clusters(i)) = sum_S(clusters(i)) + matrix(i,j);
elseif constraints(i,j) == -1
sum_S(clusters(i)) = sum_S(clusters(i)) - matrix(i,j);
end;
end;
end;
end;
value = K - (sum(sum_S./sum_D) - gamma * (norm(lambda)^2 + norm(A)^2));
disp(sum(NcutDiscrete));
disp(value);
% [lambda, A] = optimizeWeights(att_matrix,mp_matrix,NcutDiscrete,K,constraints,alpha,beta,gamma);
end