class_docstr: A class for representing and solving predictive models based on
  tractography solutions.
  
  Notes
  -----
  This is an implementation of the LiFE model described in [1]_
  
  [1] Pestilli, F., Yeatman, J, Rokem, A. Kay, K. and Wandell
      B.A. (2014). Validation and statistical inference in living
      connectomes. Nature Methods.
docstr: Fit the LiFE FiberModel for data and a set of streamlines associated
  with this data
  
  Parameters
  ----------
  data : 4D array
      Diffusion-weighted data
  streamline : list
      A bunch of streamlines
  affine : array_like (4, 4)
      The mapping from voxel coordinates to streamline points.
      The voxel_to_rasmm matrix, typically from a NIFTI file.
  evals : array-like (optional)
      The eigenvalues of the tensor response function used in
      constructing the model signal. Default: [0.001, 0, 0]
  sphere: `dipy.core.Sphere` instance or False, optional
      Whether to approximate (and cache) the signal on a discrete
      sphere. This may confer a significant speed-up in setting up the
      problem, but is not as accurate. If `False`, we use the exact
      gradients along the streamlines to calculate the matrix, instead of
      an approximation.
  
  Returns
  -------
  FiberFit class instance
docstr_tok: ["Fit","the","LiFE","FiberModel","for","data","and","a","set","of","streamlines","associated","with","this","data","Parameters","--","--","--","--","--","data",":","4D","array","Diffusion-weighted","data","streamline",":","list","A","bunch","of","streamlines","affine",":","array_like","(","4",",","4",")","The","mapping","from","voxel","coordinates","to","streamline","points",".","The","voxel_to_rasmm","matrix",",","typically","from","a","NIFTI","file",".","evals",":","array-like","(","optional",")","The","eigenvalues","of","the","tensor","response","function","used","in","constructing","the","model","signal",".","Default",":","[","0.001",",","0",",","0","]","sphere",":","`","dipy.core.Sphere","`","instance","or","False",",","optional","Whether","to","approximate","(","and","cache",")","the","signal","on","a","discrete","sphere",".","This","may","confer","a","significant","speed-up","in","setting","up","the","problem",",","but","is","not","as","accurate",".","If","`","False","`",",","we","use","the","exact","gradients","along","the","streamlines","to","calculate","the","matrix",",","instead","of","an","approximation",".","Returns","--","--","--","-","FiberFit","class","instance"]
code: def fit(
      self, data, streamline, affine, evals=(0.001, 0, 0), sphere=None
  ):
      """
      Fit the LiFE FiberModel for data and a set of streamlines associated
      with this data
  
      Parameters
      ----------
      data : 4D array
          Diffusion-weighted data
      streamline : list
          A bunch of streamlines
      affine : array_like (4, 4)
          The mapping from voxel coordinates to streamline points.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
      evals : array-like (optional)
          The eigenvalues of the tensor response function used in
          constructing the model signal. Default: [0.001, 0, 0]
      sphere: `dipy.core.Sphere` instance or False, optional
          Whether to approximate (and cache) the signal on a discrete
          sphere. This may confer a significant speed-up in setting up the
          problem, but is not as accurate. If `False`, we use the exact
          gradients along the streamlines to calculate the matrix, instead of
          an approximation.
  
      Returns
      -------
      FiberFit class instance
      """
      if affine is None:
          affine = np.eye(4)
      sl_len = np.array([len(s) for s in streamline])
      if np.any(sl_len < 2):
          raise ValueError(
              "Input contains streamlines with only one node."
              " The LiFE model cannot be fit with these streamlines included."
          )
      life_matrix, vox_coords = self.setup(
          streamline, affine, evals=evals, sphere=sphere
      )
      (
          to_fit,
          weighted_signal,
          b0_signal,
          relative_signal,
          mean_sig,
          vox_data,
      ) = self._signals(data, vox_coords)
      beta = opt.sparse_nnls(to_fit, life_matrix)
      return FiberFit(
          self,
          life_matrix,
          vox_coords,
          to_fit,
          beta,
          weighted_signal,
          b0_signal,
          relative_signal,
          mean_sig,
          vox_data,
          streamline,
          affine,
          evals,
      )
  
imports: import numpy
  import scipy.sparse
  import scipy.linalg
  from dipy.reconst.base import ReconstModel, ReconstFit
  from dipy.tracking.utils import unique_rows
  from dipy.tracking.streamline import transform_streamlines
  from dipy.tracking.vox2track import _voxel2streamline
  import dipy.data
  import dipy.core.optimize
label_desc: Use image node_id 4 for calling the FiberModel obj's underlying member method code with example usage: obj.fit(data, streamline, affine, evals, sphere) and returns: FiberFit