-
Notifications
You must be signed in to change notification settings - Fork 1
/
Parameters.h
290 lines (233 loc) · 7.39 KB
/
Parameters.h
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
#ifndef CUDIMOT_PARAMETERS_H_INCLUDED
#define CUDIMOT_PARAMETERS_H_INCLUDED
/**
*
* \class Parameters
*
* \brief A class for managing the Parameters of a Model
*
* This class contains the value of the estimated parameters of a diffusion MRI model. It also contains the value of fixed parameters of the model.
*
* \author Moises Hernandez-Fernandez - FMRIB Image Analysis Group
*
* \date March 2017
*
*
* Copyright (C) 2005 University of Oxford
*/
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "newmat.h"
#include "newimage/newimageall.h"
#include "checkcudacalls.h"
#include "cudimotoptions.h"
#include "Model.h"
#include "dMRI_Data.h"
#include "getPredictedSignal.h"
#include "BIC_AIC.h"
#include "modelparameters.h"
namespace Cudimot{
template <typename T>
class Parameters{
private:
/**
* Number of parameters in the model (to estimate)
*/
int nparams;
////////////////////////////////////////////////////////////////////////
/// FIXED PARAMETERS different for each voxel, nifti volumes (ex.T1) ///
////////////////////////////////////////////////////////////////////////
/**
* Number of Fixed Parameters in the model (different for each voxel)
*/
int nFixP;
/**
* Total size of volumes of Fixed Parameter
*/
int FixP_Tsize;
/**
* Value of the fixed parameters of the voxels of a single part
*/
T* FixP_host;
/**
* Value of the fixed parameters of the voxels of a single part allocated on the GPU
*/
T* FixP_gpu;
/////////////////////////////////////////////////////////////////
/// COMMON (to all voxels) FIXED PARAMETERS (bvals,bvecs,...) ///
/////////////////////////////////////////////////////////////////
/**
* Number of Common Fixed Parameters in the model (common to all voxels)
*/
int nCFP;
/**
* Total size of Common Fixed Parameters (without counting measurements)
*/
int CFP_Tsize;
/**
* Value of the common (to all voxels) fixed parameters
* CFP1_meas1, CFP2_meas1, CFP3_meas1 ... CFP1_meas2, CFP2_meas2 ...
*/
T* CFP_host;
/**
* Value of the common (to all voxels) fixed parameters allocated on the GPU
*/
T* CFP_gpu;
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/**
* Number of Voxels included in the data
*/
int nvox;
/**
* Number of diffusion-weighted measurements in the data
*/
int nmeas;
/**
* The data is divided into parts before beeing processd on the GPU
*/
int nparts;
/**
* Number of voxels of each part of the data
*/
int size_part;
/**
* Number of voxels of the last part of the data
*/
int size_last_part;
/**
* The number of voxels in a part can be a non-multiple of voxels per block, so some threads could access to non-allocated memory. We use the closest upper multiple. The added voxels will be ignored.
*/
int nvoxFit_part;
/**
* Parameter (to estimate) values of all the voxels.
* Voxel 0 [p0,p1,...], Voxel1 [p0,p1,...], etc...
*/
T* params_host;
/**
* Parameter (to estimate) values of the voxels in a single part allocated on the GPU
*/
T* params_gpu;
// For MCMC step
/**
* Value of the samples recorded during MCMC in a single part
*/
T* samples_host;
/**
* Value of the samples recorded during MCMC in a single part and allocated on the GPU
*/
T* samples_gpu;
/**
* Number of samples recorded during MCMC
*/
int nsamples;
/**
* Predicted Signal by the model (on the host)
*/
T* predSignal_host;
/**
* Predicted Signal by the model (on the gpu)
*/
T* predSignal_gpu;
/**
* Class with the method to get the Predicted Signal by the model (on the gpu)
*/
getPredictedSignal<T> PredictedSignal;
/**
* Bayesian information criterion (on the host)
*/
T* BIC_host;
/**
* Bayesian information criterion (on the gpu)
*/
T* BIC_gpu;
/**
* Class with the method to get the Bayesian & Akaike information criteria (on the gpu)
*/
BIC_AIC<T> bic_aic;
/**
* Bayesian information criterion (on the host)
*/
T* AIC_host;
/**
* Bayesian information criterion (on the gpu)
*/
T* AIC_gpu;
/**
* Tau. If rician noise, tau is is 1/sigma with sigma the scale parameter. Values for each voxel/sample on the host.
*/
T* tau_samples_host;
/**
* Tau. If rician noise, tau is is 1/sigma with sigma the scale parameter. Values for each voxel/sample on the GPU.
*/
T* tau_samples_gpu;
public:
/**
* Constructor
* @param model An instance of the class Model with information about the dMRI model
* @param dMRI_data An instance of the class dMRI_data with information about the dMRI data to be analyzed
*/
Parameters(Model<T> model,dMRI_Data<T> dMRI_data);
/**
* Destructor
*/
~Parameters();
/**
* @param part A number to identify a part of the data
* @return A pointer to the estimated parameter values of a part of the data (on the GPU)
*/
T* getParametersPart(int part);
/**
* @return A pointer to the samples recorded during MCMC (on the GPU)
*/
T* getSamples();
/**
* @return Total size of Common Fixed Parameters (without counting measurements)
*/
int getTsize_CFP();
/**
* @return Total size of Fixed Parameters (without counting voxels)
*/
int getTsize_FixP();
/**
* @return A pointer to the Common Fixed Parameters (on the GPU)
*/
T* getCFP();
/**
* @return A pointer to the Fixed Parameters for a part of the data (on the GPU)
*/
T* getFixP_part(int part);
/**
* Copies the value of the estimated parameters of a part from GPU to the host array with all the parameter values (at its correct position).
* @param part A number to identify a part of the data
*/
void copyParamsPartGPU2Host(int part);
/**
* Makes the pointer to the samples to point to the value of the estimated parameters (used id MCMC is not run, i.e. only one sample per parameter)
*/
void copyParams2Samples();
/**
* Copies the samples of the parameters of a part from GPU to the host array with all the samples values (at its correct position)
* @param part A number to identify a part of the data
*/
void copySamplesPartGPU2Host(int part);
/**
* Writes to a binary file the samples of the parameters, Including tau (rician noise), the predicted signal, the BIC and AIC if requested.
*/
void writeSamples();
/**
* @return A pointer to the tau parameter samples of each voxel (on the GPU)
*/
T* getTauSamples();
/**
* If the user ask for the predicted signal or BIC/AIC, calculates the predicted signal or/and the BIC/AIC for this part.
* @param mode 0: from GridSearch or LevMar (1 sample), from MCMC (several samples, needs to calculate the mean)
* @param part A number to identify a part of the data
* @param meas Pointer to Data measurements on the GPU
*/
void calculate_predictedSignal_BIC_AIC(int mode, int part,T* meas);
};
}
#endif