class_docstr: Class for fitting the Diffusion Kurtosis Model
docstr: Compute mean kurtosis (MK) from the kurtosis tensor
  
  Parameters
  ----------
  min_kurtosis : float (optional)
      To keep kurtosis values within a plausible biophysical range, mean
      kurtosis values that are smaller than `min_kurtosis` are replaced
      with `min_kurtosis`. Default = -3./7 (theoretical kurtosis limit
      for regions that consist of water confined to spherical pores [4]_)
  max_kurtosis : float (optional)
      To keep kurtosis values within a plausible biophysical range, mean
      kurtosis values that are larger than `max_kurtosis` are replaced
      with `max_kurtosis`. Default = 10
  analytical : bool (optional)
      If True, MK is calculated using its analytical solution, otherwise
      an exact numerical estimator is used (see Notes). Default is set to
      True.
  
  Returns
  -------
  mk : array
      Calculated MK.
  
  Notes
  -----
  The MK is defined as the average of directional kurtosis coefficients
  across all spatial directions, which can be formulated by the following
  surface integral[1]_:
  
  .. math::
  
       MK \equiv \frac{1}{4\pi} \int d\Omega_\mathbf{n} K(\mathbf{n})
  
  This integral can be numerically solved by averaging directional
  kurtosis values sampled for directions of a spherical t-design [2]_.
  
  Alternatively, MK can be solved from the analytical solution derived by
  Tabesh et al. [3]_. This solution is given by:
  
  .. math::
  
      MK=F_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{1111}+
         F_1(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{2222}+
         F_1(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{3333}+ \\
         F_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}+
         F_2(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{1133}+
         F_2(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{1122}
  
  where $\hat{W}_{ijkl}$ are the components of the $W$ tensor in the
  coordinates system defined by the eigenvectors of the diffusion tensor
  $\mathbf{D}$ and
  
  .. math::
  
      F_1(\lambda_1,\lambda_2,\lambda_3)=
      \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
      {18(\lambda_1-\lambda_2)(\lambda_1-\lambda_3)}
      [\frac{\sqrt{\lambda_2\lambda_3}}{\lambda_1}
      R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
      \frac{3\lambda_1^2-\lambda_1\lambda_2-\lambda_2\lambda_3-
      \lambda_1\lambda_3}
      {3\lambda_1 \sqrt{\lambda_2 \lambda_3}}
      R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-1 ]
  
      F_2(\lambda_1,\lambda_2,\lambda_3)=
      \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
      {3(\lambda_2-\lambda_3)^2}
      [\frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}
      R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
      \frac{2\lambda_1-\lambda_2-\lambda_3}{3\sqrt{\lambda_2 \lambda_3}}
      R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-2]
  
  where $R_f$ and $R_d$ are the Carlson's elliptic integrals.
  
  References
  ----------
  .. [1] Jensen, J.H., Helpern, J.A., 2010. MRI quantification of
         non-Gaussian water diffusion by kurtosis analysis. NMR in
         Biomedicine 23(7): 698-710
  .. [2] Hardin, R.H., Sloane, N.J.A., 1996. McLaren's Improved Snub Cube
         and Other New Spherical Designs in Three Dimensions. Discrete
         and Computational Geometry 15, 429-441.
  .. [3] Tabesh, A., Jensen, J.H., Ardekani, B.A., Helpern, J.A., 2011.
         Estimation of tensors and tensor-derived measures in diffusional
         kurtosis imaging. Magn Reson Med. 65(3), 823-836
  .. [4] Barmpoutis, A., & Zhuo, J., 2011. Diffusion kurtosis imaging:
         Robust estimation from DW-MRI using homogeneous polynomials.
         Proceedings of the 8th {IEEE} International Symposium on
         Biomedical Imaging: From Nano to Macro, ISBI 2011, 262-265.
         doi: 10.1109/ISBI.2011.5872402
docstr_tok: ["Compute","mean","kurtosis","(","MK",")","from","the","kurtosis","tensor","Parameters","--","--","--","--","--","min_kurtosis",":","float","(","optional",")","To","keep","kurtosis","values","within","a","plausible","biophysical","range",",","mean","kurtosis","values","that","are","smaller","than","`","min_kurtosis","`","are","replaced","with","`","min_kurtosis","`",".","Default","=","-3.\/7","(","theoretical","kurtosis","limit","for","regions","that","consist","of","water","confined","to","spherical","pores","[","4","]","_",")","max_kurtosis",":","float","(","optional",")","To","keep","kurtosis","values","within","a","plausible","biophysical","range",",","mean","kurtosis","values","that","are","larger","than","`","max_kurtosis","`","are","replaced","with","`","max_kurtosis","`",".","Default","=","10","analytical",":","bool","(","optional",")","If","True",",","MK","is","calculated","using","its","analytical","solution",",","otherwise","an","exact","numerical","estimator","is","used","(","see","Notes",")",".","Default","is","set","to","True",".","Returns","--","--","--","-","mk",":","array","Calculated","MK",".","Notes","--","--","-","The","MK","is","defined","as","the","average","of","directional","kurtosis","coefficients","across","all","spatial","directions",",","which","can","be","formulated","by","the","following","surface","integral","[","1","]","_",":","..","math",":",":","MK","\\equiv","\\frac","{","1","}","{","4\\pi","}","\\int","d\\Omega_\\mathbf","{","n","}","K","(","\\mathbf","{","n","}",")","This","integral","can","be","numerically","solved","by","averaging","directional","kurtosis","values","sampled","for","directions","of","a","spherical","t-design","[","2","]","_.","Alternatively",",","MK","can","be","solved","from","the","analytical","solution","derived","by","Tabesh","et","al",".","[","3","]","_",".","This","solution","is","given","by",":","..","math",":",":","MK=F_1","(","\\lambda_1",",","\\lambda_2",",","\\lambda_3",")","\\hat","{","W","}","_","{","1111","}","+","F_1","(","\\lambda_2",",","\\lambda_1",",","\\lambda_3",")","\\hat","{","W","}","_","{","2222","}","+","F_1","(","\\lambda_3",",","\\lambda_2",",","\\lambda_1",")","\\hat","{","W","}","_","{","3333","}","+","\\\\","F_2","(","\\lambda_1",",","\\lambda_2",",","\\lambda_3",")","\\hat","{","W","}","_","{","2233","}","+","F_2","(","\\lambda_2",",","\\lambda_1",",","\\lambda_3",")","\\hat","{","W","}","_","{","1133","}","+","F_2","(","\\lambda_3",",","\\lambda_2",",","\\lambda_1",")","\\hat","{","W","}","_","{","1122","}","where","$","\\hat","{","W","}","_","{","ijkl","}","$","are","the","components","of","the","$","W","$","tensor","in","the","coordinates","system","defined","by","the","eigenvectors","of","the","diffusion","tensor","$","\\mathbf","{","D","}","$","and","..","math",":",":","F_1","(","\\lambda_1",",","\\lambda_2",",","\\lambda_3",")","=","\\frac","{","(","\\lambda_1+\\lambda_2+\\lambda_3",")","^2","}","{","18","(","\\lambda_1-\\lambda_2",")","(","\\lambda_1-\\lambda_3",")","}","[","\\frac","{","\\sqrt","{","\\lambda_2\\lambda_3","}","}","{","\\lambda_1","}","R_F","(","\\frac","{","\\lambda_1","}","{","\\lambda_2","}",",","\\frac","{","\\lambda_1","}","{","\\lambda_3","}",",1",")","+\\\\","\\frac","{","3\\lambda_1^2-\\lambda_1\\lambda_2-\\lambda_2\\lambda_3-","\\lambda_1\\lambda_3","}","{","3\\lambda_1","\\sqrt","{","\\lambda_2","\\lambda_3","}","}","R_D","(","\\frac","{","\\lambda_1","}","{","\\lambda_2","}",",","\\frac","{","\\lambda_1","}","{","\\lambda_3","}",",1",")","-1","]","F_2","(","\\lambda_1",",","\\lambda_2",",","\\lambda_3",")","=","\\frac","{","(","\\lambda_1+\\lambda_2+\\lambda_3",")","^2","}","{","3","(","\\lambda_2-\\lambda_3",")","^2","}","[","\\frac","{","\\lambda_2+\\lambda_3","}","{","\\sqrt","{","\\lambda_2\\lambda_3","}","}","R_F","(","\\frac","{","\\lambda_1","}","{","\\lambda_2","}",",","\\frac","{","\\lambda_1","}","{","\\lambda_3","}",",1",")","+\\\\","\\frac","{","2\\lambda_1-\\lambda_2-\\lambda_3","}","{","3\\sqrt","{","\\lambda_2","\\lambda_3","}","}","R_D","(","\\frac","{","\\lambda_1","}","{","\\lambda_2","}",",","\\frac","{","\\lambda_1","}","{","\\lambda_3","}",",1",")","-2","]","where","$","R_f","$","and","$","R_d","$","are","the","Carlson","'s","elliptic","integrals",".","References","--","--","--","--","--","..","[","1","]","Jensen",",","J.H.",",","Helpern",",","J.A.",",","2010",".","MRI","quantification","of","non-Gaussian","water","diffusion","by","kurtosis","analysis",".","NMR","in","Biomedicine","23","(","7",")",":","698-710","..","[","2","]","Hardin",",","R.H.",",","Sloane",",","N.J.A.",",","1996",".","McLaren","'s","Improved","Snub","Cube","and","Other","New","Spherical","Designs","in","Three","Dimensions",".","Discrete","and","Computational","Geometry","15",",","429-441",".","..","[","3","]","Tabesh",",","A.",",","Jensen",",","J.H.",",","Ardekani",",","B.A.",",","Helpern",",","J.A.",",","2011",".","Estimation","of","tensors","and","tensor-derived","measures","in","diffusional","kurtosis","imaging",".","Magn","Reson","Med",".","65","(","3",")",",","823-836","..","[","4","]","Barmpoutis",",","A.",",","&","Zhuo",",","J.",",","2011",".","Diffusion","kurtosis","imaging",":","Robust","estimation","from","DW-MRI","using","homogeneous","polynomials",".","Proceedings","of","the","8th","{","IEEE","}","International","Symposium","on","Biomedical","Imaging",":","From","Nano","to","Macro",",","ISBI","2011",",","262-265.","doi",":","10.1109\/ISBI.2011.5872402"]
code: def mk(self, min_kurtosis=-3.0 / 7, max_kurtosis=10, analytical=True):
      r""" Compute mean kurtosis (MK) from the kurtosis tensor
  
          Parameters
          ----------
          min_kurtosis : float (optional)
              To keep kurtosis values within a plausible biophysical range, mean
              kurtosis values that are smaller than `min_kurtosis` are replaced
              with `min_kurtosis`. Default = -3./7 (theoretical kurtosis limit
              for regions that consist of water confined to spherical pores [4]_)
          max_kurtosis : float (optional)
              To keep kurtosis values within a plausible biophysical range, mean
              kurtosis values that are larger than `max_kurtosis` are replaced
              with `max_kurtosis`. Default = 10
          analytical : bool (optional)
              If True, MK is calculated using its analytical solution, otherwise
              an exact numerical estimator is used (see Notes). Default is set to
              True.
  
          Returns
          -------
          mk : array
              Calculated MK.
  
          Notes
          -----
          The MK is defined as the average of directional kurtosis coefficients
          across all spatial directions, which can be formulated by the following
          surface integral[1]_:
  
          .. math::
  
               MK \equiv \frac{1}{4\pi} \int d\Omega_\mathbf{n} K(\mathbf{n})
  
          This integral can be numerically solved by averaging directional
          kurtosis values sampled for directions of a spherical t-design [2]_.
  
          Alternatively, MK can be solved from the analytical solution derived by
          Tabesh et al. [3]_. This solution is given by:
  
          .. math::
  
              MK=F_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{1111}+
                 F_1(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{2222}+
                 F_1(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{3333}+ \\
                 F_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}+
                 F_2(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{1133}+
                 F_2(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{1122}
  
          where $\hat{W}_{ijkl}$ are the components of the $W$ tensor in the
          coordinates system defined by the eigenvectors of the diffusion tensor
          $\mathbf{D}$ and
  
          .. math::
  
              F_1(\lambda_1,\lambda_2,\lambda_3)=
              \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
              {18(\lambda_1-\lambda_2)(\lambda_1-\lambda_3)}
              [\frac{\sqrt{\lambda_2\lambda_3}}{\lambda_1}
              R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
              \frac{3\lambda_1^2-\lambda_1\lambda_2-\lambda_2\lambda_3-
              \lambda_1\lambda_3}
              {3\lambda_1 \sqrt{\lambda_2 \lambda_3}}
              R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-1 ]
  
              F_2(\lambda_1,\lambda_2,\lambda_3)=
              \frac{(\lambda_1+\lambda_2+\lambda_3)^2}
              {3(\lambda_2-\lambda_3)^2}
              [\frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}
              R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
              \frac{2\lambda_1-\lambda_2-\lambda_3}{3\sqrt{\lambda_2 \lambda_3}}
              R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-2]
  
          where $R_f$ and $R_d$ are the Carlson's elliptic integrals.
  
          References
          ----------
          .. [1] Jensen, J.H., Helpern, J.A., 2010. MRI quantification of
                 non-Gaussian water diffusion by kurtosis analysis. NMR in
                 Biomedicine 23(7): 698-710
          .. [2] Hardin, R.H., Sloane, N.J.A., 1996. McLaren's Improved Snub Cube
                 and Other New Spherical Designs in Three Dimensions. Discrete
                 and Computational Geometry 15, 429-441.
          .. [3] Tabesh, A., Jensen, J.H., Ardekani, B.A., Helpern, J.A., 2011.
                 Estimation of tensors and tensor-derived measures in diffusional
                 kurtosis imaging. Magn Reson Med. 65(3), 823-836
          .. [4] Barmpoutis, A., & Zhuo, J., 2011. Diffusion kurtosis imaging:
                 Robust estimation from DW-MRI using homogeneous polynomials.
                 Proceedings of the 8th {IEEE} International Symposium on
                 Biomedical Imaging: From Nano to Macro, ISBI 2011, 262-265.
                 doi: 10.1109/ISBI.2011.5872402
  
          """
      return mean_kurtosis(
          self.model_params, min_kurtosis, max_kurtosis, analytical
      )
  
imports: import numpy
  import warnings
  import scipy.optimize
  import dipy.core.sphere
  from dipy.reconst.multi_voxel import multi_voxel_fit
  from dipy.reconst.dti import TensorFit, mean_diffusivity, from_lower_triangular, lower_triangular, decompose_tensor, MIN_POSITIVE_SIGNAL, nlls_fit_tensor, restore_fit_tensor
  from dipy.reconst.utils import dki_design_matrix
  from dipy.reconst.recspeed import local_maxima
  from dipy.reconst.base import ReconstModel
  from dipy.core.ndindex import ndindex
  from dipy.core.geometry import sphere2cart, cart2sphere, perpendicular_directions
  from dipy.core.optimize import PositiveDefiniteLeastSquares
  from dipy.data import get_sphere, get_fnames, load_sdp_constraints
  from dipy.reconst.vec_val_sum import vec_val_vect
  from dipy.core.gradients import check_multi_b
label_desc: Use image node_id 4 for calling the DiffusionKurtosisFit obj's underlying member method code with example usage: obj.mk(min_kurtosis, max_kurtosis, analytical) and returns: mean_kurtosis