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