-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (68 loc) · 2.76 KB
/
main.cpp
File metadata and controls
81 lines (68 loc) · 2.76 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
#define DD_DEBUG
#include <chrono>
#include <cuddInt.h>
#include <iostream>
#include "src/cupaal/baum_welch.h"
#include "src/cupaal/cudd_extensions.h"
#include "src/cupaal/helpers.h"
struct options {
std::string modelPath;
std::string sequencesPath;
int iterations = 100;
double epsilon = 1e-2;
std::chrono::seconds time = std::chrono::seconds(14400);
std::string outputPath;
std::string resultPath;
} options;
void parse_input_options(const int argc, char **argv) {
const cupaal::InputParser input(argc, argv);
if (!input.hasCmdOption("-m") || !input.hasCmdOption("-s")) {
std::cerr << "error: please supply both a model and data file" << std::endl;
exit(EXIT_FAILURE);
}
options.modelPath = input.getCmdOption("-m");
options.sequencesPath = input.getCmdOption("-s");
if (input.hasCmdOption("-i")) {
options.iterations = input.getIntFromCmdOption("-i");
}
if (input.hasCmdOption("-e")) {
options.epsilon = input.getDoubleFromCmdOption("-e");
}
if (input.hasCmdOption("-t")) {
const int seconds = input.getIntFromCmdOption("-t");
options.time = std::chrono::seconds(seconds);
}
if (input.hasCmdOption("-o")) {
options.outputPath = input.getCmdOption("-o");
}
if (input.hasCmdOption("-r")) {
options.resultPath = input.getCmdOption("-r");
}
}
int main(const int argc, char *argv[]) {
const auto program_start = std::chrono::steady_clock::now();
parse_input_options(argc, argv);
std::cout << "Reading model from file: " << options.modelPath << std::endl;
std::cout << "Reading sequences from file: " << options.sequencesPath << std::endl;
cupaal::MarkovModel model(options.modelPath, options.sequencesPath);
if (model.observations.size() > 1) {
model.baum_welch_multiple_observations(options.iterations, options.epsilon, options.time);
} else {
model.baum_welch(options.iterations, options.epsilon, options.time);
}
if (!options.outputPath.empty()) {
std::cout << "Saving model to: " << options.outputPath << std::endl;
model.export_to_file(options.outputPath);
}
if (!options.resultPath.empty()) {
std::cout << "Saving iteration details to: " << options.resultPath << std::endl;
model.save_experiment_to_csv(options.resultPath);
}
model.clean_up_cudd();
std::cout << "Remaining references (expecting 0): " << Cudd_CheckZeroRef(model.manager) << std::endl;
const auto program_end = std::chrono::steady_clock::now();
const auto elapsed_time = program_end - program_start;
std::cout << "Total time spent(s): " << std::chrono::duration_cast<std::chrono::seconds>(elapsed_time) << std::endl;
Cudd_Quit(model.manager);
exit(EXIT_SUCCESS);
}