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