-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_preprocess.cpp
executable file
·157 lines (144 loc) · 5.95 KB
/
utils_preprocess.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
#include "string"
#include "parameters.h"
#include "energy_structures.h"
#include <wordexp.h>
#include <sstream>
#include <fstream>
#include <algorithm>
bool pick_option(std::vector<std::string>& args, const std::string& option){
auto it = find(args.begin(), args.end(), "-" + option);
bool found = it != args.end();
if (found)
args.erase(it);
return found;
}
std::string pick_option(std::vector<std::string>& args, const std::string& option, const std::string& default_value){
auto arg = "-" + option;
for (auto it = args.begin(); it != args.end(); it++) {
if (*it == arg) {
auto next = it + 1;
if (next == args.end())
continue;
auto result = *next;
args.erase(it, it + 2);
return result;
}
}
return default_value;
}
Parameters init_params(const std::string& file_params, int step_alg){
Parameters params;
if (step_alg == LOCAL_STEP){
params.warps = PAR_DEFAULT_NWARPS_LOCAL;
//params.iterations_of = MAX_ITERATIONS_LOCAL; // Defined in local_faldoi
}else{
params.warps = PAR_DEFAULT_NWARPS_GLOBAL;
//params.iterations_of = MAX_ITERATIONS_GLOBAL; // Defined in local_faldoi
}
params.tol_OF = PAR_DEFAULT_TOL_D;
params.verbose = PAR_DEFAULT_VERBOSE;
params.step_algorithm = step_alg;
if (file_params.empty()){
if (params.verbose)
std::cout << "No parameters text file provided..." << std::endl;
params.lambda = PAR_DEFAULT_LAMBDA;
params.beta = PAR_DEFAULT_BETA;
params.theta = PAR_DEFAULT_THETA;
params.tau = PAR_DEFAULT_TAU;
params.alpha = PAR_DEFAULT_ALPHA;
params.tau_u = PAR_DEFAULT_TAU_U;
params.tau_eta = PAR_DEFAULT_TAU_ETA;
params.tau_chi = PAR_DEFAULT_TAU_CHI;
params.mu = PAR_DEFAULT_MU;
}else{
if (params.verbose)
std::cout << "text file provided (will print inputted parameters)..." << std::endl;
std::string::size_type sz;
std::string line;
std::ifstream infile;
infile.open(file_params);
getline(infile, line);
params.lambda = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.lambda: " << params.lambda << std::endl;
}
if (params.lambda <= 0) {
params.lambda = PAR_DEFAULT_LAMBDA;
if (params.verbose) fprintf(stderr, "warning: lambda changed to default: %g\n", params.lambda);
}
params.theta = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.theta: " << params.theta << std::endl;
}
if (params.theta <= 0) {
params.theta = PAR_DEFAULT_THETA;
if (params.verbose) fprintf(stderr, "warning: "
"theta changed to default:%g\n", params.theta);
}
params.tau = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.tau: " << params.tau << std::endl;
}
if (params.tau <= 0 || params.tau > 0.25) {
params.tau = PAR_DEFAULT_TAU;
if (params.verbose) fprintf(stderr, "warning: "
"tau changed to default: %g\n", params.tau);
}
params.beta = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.beta: " << params.beta << std::endl;
}
if (params.beta <= 0) {
params.beta = PAR_DEFAULT_BETA;
if (params.verbose) fprintf(stderr, "warning: "
"beta changed to default: %f\n", params.beta);
}
params.alpha = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.alpha: " << params.tau << std::endl;
}
if (params.alpha <= 0) {
params.alpha = PAR_DEFAULT_ALPHA;
if (params.verbose) fprintf(stderr, "warning: "
"alpha changed to default: %f\n", params.alpha);
}
params.tau_u = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.tau_u: " << params.tau_u << std::endl;
}
if (params.tau_u <= 0 || params.tau_u > 0.25) {
params.tau_u = PAR_DEFAULT_TAU_U;
if (params.verbose) fprintf(stderr, "warning: "
"tau_u changed to default: %g\n", params.tau_u);
}
params.tau_eta = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.tau_eta: " << params.tau_eta << std::endl;
}
if (params.tau_eta <= 0 || params.tau_eta > 0.25) {
params.tau_eta = PAR_DEFAULT_TAU_ETA;
if (params.verbose) fprintf(stderr, "warning: "
"tau_eta changed to default: %g\n", params.tau_eta);
}
params.tau_chi = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.tau_chi: " << params.tau_chi << std::endl;
}
if (params.tau_chi <= 0 || params.tau_chi > 0.25) {
params.tau_chi = PAR_DEFAULT_TAU_CHI;
if (params.verbose) fprintf(stderr, "warning: "
"tau_chi changed to default: %g\n", params.tau_chi);
}
params.mu = std::stof(line, &sz); getline(infile, line);
if (params.verbose) {
std::cout << "params.mu: " << params.mu << std::endl;
}
if (params.mu <= 0) {
params.mu = PAR_DEFAULT_MU;
if (params.verbose) fprintf(stderr, "warning: "
"mu changed to default: %f\n", params.mu);
}
infile.close();
}
return params;
}