-
Notifications
You must be signed in to change notification settings - Fork 1
/
cudimot.cc
133 lines (108 loc) · 3.77 KB
/
cudimot.cc
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
/* cudimot.cc
Moises Hernandez-Fernandez - FMRIB Image Analysis Group
Copyright (C) 2005 University of Oxford */
#include <sys/time.h>
//#include <boost/filesystem/operations.hpp>
//#include <boost/filesystem/path.hpp>
#include "cudimotoptions.h"
#include "init_gpu.h"
#include "dMRI_Data.h"
#include "Model.h"
#include "Parameters.h"
#include "GridSearch.h"
#include "Levenberg_Marquardt.h"
#include "MCMC.h"
using namespace Cudimot;
double timeval_diff(struct timeval *a, struct timeval *b){
return (double)(a->tv_sec +(double)a->tv_usec/1000000) - (double)(b->tv_sec +(double)b->tv_usec/1000000);
}
int main(int argc, char *argv[]){
struct timeval t1,t2;
double time;
gettimeofday(&t1,NULL);
// Setup logging:
Log& logger = LogSingleton::getInstance();
cudimotOptions& opts = cudimotOptions::getInstance();
opts.parse_command_line(argc,argv,logger);
srand(opts.seed.value()); //randoms seed
init_gpu();
// Check if GridSearch, MCMC or LevMar flags
if(opts.gridSearch.value()=="" && opts.no_LevMar.value() && !opts.runMCMC.value()){
cerr << "CUDIMOT Error: You must select at least one method to fit the model: GridSearch, Levenberg_Marquardt or MCMC" << endl;
exit(-1);
}
// Encapsulate dMRI data
dMRI_Data<MyType> data;
// get path of this binary to get the priors file
char buf[1024];
ssize_t count = readlink("/proc/self/exe",buf,sizeof(buf)-1);
string bin_path(buf,(count > 0) ? count : 0 );
string default_priors_file(bin_path+"_priors");
Model<MyType> model(default_priors_file);
Parameters<MyType> params(model,data);
GridSearch<MyType> methodGridSearch(model.getNGridParams(),
model.getGridParams(),
model.getGridCombs(),
model.getGrid(),
model.getBound_types(),
model.getBounds_min(),
model.getBounds_max());
Levenberg_Marquardt<MyType> methodLM(model.getBound_types(),
model.getBounds_min(),
model.getBounds_max(),
model.getFixed());
MCMC<MyType> methodMCMC(data.getNvoxFit_part(),
model.getBound_types(),
model.getBounds_min(),
model.getBounds_max(),
model.getPrior_types(),
model.getPriors_a(),
model.getPriors_b(),
model.getFixed());
// Data and parameters are divided into parts => process each part
for(int part=0;part<data.getNparts();part++){
int part_size=0;
MyType* meas=data.getMeasPart(part,part_size);
MyType* parameters_part = params.getParametersPart(part);
if(opts.gridSearch.value()!=""){
methodGridSearch.run(part_size,data.getNmeas(),
params.getTsize_CFP(),
params.getTsize_FixP(),
meas,parameters_part,
params.getCFP(),
params.getFixP_part(part));
}
if(!opts.no_LevMar.value()){
methodLM.run(part_size,data.getNmeas(),
params.getTsize_CFP(),
params.getTsize_FixP(),
meas,parameters_part,
params.getCFP(),
params.getFixP_part(part));
}
if(!opts.runMCMC.value()){
params.copyParamsPartGPU2Host(part);
params.calculate_predictedSignal_BIC_AIC(0,part,meas);
}else{
methodMCMC.run(part_size,data.getNmeas(),
params.getTsize_CFP(),
params.getTsize_FixP(),
meas,parameters_part,
params.getCFP(),
params.getFixP_part(part),
params.getSamples(),
params.getTauSamples());
params.copyParamsPartGPU2Host(part);
params.copySamplesPartGPU2Host(part);
params.calculate_predictedSignal_BIC_AIC(1,part,meas);
}
}
if(!opts.runMCMC.value()){
// only 1 sample, the value of parameters
params.copyParams2Samples();
}
params.writeSamples();
gettimeofday(&t2,NULL);
time=timeval_diff(&t2,&t1);
cout << endl << "Part processed in: " << time << " seconds" << endl;
}