1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from Numeric import Float64, zeros
25
26
27
28
29
30
31
32
33
34
35
37 """Spectral density component function.
38
39 Calculate the components of the spectral density value for the original model-free formula with
40 the parameters {S2, te}.
41
42 The model-free formula is:
43
44 _n_
45 2 \ / S2 (1 - S2)(te + ti)te \
46 J(w) = - > ci . ti | ------------ + ------------------------- |
47 5 /__ \ 1 + (w.ti)^2 (te + ti)^2 + (w.te.ti)^2 /
48 i=m
49
50 Replicated calculations are:
51
52 w_ti_sqrd = (w.ti)^2 (pre-calculated during initialisation)
53
54 te_ti = te + ti
55 te_ti_te = (te + ti).te
56
57
58 Calculations which are replicated in the gradient equations are:
59
60 fact_ti = 1 / (1 + (w.ti)^2) (pre-calculated during initialisation)
61
62 one_s2 = 1 - S2
63
64 te_ti_sqrd = (te + ti)^2
65 w_te_ti_sqrd = (w.te.ti)^2
66
67 (te + ti)te
68 fact_te = -------------------------
69 (te + ti)^2 + (w.te.ti)^2
70
71 """
72
73 data.one_s2 = 1.0 - params[data.s2_index]
74
75 data.te_ti = params[data.te_index] + data.ti
76 data.te_ti_te = data.te_ti * params[data.te_index]
77 data.te_ti_sqrd = data.te_ti**2
78 data.w_te_ti_sqrd = data.w_ti_sqrd * params[data.te_index]**2
79 data.inv_te_denom = 1.0 / (data.te_ti_sqrd + data.w_te_ti_sqrd)
80 data.fact_te = data.te_ti_te * data.inv_te_denom
81
82
83
84
85
86
88 """Spectral density component function.
89
90 Calculate the components of the spectral density value for the extended model-free formula with
91 the parameters {S2f, S2, ts}.
92
93 The model-free formula is:
94
95 _n_
96 2 \ / S2 (S2f - S2)(ts + ti)ts \
97 J(w) = - > ci . ti | ------------ + ------------------------- |
98 5 /__ \ 1 + (w.ti)^2 (ts + ti)^2 + (w.ts.ti)^2 /
99 i=m
100
101 Replicated calculations are:
102
103 w_ti_sqrd = (w.ti)^2 (pre-calculated during initialisation)
104
105 ts_ti = ts + ti
106 ts_ti_ts = (ts + ti).ts
107
108
109 Calculations which are replicated in the gradient equations are:
110
111 fact_ti = 1 / (1 + (w.ti)^2) (pre-calculated during initialisation)
112
113 s2f_s2 = S2f - S2
114
115 ts_ti_sqrd = (ts + ti)^2
116 w_ts_ti_sqrd = (w.ts.ti)^2
117 inv_ts_denom = 1 / ((ts + ti)^2 + (w.ts.ti)^2)
118
119 (ts + ti)ts
120 fact_ts = -------------------------
121 (ts + ti)^2 + (w.ts.ti)^2
122
123 """
124
125 data.s2f_s2 = params[data.s2f_index] - params[data.s2_index]
126
127 data.ts_ti = params[data.ts_index] + data.ti
128 data.ts_ti_ts = data.ts_ti * params[data.ts_index]
129 data.ts_ti_sqrd = data.ts_ti**2
130 data.w_ts_ti_sqrd = data.w_ti_sqrd * params[data.ts_index]**2
131 data.inv_ts_denom = 1.0 / (data.ts_ti_sqrd + data.w_ts_ti_sqrd)
132 data.fact_ts = data.ts_ti_ts * data.inv_ts_denom
133
134
135
136
137
138
140 """Spectral density component function.
141
142 Calculate the components of the spectral density value for the extended model-free formula with
143 the parameters {S2f, S2s, ts}.
144
145 The model-free formula is:
146
147 _n_
148 2 \ / S2s (1 - S2s)(ts + ti)ts \
149 J(w) = - S2f > ci . ti | ------------ + ------------------------- |
150 5 /__ \ 1 + (w.ti)^2 (ts + ti)^2 + (w.ts.ti)^2 /
151 i=m
152
153 Replicated calculations are:
154
155 w_ti_sqrd = (w.ti)^2 (pre-calculated during initialisation)
156
157 ts_ti = ts + ti
158 ts_ti_ts = (ts + ti).ts
159
160
161 Calculations which are replicated in the gradient equations are:
162
163 fact_ti = 1 / (1 + (w.ti)^2) (pre-calculated during initialisation)
164
165 one_s2s = 1 - S2s
166
167 ts_ti_sqrd = (ts + ti)^2
168 w_ts_ti_sqrd = (w.ts.ti)^2
169 inv_ts_denom = 1 / ((ts + ti)^2 + (w.ts.ti)^2)
170
171 (ts + ti)ts
172 fact_ts = -------------------------
173 (ts + ti)^2 + (w.ts.ti)^2
174
175 """
176
177 data.one_s2s = 1.0 - params[data.s2s_index]
178
179 data.ts_ti = params[data.ts_index] + data.ti
180 data.ts_ti_ts = data.ts_ti * params[data.ts_index]
181 data.ts_ti_sqrd = data.ts_ti**2
182 data.w_ts_ti_sqrd = data.w_ti_sqrd * params[data.ts_index]**2
183 data.inv_ts_denom = 1.0 / (data.ts_ti_sqrd + data.w_ts_ti_sqrd)
184 data.fact_ts = data.ts_ti_ts * data.inv_ts_denom
185
186
187
188
189
190
192 """Spectral density component function.
193
194 Calculate the components of the spectral density value for the extended model-free formula with
195 the parameters {S2f, tf, S2, ts}.
196
197 The model-free formula is:
198
199 _n_
200 2 \ / S2 (1 - S2f)(tf + ti)tf (S2f - S2)(ts + ti)ts \
201 J(w) = - > ci . ti | ------------ + ------------------------- + ------------------------- |
202 5 /__ \ 1 + (w.ti)^2 (tf + ti)^2 + (w.tf.ti)^2 (ts + ti)^2 + (w.ts.ti)^2 /
203 i=m
204
205 Replicated calculations are:
206
207 w_ti_sqrd = (w.ti)^2 (pre-calculated during initialisation)
208
209 tf_ti = tf + ti
210 ts_ti = ts + ti
211 tf_ti_tf = (tf + ti).tf
212 ts_ti_ts = (ts + ti).ts
213
214
215 Calculations which are replicated in the gradient equations are:
216
217 fact_ti = 1 / (1 + (w.ti)^2) (pre-calculated during initialisation)
218
219 one_s2f = 1 - S2f
220 s2f_s2 = S2f - S2
221
222 tf_ti_sqrd = (tf + ti)^2
223 ts_ti_sqrd = (ts + ti)^2
224 w_tf_ti_sqrd = (w.tf.ti)^2
225 w_ts_ti_sqrd = (w.ts.ti)^2
226 inv_tf_denom = 1 / ((tf + ti)^2 + (w.tf.ti)^2)
227 inv_ts_denom = 1 / ((ts + ti)^2 + (w.ts.ti)^2)
228
229 (tf + ti)tf
230 fact_tf = -------------------------
231 (tf + ti)^2 + (w.tf.ti)^2
232
233
234 (ts + ti)ts
235 fact_ts = -------------------------
236 (ts + ti)^2 + (w.ts.ti)^2
237
238 """
239
240 data.one_s2f = 1.0 - params[data.s2f_index]
241 data.s2f_s2 = params[data.s2f_index] - params[data.s2_index]
242
243 data.tf_ti = params[data.tf_index] + data.ti
244 data.ts_ti = params[data.ts_index] + data.ti
245 data.tf_ti_tf = data.tf_ti * params[data.tf_index]
246 data.ts_ti_ts = data.ts_ti * params[data.ts_index]
247 data.tf_ti_sqrd = data.tf_ti**2
248 data.ts_ti_sqrd = data.ts_ti**2
249 data.w_tf_ti_sqrd = data.w_ti_sqrd * params[data.tf_index]**2
250 data.w_ts_ti_sqrd = data.w_ti_sqrd * params[data.ts_index]**2
251 data.inv_tf_denom = 1.0 / (data.tf_ti_sqrd + data.w_tf_ti_sqrd)
252 data.inv_ts_denom = 1.0 / (data.ts_ti_sqrd + data.w_ts_ti_sqrd)
253 data.fact_tf = data.tf_ti_tf * data.inv_tf_denom
254 data.fact_ts = data.ts_ti_ts * data.inv_ts_denom
255
256
257
258
259
260
262 """Spectral density component function.
263
264 Calculate the components of the spectral density value for the extended model-free formula with
265 the parameters {S2f, tf, S2s, ts}.
266
267 The model-free formula is:
268
269 _n_
270 2 \ / S2f . S2s (1 - S2f)(tf + ti)tf S2f(1 - S2s)(ts + ti)ts \
271 J(w) = - > ci . ti | ------------ + ------------------------- + ------------------------- |
272 5 /__ \ 1 + (w.ti)^2 (tf + ti)^2 + (w.tf.ti)^2 (ts + ti)^2 + (w.ts.ti)^2 /
273 i=m
274
275 Replicated calculations are:
276
277 w_ti_sqrd = (w.ti)^2 (pre-calculated during initialisation)
278
279 tf_ti = tf + ti
280 ts_ti = ts + ti
281 tf_ti_tf = (tf + ti).tf
282 ts_ti_ts = (ts + ti).ts
283
284
285 Calculations which are replicated in the gradient equations are:
286
287 fact_ti = 1 / (1 + (w.ti)^2) (pre-calculated during initialisation)
288
289 one_s2s = 1 - S2s
290 one_s2f = 1 - S2f
291 s2f_s2 = S2f(1 - S2s) = S2f - S2
292
293 tf_ti_sqrd = (tf + ti)^2
294 ts_ti_sqrd = (ts + ti)^2
295 w_tf_ti_sqrd = (w.tf.ti)^2
296 w_ts_ti_sqrd = (w.ts.ti)^2
297 inv_tf_denom = 1 / ((tf + ti)^2 + (w.tf.ti)^2)
298 inv_ts_denom = 1 / ((ts + ti)^2 + (w.ts.ti)^2)
299
300 (tf + ti)tf
301 fact_tf = -------------------------
302 (tf + ti)^2 + (w.tf.ti)^2
303
304
305 (ts + ti)ts
306 fact_ts = -------------------------
307 (ts + ti)^2 + (w.ts.ti)^2
308
309 """
310
311 data.one_s2s = 1.0 - params[data.s2s_index]
312 data.one_s2f = 1.0 - params[data.s2f_index]
313 data.s2f_s2 = params[data.s2f_index] * data.one_s2s
314
315 data.tf_ti = params[data.tf_index] + data.ti
316 data.ts_ti = params[data.ts_index] + data.ti
317 data.tf_ti_tf = data.tf_ti * params[data.tf_index]
318 data.ts_ti_ts = data.ts_ti * params[data.ts_index]
319 data.tf_ti_sqrd = data.tf_ti**2
320 data.ts_ti_sqrd = data.ts_ti**2
321 data.w_tf_ti_sqrd = data.w_ti_sqrd * params[data.tf_index]**2
322 data.w_ts_ti_sqrd = data.w_ti_sqrd * params[data.ts_index]**2
323 data.inv_tf_denom = 1.0 / (data.tf_ti_sqrd + data.w_tf_ti_sqrd)
324 data.inv_ts_denom = 1.0 / (data.ts_ti_sqrd + data.w_ts_ti_sqrd)
325 data.fact_tf = data.tf_ti_tf * data.inv_tf_denom
326 data.fact_ts = data.ts_ti_ts * data.inv_ts_denom
327
328
329
330
331
332
333
334
335
336
337
338
340 """Spectral density gradient component function.
341
342 Calculate the components of the spectral density gradient for the original model-free formula
343 with no parameters {} or the parameter {S2} together with diffusion tensor parameters.
344
345 Replicated calculations are:
346
347 1 - (w.ti)^2
348 fact_ti_djw_dti = ----------------
349 (1 + (w.ti)^2)^2
350 """
351
352 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
353
354
355
356
357
358
360 """Spectral density gradient component function.
361
362 Calculate the components of the spectral density gradient for the original model-free formula
363 with the parameters {S2, te}.
364
365 Replicated calculations are:
366
367 (te + ti)^2 - (w.te.ti)^2
368 fact_djw_dte = ti^2 -----------------------------
369 ((te + ti)^2 + (w.te.ti)^2)^2
370 """
371
372 data.fact_djw_dte = data.ti**2 * (data.te_ti_sqrd - data.w_te_ti_sqrd) * data.inv_te_denom**2
373
374
375
376
377
378
380 """Spectral density gradient component function.
381
382 Calculate the components of the spectral density gradient for the original model-free formula
383 with the parameters {S2, te} together with diffusion tensor parameters.
384
385 Replicated calculations are:
386
387 (te + ti)^2 - (w.te.ti)^2
388 fact_djw = -----------------------------
389 ((te + ti)^2 + (w.te.ti)^2)^2
390
391 1 - (w.ti)^2
392 fact_ti_djw_dti = ----------------
393 (1 + (w.ti)^2)^2
394
395 (te + ti)^2 - (w.te.ti)^2
396 fact_te_djw_dti = te^2 -----------------------------
397 ((te + ti)^2 + (w.te.ti)^2)^2
398
399 (te + ti)^2 - (w.te.ti)^2
400 fact_djw_dte = ti^2 -----------------------------
401 ((te + ti)^2 + (w.te.ti)^2)^2
402 """
403
404 fact_djw = (data.te_ti_sqrd - data.w_te_ti_sqrd) * data.inv_te_denom**2
405 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
406 data.fact_te_djw_dti = params[data.te_index]**2 * fact_djw
407 data.fact_djw_dte = data.ti**2 * fact_djw
408
409
410
411
412
413
415 """Spectral density gradient component function.
416
417 Calculate the components of the spectral density gradient for the extended model-free formula
418 with the parameters {S2f, S2, ts}.
419
420 Replicated calculations are:
421
422
423 (ts + ti)^2 - (w.ts.ti)^2
424 fact_djw_dts = ti^2 -----------------------------
425 ((ts + ti)^2 + (w.ts.ti)^2)^2
426 """
427
428 data.fact_djw_dts = data.ti**2 * (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
429
430
431
432
433
434
436 """Spectral density gradient component function.
437
438 Calculate the components of the spectral density gradient for the extended model-free formula
439 with the parameters {S2f, S2, ts} together with diffusion tensor parameters.
440
441 Replicated calculations are:
442
443 (ts + ti)^2 - (w.ts.ti)^2
444 fact_djw = -----------------------------
445 ((ts + ti)^2 + (w.ts.ti)^2)^2
446
447
448 1 - (w.ti)^2
449 fact_ti_djw_dti = ----------------
450 (1 + (w.ti)^2)^2
451
452
453 (ts + ti)^2 - (w.ts.ti)^2
454 fact_ts_djw_dti = ts^2 -----------------------------
455 ((ts + ti)^2 + (w.ts.ti)^2)^2
456
457
458 (ts + ti)^2 - (w.ts.ti)^2
459 fact_djw_dts = ti^2 -----------------------------
460 ((ts + ti)^2 + (w.ts.ti)^2)^2
461 """
462
463
464 fact_djw = (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
465 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
466 data.fact_ts_djw_dti = params[data.ts_index]**2 * fact_djw
467 data.fact_djw_dts = data.ti**2 * fact_djw
468
469
470
471
472
473
475 """Spectral density gradient component function.
476
477 Calculate the components of the spectral density gradient for the extended model-free formula
478 with the parameters {S2f, tf, S2, ts}.
479
480 Replicated calculations are:
481
482 (tf + ti)^2 - (w.tf.ti)^2
483 fact_djw_dtf = ti^2 -----------------------------
484 ((tf + ti)^2 + (w.tf.ti)^2)^2
485
486
487 (ts + ti)^2 - (w.ts.ti)^2
488 fact_djw_dts = ti^2 -----------------------------
489 ((ts + ti)^2 + (w.ts.ti)^2)^2
490 """
491
492 data.fact_djw_dtf = data.ti**2 * (data.tf_ti_sqrd - data.w_tf_ti_sqrd) * data.inv_tf_denom**2
493 data.fact_djw_dts = data.ti**2 * (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
494
495
496
497
498
499
501 """Spectral density gradient component function.
502
503 Calculate the components of the spectral density gradient for the extended model-free formula
504 with the parameters {S2f, tf, S2, ts} together with diffusion tensor parameters.
505
506 Replicated calculations are:
507
508 (tf + ti)^2 - (w.tf.ti)^2
509 fact_tf_djw = -----------------------------
510 ((tf + ti)^2 + (w.tf.ti)^2)^2
511
512
513 (ts + ti)^2 - (w.ts.ti)^2
514 fact_ts_djw = -----------------------------
515 ((ts + ti)^2 + (w.ts.ti)^2)^2
516
517
518 1 - (w.ti)^2
519 fact_ti_djw_dti = ----------------
520 (1 + (w.ti)^2)^2
521
522
523 (tf + ti)^2 - (w.tf.ti)^2
524 fact_tf_djw_dti = tf^2 -----------------------------
525 ((tf + ti)^2 + (w.tf.ti)^2)^2
526
527
528 (ts + ti)^2 - (w.ts.ti)^2
529 fact_ts_djw_dti = ts^2 -----------------------------
530 ((ts + ti)^2 + (w.ts.ti)^2)^2
531
532
533 (tf + ti)^2 - (w.tf.ti)^2
534 fact_djw_dtf = ti^2 -----------------------------
535 ((tf + ti)^2 + (w.tf.ti)^2)^2
536
537
538 (ts + ti)^2 - (w.ts.ti)^2
539 fact_djw_dts = ti^2 -----------------------------
540 ((ts + ti)^2 + (w.ts.ti)^2)^2
541 """
542
543
544 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
545
546
547 fact_tf_djw = (data.tf_ti_sqrd - data.w_tf_ti_sqrd) * data.inv_tf_denom**2
548 data.fact_tf_djw_dti = params[data.tf_index]**2 * fact_tf_djw
549 data.fact_djw_dtf = data.ti**2 * fact_tf_djw
550
551
552 fact_ts_djw = (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
553 data.fact_ts_djw_dti = params[data.ts_index]**2 * fact_ts_djw
554 data.fact_djw_dts = data.ti**2 * fact_ts_djw
555
556
557
558
559
560
562 """Spectral density gradient component function.
563
564 Calculate the components of the spectral density gradient for the extended model-free formula
565 with the parameters {S2f, S2s, ts}.
566
567 Replicated calculations are:
568
569 (ts + ti)^2 - (w.ts.ti)^2
570 fact_djw_dts = ti^2 -----------------------------
571 ((ts + ti)^2 + (w.ts.ti)^2)^2
572 """
573
574 data.fact_djw_dts = data.ti**2 * (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
575
576
577
578
579
580
582 """Spectral density gradient component function.
583
584 Calculate the components of the spectral density gradient for the extended model-free formula
585 with the parameters {S2f, S2s, ts} together with diffusion tensor parameters.
586
587 Replicated calculations are:
588
589 (ts + ti)^2 - (w.ts.ti)^2
590 fact_djw = -----------------------------
591 ((ts + ti)^2 + (w.ts.ti)^2)^2
592
593
594 1 - (w.ti)^2
595 fact_ti_djw_dti = ----------------
596 (1 + (w.ti)^2)^2
597
598
599 (ts + ti)^2 - (w.ts.ti)^2
600 fact_te_djw_dti = ts^2 -----------------------------
601 ((ts + ti)^2 + (w.ts.ti)^2)^2
602
603
604 (ts + ti)^2 - (w.ts.ti)^2
605 fact_djw_dts = ti^2 -----------------------------
606 ((ts + ti)^2 + (w.ts.ti)^2)^2
607 """
608
609 fact_djw = (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
610 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
611 data.fact_te_djw_dti = params[data.ts_index]**2 * fact_djw
612 data.fact_djw_dts = data.ti**2 * fact_djw
613
614
615
616
617
618
620 """Spectral density gradient component function.
621
622 Calculate the components of the spectral density gradient for the extended model-free formula
623 with the parameters {S2f, tf, S2s, ts}.
624
625 Replicated calculations are:
626
627 (tf + ti)^2 - (w.tf.ti)^2
628 fact_djw_dtf = ti^2 -----------------------------
629 ((tf + ti)^2 + (w.tf.ti)^2)^2
630
631
632 (ts + ti)^2 - (w.ts.ti)^2
633 fact_djw_dts = ti^2 -----------------------------
634 ((ts + ti)^2 + (w.ts.ti)^2)^2
635 """
636
637 data.fact_djw_dtf = data.ti**2 * (data.tf_ti_sqrd - data.w_tf_ti_sqrd) * data.inv_tf_denom**2
638 data.fact_djw_dts = data.ti**2 * (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
639
640
641
642
643
644
646 """Spectral density gradient component function.
647
648 Calculate the components of the spectral density gradient for the extended model-free formula
649 with the parameters {S2f, tf, S2, ts} together with diffusion tensor parameters.
650
651 Replicated calculations are:
652
653 (tf + ti)^2 - (w.tf.ti)^2
654 fact_tf_djw = -----------------------------
655 ((tf + ti)^2 + (w.tf.ti)^2)^2
656
657
658 (ts + ti)^2 - (w.ts.ti)^2
659 fact_ts_djw = -----------------------------
660 ((ts + ti)^2 + (w.ts.ti)^2)^2
661
662
663 1 - (w.ti)^2
664 fact_ti_djw_dti = ----------------
665 (1 + (w.ti)^2)^2
666
667
668 (tf + ti)^2 - (w.tf.ti)^2
669 fact_tf_djw_dti = tf^2 -----------------------------
670 ((tf + ti)^2 + (w.tf.ti)^2)^2
671
672
673 (ts + ti)^2 - (w.ts.ti)^2
674 fact_ts_djw_dti = ts^2 -----------------------------
675 ((ts + ti)^2 + (w.ts.ti)^2)^2
676
677
678 (tf + ti)^2 - (w.tf.ti)^2
679 fact_djw_dtf = ti^2 -----------------------------
680 ((tf + ti)^2 + (w.tf.ti)^2)^2
681
682
683 (ts + ti)^2 - (w.ts.ti)^2
684 fact_djw_dts = ti^2 -----------------------------
685 ((ts + ti)^2 + (w.ts.ti)^2)^2
686 """
687
688
689 data.fact_ti_djw_dti = (1.0 - data.w_ti_sqrd) * data.fact_ti**2
690
691
692 fact_tf_djw = (data.tf_ti_sqrd - data.w_tf_ti_sqrd) * data.inv_tf_denom**2
693 data.fact_tf_djw_dti = params[data.tf_index]**2 * fact_tf_djw
694 data.fact_djw_dtf = data.ti**2 * fact_tf_djw
695
696
697 fact_ts_djw = (data.ts_ti_sqrd - data.w_ts_ti_sqrd) * data.inv_ts_denom**2
698 data.fact_ts_djw_dti = params[data.ts_index]**2 * fact_ts_djw
699 data.fact_djw_dts = data.ti**2 * fact_ts_djw
700