-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmmnNe.m
27 lines (27 loc) · 937 Bytes
/
cmmnNe.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
function Score = CN(testID,Net)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the link prediction score using "Common Neighbors(CN)"
% score(A,B) = N(A) && N(B)
% % Input:
% 1)testID: the ID of the testing node pairs
% 2)Net: the adjacency matrix of the nentwork
% % Output:
% The prediction score of the testing nodes
% N(A) denotes the neighbors of node A
% Xi Wang
% 06/05/2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num_test = size(testID,1);
Score = zeros(num_test,1);
I = unique(testID(:,1));
Num = length(I);
for i = 1:Num
list = testID((testID(:,1)==I(i)),2); %index of links connecting node i
list2 = find((testID(:,1)==I(i)));
if(~isempty(list))
tmp = repmat(Net(I(i),:),length(list),1);
IDX = logical(tmp) & logical(Net(list,:));
Score(list2,:) = sum(IDX,2);
end
end
end