-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.m
157 lines (111 loc) · 2.98 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
function main(rank1, rank2, w, alpha, beta, gamma, DorT, scenario, k)
if nargin < 9
k = 20;
end
if nargin < 8
scenario = '1';
end
if nargin < 7
DorT = '1';
end
if nargin < 6
gamma = 0.01;
end
if nargin < 5
beta = 0.01;
end
if nargin < 4
alpha = 0.01;
end
if nargin < 3
w = 0.3;
end
if nargin < 2
rank2 = 90;
end
if nargin < 1
rank1 = 70;
end
load DiseaseSimMat;
load DrugDisease;
load DrugSimMat1;
load DrugSimMat2;
load DrugTarget;
load SMat;
load TargetSimMat;
X = {}; % contain binary interaction of drug-disease and drug-target
Au = {};
Av = {};
if DorT == '2'
X{2} = DrugDisease;
X{1} = DrugTarget;
Au{2} = DrugSimMat1;
Au{1} = DrugSimMat2;
Av{2} = DiseaseSimMat;
Av{1} = TargetSimMat;
S = SMat';
end
if DorT == '1'
X{1} = DrugDisease;
X{2} = DrugTarget;
Au{1} = DrugSimMat1;
Au{2} = DrugSimMat2;
Av{1} = DiseaseSimMat;
Av{2} = TargetSimMat;
S = SMat; % mapping matrix for two domain.
end
yy = X{1};
nfolds = 5;
para = [alpha, beta, gamma];
[positiveId, crossval_id] = train_test_split(X{1}, nfolds, scenario);
AUPR = zeros(nfolds,1);
AUC = zeros(nfolds, 1);
for fold = 1:nfolds
X{1} = yy;
PtrainID = positiveId(find(crossval_id~=fold));
PtestID = positiveId(find(crossval_id==fold));
% sample equal amount of negative sample
negativeID = find(X{1}==0);
num = numel(negativeID);
Nidx = randperm(num);
NtestID = negativeID(Nidx(1:length(PtestID)));
X{1}(PtestID) = 0; % mask out the test data
%nid = find(X{1}==0);
%X{1}(nid) = mean(mean(X{1}))+0.05; % initilzation for strategy 2 and 3 to avoild zero block
tic
[U, V, objs] = iDrug(X, w, Au, Av, S, rank1, rank2, para);
time =toc;
predX = U{1} * V{1}';
testScore = [yy(PtestID); yy(NtestID)];
pred = [predX(PtestID); predX(NtestID)];
[auc1, aupr, rocx, rocy, prx, pry] = auc(testScore(:), pred(:), 1e-6);
if scenario == '2' || scenario == '3'
[B,I] = sort(pred,'descend');
prec = sum(testScore(I(1:k)) == 1) / min(k, sum(testScore == 1));
fprintf('precision %f \n',prec);
end
fprintf('%d-Fold: the AUPR score %d, the AUC score: %d, running time %f \n', fold, aupr, auc1, time);
AUPR(fold,1) = aupr;
AUC(fold, 1) = auc1;
end
auprs = mean(AUPR);
aucs = mean(AUC);
fprintf('The averaqge of AUPR and AUC score: %d, %d \n', auprs, aucs);
figure(1)
subplot(1,3,1);
plot(rocx, rocy);
xlabel('FPR');
ylabel('TPR');
title('(a) AUROC')
subplot(1,3,2);
plot(prx, pry);
xlabel('Recall');
ylabel('Precision');
title('(a) AUPR')
% check the convergence
subplot(1,3,3)
plot(objs);
xlabel('Number of Iteration');
ylabel('Objective value');
title('Convergence')
end