-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
335 lines (307 loc) · 10.9 KB
/
main.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include <iostream>
#include <string>
#include <cmath>
#ifndef CCODE
#include <Rcpp.h>
#endif
// redeclare the drive funciton
int drive( const std::string& dataFile, const std::string& mrfGFile, const std::string& blockFile, const std::string& structureGraphFile, const std::string& hyperParFile, const std::string& outFilePath,
unsigned int nIter, unsigned int burnin, unsigned int nChains,
const std::string& covariancePrior,
const std::string& gammaPrior, const std::string& gammaSampler, const std::string& gammaInit,
const std::string& betaPrior,
bool output_gamma, bool output_beta, bool output_G, bool output_sigmaRho, bool output_pi, bool output_tail, bool output_model_size, bool output_CPO, bool output_model_visit );
int main(int argc, char* argv[])
{
unsigned int nIter = 10; // default number of iterations
unsigned int burnin = 0;
unsigned int nChains = 1;
std::string dataFile = "data.txt";
std::string mrfGFile = "mrfG.txt";
std::string blockFile = "blocks.txt";
std::string structureGraphFile = "structureGraph.txt";
std::string hpFile = "model.xml";
std::string outFilePath = "";
std::string covariancePrior = "";
std::string gammaPrior = "";
// std::string mrfGFile = "";
std::string gammaSampler = "bandit";
std::string gammaInit = "MLE";
std::string betaPrior = "independent";
bool out_gamma = true, out_beta = true, out_G = true,
out_sigmaRho = true, out_pi = true, out_tail = true,
out_model_size = true, out_CPO = true, out_model_visit = false;
// ### Read and interpret command line (to put in a separate file / function?)
int na = 1;
while(na < argc)
{
if ( 0 == std::string{argv[na]}.compare(std::string{"--covariancePrior"}) )
{
covariancePrior = std::string(argv[++na]); // use the next
if ( covariancePrior == "sparse" || covariancePrior == "Sparse" || covariancePrior == "SPARSE" || covariancePrior == "HIW" || covariancePrior == "hiw" )
covariancePrior = "HIW";
else if ( covariancePrior == "dense" || covariancePrior == "Dense" || covariancePrior == "DENSE" || covariancePrior == "IW" || covariancePrior == "iw" )
covariancePrior = "IW";
else if ( covariancePrior == "independent" || covariancePrior == "Independent" || covariancePrior == "INDEPENDENT" || covariancePrior == "INDEP" || covariancePrior == "indep" || covariancePrior == "IG" || covariancePrior == "ig" )
covariancePrior = "IG";
else
{
std::cout << "Unknown covariancePrior argument: only sparse (HIW), dense(IW) or independent (IG) are available" << std::endl;
return(1);
}
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--mrfGFile"}) )
{
mrfGFile = ""+std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--gammaPrior"}) )
{
gammaPrior = std::string(argv[++na]); // use the next
if ( gammaPrior == "hotspot" || gammaPrior == "HOTSPOT" || gammaPrior == "hotspots" || gammaPrior == "HOTSPOTS" || gammaPrior == "hs" || gammaPrior == "HS" )
gammaPrior = "hotspot";
else if ( gammaPrior == "MRF" || gammaPrior == "mrf" || gammaPrior == "markov random field" || gammaPrior == "Markov Random Field" )
gammaPrior = "MRF";
else if ( gammaPrior == "hierarchical" || gammaPrior == "h" || gammaPrior == "H" )
gammaPrior = "hierarchical";
else
{
std::cout << "Unknown gammaPrior argument: only hotspot, MRF or hierarchical are available" << std::endl;
return(1);
}
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--gammaSampler"}) )
{
gammaSampler = std::string(argv[++na]); // use the next
if ( gammaSampler == "MC3" || gammaSampler == "mc3" )
gammaSampler = "MC3";
else if ( gammaSampler == "Bandit" || gammaSampler == "bandit" || gammaSampler == "BANDIT" )
gammaSampler = "bandit";
else
{
std::cout << "Unknown gammaSampler method: only Bandit or MC3 are available" << std::endl;
return(1);
}
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--gammaInit"}) )
{
gammaInit = std::string(argv[++na]); // use the next
if( gammaInit != "R" && gammaInit != "0" && gammaInit != "1" && gammaInit != "MLE")
{
std::cout << "Unknown gammaInit method: only allowed:\n\t*\tR: random init (0.5 probability)\n\t*\t0: all elements set to 0\n\t*\t1: all elements set to 1\n\t*\tMLE: computes MLE for beta and init gamma for all significant coeffs" << std::endl;
return(1);
}
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--betaPrior"}) )
{
betaPrior = std::string(argv[++na]); // use the next
if ( betaPrior == "independent" || betaPrior == "Independent" || betaPrior == "INDEPENDENT" || betaPrior == "indep" || betaPrior == "Indep" || betaPrior == "i" || betaPrior == "I" )
betaPrior = "independent";
else if ( betaPrior == "gprior" || betaPrior == "gPrior" || betaPrior == "g-prior" || betaPrior == "G-Prior" || betaPrior == "GPRIOR" )
betaPrior = "g-prior";
else
{
std::cout << "Unknown betaPrior method: only independent is available as of yet" << std::endl;
return(1);
}
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--nIter"}) )
{
nIter = std::stoi(argv[++na]);
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--burnin"}) )
{
burnin = std::stoi(argv[++na]);
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--nChains"}) )
{
nChains = std::stoi(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--dataFile"}) )
{
dataFile = ""+std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--blockFile"}) )
{
blockFile = ""+std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--structureGraphFile"}) )
{
structureGraphFile = ""+std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--parFile"}) || 0 == std::string{argv[na]}.compare(std::string{"--hyperparFile"}) )
{
hpFile = ""+std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--outFilePath"}) )
{
outFilePath = std::string(argv[++na]); // use the next
if (na+1==argc) break; // in case it's last, break
++na; // otherwise augment counter
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--gammaOut"}) ) // From here set outputs
{
out_gamma = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOGammaOut"}) )
{
out_gamma = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--betaOut"}) )
{
out_beta = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOBetaOut"}) )
{
out_beta = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--GOut"}) )
{
out_G = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOGOut"}) )
{
out_G = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--sigmaRhoOut"}) )
{
out_sigmaRho = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOSigmaRhoOut"}) )
{
out_sigmaRho = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--piOut"}) )
{
out_pi = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOPiOut"}) )
{
out_pi = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--tailOut"}) )
{
out_tail = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOTailOut"}) )
{
out_tail = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--modelSizeOut"}) )
{
out_model_size = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOModelSizeOut"}) )
{
out_model_size = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--CPOOut"}) )
{
out_CPO = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOCPOOut"}) )
{
out_CPO = false;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--ModelVisitOut"}) )
{
out_model_visit = true;
if (na+1==argc) break;
++na;
}
else if ( 0 == std::string{argv[na]}.compare(std::string{"--NOModelVisitOut"}) )
{
out_model_visit = false;
if (na+1==argc) break;
++na;
}
else
{
std::cout << "Unknown option: " << argv[na] << std::endl;
return(1);
}
}//end reading from command line
if( gammaPrior == "" )
{
if ( mrfGFile == "" )
{
std::cout << "Using default prior for Gamma - hotspot prior" << std::endl;
gammaPrior = "hotspot";
}
else
{
std::cout << "No value for gammaPrior was specified, but mrfG was given - choosing MRF prior" << std::endl;
gammaPrior = "MRF";
}
}
int status{1};
try
{
status = drive(dataFile,mrfGFile,blockFile,structureGraphFile,hpFile,outFilePath,
nIter,burnin,nChains,
covariancePrior,gammaPrior,gammaSampler,gammaInit,betaPrior,
out_gamma,out_beta,out_G,out_sigmaRho,out_pi,out_tail,out_model_size,out_CPO,out_model_visit);
}
catch(const std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return status;
}