-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
53 lines (41 loc) · 1.17 KB
/
utils.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
#include "utils.h"
void testPageRankVector(int N, float* result, const std::string& inputFileName)
{
std::string groundTruthFile(inputFileName + "_prob.txt");
double s = 0;
for(int i = 0; i < N; i++){
s = s + result[i];
}
std::cout << std::endl << "[Page Rank Vector Sum]: " << s << std::endl;
for(int i = 0; i < 10; i++)
std::cout << std::fixed << std::setprecision(4) << result[i] << " ";
std::cout << std::fixed << std::setprecision(9) << std::endl;
std::ifstream probFile;
probFile.open(groundTruthFile.c_str());
if (!probFile.is_open())
{
std::cout << "Could not open probability file!" << std::endl;
return;
}
std::string line;
int i = 0;
double mae = -1;
while (getline(probFile, line))
{
std::stringstream ss(line);
// Check that the line is not a comment line.
if (line[0] != '#')
{
double trueProb;
ss >> trueProb;
double temp = result[i] - trueProb;
if (temp > mae)
mae = temp;
}
}
std::ios::fmtflags f;
f = std::cout.flags();
std::cout << std::scientific << "[PageRank Serial Test]: Max Absolute Error = " << mae << std::endl;
std::cout.flags(f);
return;
}