-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
317 lines (183 loc) · 6.25 KB
/
main.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include<iostream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include "RMS_testing_2.h"
using namespace std;
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
};
//Per provare genero due vettori
void rand_vec (vector<pair<int,double> > & v1, vector<pair<int,double> > & v2,int size_vec) {
for (int i = 0; i < size_vec; i++) {
double rnd = fRand(-1,5);
if (rnd < 0) {
rnd = -1;
}
v1.push_back(make_pair(i+1,rnd));
rnd = fRand(-1,5);
if (rnd < 0) {
rnd = -1;
}
v2.push_back(make_pair(i+1,rnd));
}
};
int main() {
int N = 10;
clock_t tot_t = clock();
cout<<"CLOCKS_PER_SEC: "<<CLOCKS_PER_SEC<<endl;
cout<<"For list of "<<N<<" elements: "<<endl<<endl ;
ifstream myReadFile;
//Prima parte: recall, precision, ARHR, ARP, DCG
vector<data> v1;
myReadFile.open("INPUT_recall.txt");
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
int it, usr, pos;
double rate;
myReadFile >>it>>usr>>pos>>rate;
data d(it,usr,rate,pos);
v1.push_back(d);
}
}
myReadFile.close();
cout<<"First part: "<<endl;
cout<<"Sequential: "<<endl;
cout<<"Recall is: "<<RMS_recall(v1,N)<<endl;
cout<<"Precision is: "<<RMS_precision(v1,N)<<endl;
cout<<"The ARHR is: "<<RMS_ARHR(v1,N)<<endl;
cout<<"The ARP is: "<<RMS_ARP(v1,N)<<endl;
cout<<"The DCG is: "<<RMS_DCG(v1,N)<<endl;
cout<<"openMP directives: "<<endl;
cout<<"Recall is: "<<RMS_recall_omp(v1,N)<<endl;
cout<<"Precision is: "<<RMS_precision_omp(v1,N)<<endl;
cout<<"The ARHR is: "<<RMS_ARHR_omp(v1,N)<<endl;
cout<<"The ARP is: "<<RMS_ARP_omp(v1,N)<<endl;
cout<<"The DCG is: "<<RMS_DCG_omp(v1,N)<<endl;
cout<<"End first part."<<endl<<endl;
//Per verificare quanto i metodi open mp sono più efficienti:
vector<double> time_sec;
vector<double> time_omp;
cout<<endl<<"Those are the (cumulative) ratio that measures the difference of efficiency between OMP directives and sequential ones. Note that will be different between computers (more cores -> lower ratios): "<<endl;
clock_t init_t = clock();
for(int j = 1; j < 200; j++){
double rec = RMS_recall(v1,j);
double pr = RMS_precision(v1,j);
double ARHR = RMS_ARHR(v1,j);
double ARP = RMS_ARP(v1,j);
double DCG = RMS_DCG(v1,j);
time_sec.push_back(((double)(clock()-init_t))/CLOCKS_PER_SEC);
}
init_t = clock();
for(int j = 1; j < 200; j++){
double rec = RMS_recall_omp(v1,j);
double pr = RMS_precision_omp(v1,j);
double ARHR = RMS_ARHR_omp(v1,j);
double ARP = RMS_ARP_omp(v1,j);
double DCG = RMS_DCG_omp(v1,j);
time_omp.push_back(((double)(clock()-init_t))/CLOCKS_PER_SEC);
}
for(int j = 1; j < time_sec.size();j++){
if ( (time_sec[j] != 0) && (j%10 == 0 || j == (time_sec.size()-1)) )
cout<<time_omp[j]/time_sec[j]<<"\t";
}
cout<<endl<<endl;
//fine prima parte
//Seconda parte: Fallout
vector<data> v2;
ifstream myReadFile2;
myReadFile2.open("INPUT_fallout.txt");
if (myReadFile2.is_open()) {
while (!myReadFile2.eof()) {
int it, usr, pos;
double rate;
myReadFile2 >>it>>usr>>pos>>rate;
data d(it,usr,rate,pos);
v2.push_back(d);
}
}
myReadFile2.close();
cout<<"Second part: "<<endl;
cout<<"Fallout is: "<<RMS_fallout(v2,N)<<endl;
cout<<"openMP fallout is: "<<RMS_fallout_omp(v2,N)<<endl;
cout<<"End second part."<<endl<<endl;
//fine seconda parte
//Terza parte: ROC (dipende da parte 1 e 2)
cout<<"Third part: "<<endl;
cout<<"The area under the ROC curve is: "<<AUC_ROC(v1,v2)<<endl;
draw_ROC(v1,v2);
draw_ROC_m(v1,v2);
cout<<"End third part."<<endl<<endl;
//fine terza parte
//Quarta parte: Novelity (dipende da parte 1)
vector<int> popularity;
ifstream myReadFile3;
myReadFile3.open("popularity.txt");
if (myReadFile3.is_open()) {
while (!myReadFile3.eof()) {
int it;
myReadFile3 >>it;
popularity.push_back(it);
}
}
myReadFile3.close();
cout<<"Fourth part: "<<endl;
cout<<"Novelity is: "<<novelity(v1,popularity,N)<<endl;
cout<<"End fourth part."<<endl<<endl;
//fine quarta parte
//Quinta parte: Spearman/Kendall
vector<pair<int,double> > v3, v4;
//Caso non abbiamo dati:
//rand_vec(v3,v4,6);
ifstream myReadFile4;
myReadFile4.open("real.txt");
if (myReadFile4.is_open()) {
while (!myReadFile4.eof()) {
int it;
double rate;
myReadFile4 >>it>>rate;
v3.push_back(make_pair(it,rate));
}
}
myReadFile4.close();
ifstream myReadFile5;
myReadFile5.open("predicted.txt");
if (myReadFile5.is_open()) {
while (!myReadFile5.eof()) {
int it;
double rate;
myReadFile5 >>it>>rate;
v4.push_back(make_pair(it,rate));
}
}
myReadFile5.close();
/*
cout<<endl<<endl<<"Vectors: "<<endl;
for (int i = 0; i < v3.size(); i++) {
cout <<v3[i].first<<"\t";
}
cout<<endl;
for (int i = 0; i < v3.size(); i++) {
cout <<setprecision(4)<<v3[i].second<<"\t";
}
cout<<endl<<endl;
for (int i = 0; i < v4.size(); i++) {
cout <<v4[i].first<<"\t";
}
cout<<endl;
for (int i = 0; i < v4.size(); i++) {
cout <<setprecision(4)<<v4[i].second<<"\t";
}
*/
cout<<"Fifth part: "<<endl;
cout<<"Spearsman rho: "<<compute_s_rho(v4,v3)<<endl;
cout<<"Kendau tau: "<<compute_k_tau(v4,v3)<<endl;
cout<<"End fifth part."<<endl<<endl;
//cout<<"Fallout is: "<<RMS_fallout_robust(v2,10)<<endl;
//cout<<"Precision is: "<<RMS_precision (v1, 10)<<endl;
//cout<<"Robust Precision is: "<<RMS_precision_robust (v1, 10)<<endl;
cout<<endl<<endl<<"Total elapsed time: "<<((double)(clock()-tot_t))/CLOCKS_PER_SEC<<"s"<<endl;
return 0;
}