-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain.cc
More file actions
203 lines (179 loc) · 4.86 KB
/
Copy pathtrain.cc
File metadata and controls
203 lines (179 loc) · 4.86 KB
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
#include <string>
#include <fstream>
#include <iostream>
#include <chrono>
#include "database.h"
#include "fastWY.h"
//for G option
#include "genusdata.h"
using namespace std;
using uint = unsigned int;
//for G option
using Genus = vector<string>;
inline void exit_with_help()
{
cout << "-- FastWY method for sequential pattern mining --\n"
"Usage: train [-options] input_file\n"
"options:\n"
" -m : minimum supportSum (default 1)\n"
" If you want to decide on the percentage of the whole, please enter a value less than 1.\n"
" -M : minimum length of pattern (default 1)\n"
" -L : maximum length of pattern (default 10)\n"
" -F : name of reslut file (default output/result.csv)\n"
" -p : maximum interval of event (default 0|-1:none)\n"
" -C : whether to do CloSpan (default 0:do not|1:do)\n"
" -R : Repeat resampling in FastWY (default 10000)\n"
" -a : significance level (default 0.05)\n"
" -s : the Mode of counting supportSum(default 0)\n"
" : 0 is 0 or 1 per record,1 is the number of pattern\n"
" -w : whether to consider WildCard (default 0:No | 1:Yes)\n"
" -S : double or single-side test (default 0:double | 1:upper-side | 2:lower-side)\n"
" -A : (全パターン出力)\n"
" -G : (属も考慮 ファイル名を指定)\n"
" -K : (GオプションのNonFood-Aに関して種類数の閾値kを指定 (default 2))\n"
" -Z : (アレルゲンに関して, sup-が0となるようなパターンのみを抽出 (default 0: disable | 1: enable))"
" -T : (カテゴリが種の場合(202009): 1\n"
" -r : (SEEDの値を設定(randomのr)) default : srandなし\n "
<< endl;
exit(1);
}
int main(int argc, char **argv)
{
//default
double tMinsup = 1;
uint tMinpat = 1;
uint tMaxpat = 10;
uint tR = 10000;
double tAlpha = 0.05;
uint tWild = 0;
uint tSide = 0;
int tInterval = 0;
uint tSupMode = 0;
uint tCloSpan = 0;
uint tGenusMode = 0;
uint tKind = 2;
uint tZeroMode = 0;
uint tSpecies = 0;
uint tRand = 0;
string tFilename = "result.csv";
string tAllFilename = "allResult.csv";
string tGenusFilename = "genericName.csv";
int tI;
for (tI = 1; tI < argc; tI++)
{
if (argv[tI][0] != '-')
{
break;
}
if (++tI >= argc)
{
exit_with_help();
}
switch (argv[tI - 1][1])
{
case 'm':
tMinsup = atof(argv[tI]);
break;
case 'M':
tMinpat = atoi(argv[tI]);
break;
case 'L':
tMaxpat = atoi(argv[tI]);
break;
case 'F':
tFilename = argv[tI];
break;
case 'p':
tInterval = atoi(argv[tI]);
break;
case 's':
tSupMode = atoi(argv[tI]);
break;
case 'C':
tCloSpan = atoi(argv[tI]);
break;
case 'R':
tR = atoi(argv[tI]);
break;
case 'a':
tAlpha = atof(argv[tI]);
break;
case 'w':
tWild = atof(argv[tI]);
break;
case 'S':
tSide = atof(argv[tI]);
break;
case 'A':
tAllFilename = argv[tI];
break;
case 'G':
tGenusFilename = argv[tI];
tGenusMode = 1;
break;
case 'K':
tKind = atoi(argv[tI]);
break;
case 'Z':
tZeroMode = atoi(argv[tI]);
break;
case 'T':
tSpecies = atoi(argv[tI]);
break;
case 'r':
tRand = atoi(argv[tI]);
srand(tRand);
cout << "srand(" << tRand << ")" << endl;
break;
default:
cerr << "Error unknown option: -" << argv[tI - 1][1] << endl;
exit_with_help();
break;
}
}
if (tI >= argc)
{
cerr << "Error please input filename" << endl;
exit_with_help();
}
if (tWild == 1 && tInterval != 0)
{
cerr << "Error: If you want to consider WildCard, please set Interval value to 0" << endl;
exit_with_help();
}
//read data
Database tDatabase;
tDatabase.read(argv[tI]);
vector<vector<Event>> tTransaction = tDatabase.get_transaction();
vector<double> tY = tDatabase.get_y();
//for G option
Genusdata tGenusdata;
if (tGenusMode == 1)
{
tGenusdata.init(tGenusFilename, tR, tKind, tSpecies, tY);
// vector<string> tGenus = tGenusdata.get_genus();
// for (auto itr = tGenus.begin(); itr != tGenus.end(); ++itr)
// {
// cout << *itr << endl;
// }
}
chrono::system_clock::time_point start, end; // 型は auto で可
start = chrono::system_clock::now(); // 計測開始時間
//make fastWY
FastWY tFastWY(tMinsup, tMinpat, tMaxpat, tR, tAlpha, tCloSpan, tSupMode, tInterval, tWild, tSide, tGenusMode, tGenusdata, tZeroMode);
tFastWY.init(tTransaction, tY);
cout << "init finish" << endl;
//FastWY実行
tFastWY.main();
cout << "FastWY finish" << endl;
end = chrono::system_clock::now(); // 計測終了時間
double elapsed = chrono::duration_cast<chrono::milliseconds>(end - start).count(); //処理に要した時間をミリ秒に変換
elapsed *= 0.001;
cout << "****************************" << endl;
cout << "time(sec):" << elapsed << endl;
//write outcome
tFastWY.printSigPattern(tFilename);
tFastWY.printTree(tAllFilename);
cout << "print finish" << endl;
return 0;
}