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