-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotifs.cpp
114 lines (89 loc) · 2.82 KB
/
motifs.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <ctime>
#include <cstdio>
#include "MotifDiscovery/RandomProjection.h"
#include "MotifDiscovery/ParallelRandomProjection.h"
#include "MotifDiscovery/MotifParameters.h"
void testParallelRandomProjection(std::string db){
clock_t begin = clock();
ParallelRandomProjection rp;
MotifParameters params;
std::ifstream ifs (db.c_str());
std::string line;
int iter = 0;
while ( getline(ifs, line) ) {
std::vector<double> ts;
double value;
std::stringstream ss (line);
while ( ss >> value)
ts.push_back(value);
Word isaxWord(ts, params.wordLength, params.initialCardinality);
rp.addWord(isaxWord);
// std::cout << isaxWord.toString() << std::endl;
//std::cout << iter++ << std::endl;
iter++ ;
}
rp.randomProjection();
//rp.showResult();
clock_t end = clock();
//rp.show1MotifResult();
double time = (end - begin) / 1000.0;
std::cout << "Exec time (ms): " << ( time ) << std::endl;
char buffer_tmp[100];
std::string nameFile = db + "." + "SERIAL.MOTIFS";
std::ofstream save_file(nameFile.c_str());
sprintf(buffer_tmp,"Random Projections Motifs time exec: %0.6lf\n", (double)time);
printf(buffer_tmp);
save_file << buffer_tmp;
save_file.close();
}
void testRandomProjection(std::string db) {
clock_t begin = clock();
RandomProjection rp;
MotifParameters params;
std::ifstream ifs (db.c_str());
std::string line;
int iter = 0;
while ( getline(ifs, line) ) {
std::vector<double> ts;
double value;
std::stringstream ss (line);
while ( ss >> value) {
ts.push_back(value);
}
Word isaxWord(ts, params.wordLength, params.initialCardinality);
rp.addWord(isaxWord);
//std::cout << isaxWord.toString() << std::endl;
//std::cout << iter++ << std::endl;
}
rp.randomProjection();
//rp.showResult();
clock_t end = clock();
double time = (end - begin) / 1000.0;
std::cout << "Exec time (ms): " << ( time ) << std::endl;
char buffer_tmp[100];
std::string nameFile = db + "." + "SERIAL.MOTIFS";
std::ofstream save_file(nameFile.c_str());
sprintf(buffer_tmp,"Random Projections Motifs time exec: %0.6lf\n", (double)time);
printf(buffer_tmp);
save_file << buffer_tmp;
save_file.close();
}
void usage(char *programName) {
printf("Usage: %s serial|parallel data_set_file\n", programName);
}
int main(int nargs, char* args[]) {
if (nargs < 2) {
usage(args[0]);
exit(1);
}
std::string type = args[1];
std::string db = args[2];
if (type == "serial")
testRandomProjection(db);
else
testParallelRandomProjection(db);
return 0;
}