-
Notifications
You must be signed in to change notification settings - Fork 1
/
SNF.m
78 lines (62 loc) · 1.4 KB
/
SNF.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
function [W]=SNF(Wall,K,t,ALPHA)
if nargin < 2
K = 20;
end
if nargin < 3
t = 20;
end
if nargin < 4
ALPHA = 1;
end
C = length(Wall); %number of data types :
[m,n]=size(Wall{1});
%Construct the normalized similarity matrix P
for i = 1 : C
Wall{i} = Wall{i}./repmat(sum(Wall{i},2),1,n);
% Wall{i} = Wall{i}./min(min(Wall{i}(Wall{i}>0)));
Wall{i} = (Wall{i} + Wall{i}')/2;
end
%Construct the normalized local similarity matrix S
for i = 1 : C
newW{i} = FindDominateSet(Wall{i},round(K));
end
Wsum = zeros(m,n);
for i = 1 : C
Wsum = Wsum + Wall{i};
end
for ITER=1:t
for i = 1 : C
Wall0{i}=newW{i}*(Wsum - Wall{i})*newW{i}'/(C-1);
end
for i = 1 : C
Wall{i} = BOnormalized(Wall0{i},ALPHA);
end
Wsum = zeros(m,n);
for i = 1 : C
Wsum = Wsum + Wall{i};
end
end
W = Wsum/C; %Pc=(P1+P2+....+Pn)/n
W = W./repmat(sum(W,2),1,n); %normalization of Pc
W = (W +W'+eye(n))/2;
end
function W = BOnormalized(W,ALPHA)
if nargin < 2
ALPHA = 1;
end
W = W+ALPHA*eye(length(W));
W = (W +W')/2;
end
function newW = FindDominateSet(W,K)
[m,n]=size(W);
[YW,IW1] = sort(W,2,'descend');
clear YW;
newW=zeros(m,n);
temp=repmat((1:n)',1,K);
I1=(IW1(:,1:K)-1)*m+temp;
newW(I1(:))=W(I1(:));
newW=newW./repmat(sum(newW,2),1,n);
clear IW1;
clear IW2;
clear temp;
end