2020#
2121# https://www.nipreps.org/community/licensing/
2222#
23- r"""
24- Derivations from scikit-learn for Gaussian Processes.
25-
26-
27- Gaussian Process Model: Pairwise orientation angles
28- ---------------------------------------------------
29- Squared Exponential covariance kernel
30- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31- Kernel based on a squared exponential function for Gaussian processes on
32- multi-shell DWI data following to eqs. 14 and 16 in [Andersson15]_.
33- For a 2-shell case, the :math:`\mathbf{K}` kernel can be written as:
34-
35- .. math::
36- \begin{equation}
37- \mathbf{K} = \left[
38- \begin{matrix}
39- \lambda C_{\theta}(\theta (\mathbf{G}_{1}); a) + \sigma_{1}^{2} \mathbf{I} &
40- \lambda C_{\theta}(\theta (\mathbf{G}_{2}, \mathbf{G}_{1}); a) C_{b}(b_{2}, b_{1}; \ell) \\
41- \lambda C_{\theta}(\theta (\mathbf{G}_{1}, \mathbf{G}_{2}); a) C_{b}(b_{1}, b_{2}; \ell) &
42- \lambda C_{\theta}(\theta (\mathbf{G}_{2}); a) + \sigma_{2}^{2} \mathbf{I} \\
43- \end{matrix}
44- \right]
45- \end{equation}
46-
47- **Squared exponential shell-wise covariance kernel**:
48- Compute the squared exponential smooth function describing how the
49- covariance changes along the b direction.
50- It uses the log of the b-values as the measure of distance along the
51- b-direction according to eq. 15 in [Andersson15]_.
52-
53- .. math::
54- C_{b}(b, b'; \ell) = \exp\left( - \frac{(\log b - \log b')^2}{2 \ell^2} \right).
55-
56- **Squared exponential covariance kernel**:
57- Compute the squared exponential covariance matrix following to eq. 14 in [Andersson15]_.
58-
59- .. math::
60- k(\textbf{x}, \textbf{x'}) = C_{\theta}(\mathbf{g}, \mathbf{g'}; a) C_{b}(|b - b'|; \ell)
61-
62- where :math:`C_{\theta}` is given by:
63-
64- .. math::
65- \begin{equation}
66- C(\theta) =
67- \begin{cases}
68- 1 - \frac{3 \theta}{2 a} + \frac{\theta^3}{2 a^3} & \textnormal{if} \; \theta \leq a \\
69- 0 & \textnormal{if} \; \theta > a
70- \end{cases}
71- \end{equation}
72-
73- :math:`\theta` being computed as:
74-
75- .. math::
76- \theta(\mathbf{g}, \mathbf{g'}) = \arccos(|\langle \mathbf{g}, \mathbf{g'} \rangle|)
77-
78- and :math:`C_{b}` is given by:
79-
80- .. math::
81- C_{b}(b, b'; \ell) = \exp\left( - \frac{(\log b - \log b')^2}{2 \ell^2} \right)
82-
83- :math:`b` and :math:`b'` being the b-values, and :math:`\mathbf{g}` and
84- :math:`\mathbf{g'}` the unit diffusion-encoding gradient unit vectors of the
85- shells; and :math:`{a, \ell}` some hyperparameters.
86-
87- """
23+ """Derivations from scikit-learn for Gaussian Processes."""
8824
8925from __future__ import annotations
9026
@@ -175,6 +111,44 @@ class EddyMotionGPR(GaussianProcessRegressor):
175111 frequently better at avoiding local maxima.
176112 Hence, that was the method we used for all optimisations in the present
177113 paper.
114+
115+ **Multi-shell regression (TODO).**
116+ For multi-shell modeling, the kernel :math:`k(\textbf{x}, \textbf{x'})`
117+ is updated following Eq. (14) in [Andersson15]_.
118+
119+ .. math::
120+ k(\textbf{x}, \textbf{x'}) = C_{\theta}(\mathbf{g}, \mathbf{g'}; a) C_{b}(|b - b'|; \ell)
121+
122+ and :math:`C_{b}` is based the log of the b-values ratio, a measure of distance along the
123+ b-direction, according to Eq. (15) given by:
124+
125+ .. math::
126+ C_{b}(b, b'; \ell) = \exp\left( - \frac{(\log b - \log b')^2}{2 \ell^2} \right),
127+
128+ :math:`b` and :math:`b'` being the b-values, and :math:`\mathbf{g}` and
129+ :math:`\mathbf{g'}` the unit diffusion-encoding gradient unit vectors of the
130+ shells; and :math:`{a, \ell}` some hyperparameters.
131+
132+ The full GP regression kernel :math:`\mathbf{K}` is then updated for a 2-shell case as
133+ follows (Eq. (16) in [Andersson15]_):
134+
135+ .. math::
136+ \begin{equation}
137+ \mathbf{K} = \left[
138+ \begin{matrix}
139+ \lambda C_{\theta}(\theta (\mathbf{G}_{1}); a) + \sigma_{1}^{2} \mathbf{I} &
140+ \lambda C_{\theta}(\theta (\mathbf{G}_{2}, \mathbf{G}_{1}); a) C_{b}(b_{2}, b_{1}; \ell) \\
141+ \lambda C_{\theta}(\theta (\mathbf{G}_{1}, \mathbf{G}_{2}); a) C_{b}(b_{1}, b_{2}; \ell) &
142+ \lambda C_{\theta}(\theta (\mathbf{G}_{2}); a) + \sigma_{2}^{2} \mathbf{I} \\
143+ \end{matrix}
144+ \right]
145+ \end{equation}
146+
147+ References
148+ ----------
149+ .. [Andersson15] J. L. R. Andersson. et al., An integrated approach to
150+ correction for off-resonance effects and subject movement in diffusion MR
151+ imaging, NeuroImage 125 (2016) 1063-11078
178152
179153 """
180154
@@ -497,9 +471,21 @@ def __repr__(self) -> str:
497471
498472
499473def exponential_covariance (theta : np .ndarray , a : float ) -> np .ndarray :
500- """
474+ r """
501475 Compute the exponential covariance for given distances and scale parameter.
502476
477+ Implements :math:`C_{\theta}`, following Eq. (9) in [Andersson15]_:
478+
479+ .. math::
480+ \begin{equation}
481+ C(\theta) = e^{-\theta/a} \,\, \text{for} \, 0 \leq \theta \leq \pi,
482+ \end{equation}
483+
484+ :math:`\theta` being computed as:
485+
486+ .. math::
487+ \theta(\mathbf{g}, \mathbf{g'}) = \arccos(|\langle \mathbf{g}, \mathbf{g'} \rangle|)
488+
503489 Parameters
504490 ----------
505491 theta : :obj:`~numpy.ndarray`
@@ -517,9 +503,25 @@ def exponential_covariance(theta: np.ndarray, a: float) -> np.ndarray:
517503
518504
519505def spherical_covariance (theta : np .ndarray , a : float ) -> np .ndarray :
520- """
506+ r """
521507 Compute the spherical covariance for given distances and scale parameter.
522508
509+ Implements :math:`C_{\theta}`, following Eq. (10) in [Andersson15]_:
510+
511+ .. math::
512+ \begin{equation}
513+ C(\theta) =
514+ \begin{cases}
515+ 1 - \frac{3 \theta}{2 a} + \frac{\theta^3}{2 a^3} & \textnormal{if} \; \theta \leq a \\
516+ 0 & \textnormal{if} \; \theta > a
517+ \end{cases}
518+ \end{equation}
519+
520+ :math:`\theta` being computed as:
521+
522+ .. math::
523+ \theta(\mathbf{g}, \mathbf{g'}) = \arccos(|\langle \mathbf{g}, \mathbf{g'} \rangle|)
524+
523525 Parameters
524526 ----------
525527 theta : :obj:`~numpy.ndarray`
@@ -583,12 +585,6 @@ def compute_pairwise_angles(
583585 >>> compute_pairwise_angles(X)[0, 1]
584586 0.0
585587
586- References
587- ----------
588- .. [Andersson15] J. L. R. Andersson. et al., An integrated approach to
589- correction for off-resonance effects and subject movement in diffusion MR
590- imaging, NeuroImage 125 (2016) 1063-11078
591-
592588 """
593589
594590 cosines = np .clip (cosine_similarity (X , Y , dense_output = dense_output ), - 1.0 , 1.0 )
0 commit comments