-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDivideNet.m
57 lines (36 loc) · 1.42 KB
/
DivideNet.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
function [ train,test ] = DivideNet( net, ratioTrain)
num_testlinks = ceil((1-ratioTrain) * nnz(net)/2);
[xindex, yindex] = find(tril(net)); linklist = [xindex yindex];
clear xindex yindex;
test = sparse(size(net,1),size(net,2));
while (nnz(test) < num_testlinks)
index_link = ceil(rand(1) * length(linklist));
uid1 = linklist(index_link,1);
uid2 = linklist(index_link,2);
net(uid1,uid2) = 0; net(uid2,uid1) = 0;
tempvector = net(uid1,:);
sign = 0;
uid1TOuid2 = tempvector * net + tempvector;
if uid1TOuid2(uid2) > 0
sign = 1;
else
while (nnz(spones(uid1TOuid2) - tempvector) ~=0)
tempvector = spones(uid1TOuid2);
uid1TOuid2 = tempvector * net + tempvector;
if uid1TOuid2(uid2) > 0
sign = 1;
break;
end
end
end
if sign == 1
linklist(index_link,:) = [];
test(uid1,uid2) = 1;
else
linklist(index_link,:) = [];
net(uid1,uid2) = 1;
net(uid2,uid1) = 1;
end
end
train = net; test = test + test';
end