docstr: Initialize a Sparse Fascicle Model
  
  Parameters
  ----------
  gtab : GradientTable class instance
  
  sphere : Sphere class instance, optional
      A sphere on which coefficients will be estimated. Default:
      symmetric sphere with 362 points (from :mod:`dipy.data`).
  
  response : (3,) array-like, optional
      The eigenvalues of a canonical tensor to be used as the response
      function of single-fascicle signals.
      Default:[0.0015, 0.0005, 0.0005]
  
  solver : string, or initialized linear model object.
      This will determine the algorithm used to solve the set of linear
      equations underlying this model. If it is a string it needs to be
      one of the following: {'ElasticNet', 'NNLS'}. Otherwise, it can be
      an object that inherits from `dipy.optimize.SKLearnLinearSolver`
      or an object with a similar interface from Scikit Learn:
      `sklearn.linear_model.ElasticNet`, `sklearn.linear_model.Lasso` or
      `sklearn.linear_model.Ridge` and other objects that inherit from
      `sklearn.base.RegressorMixin`.
      Default: 'ElasticNet'.
  
  l1_ratio : float, optional
      Sets the balance between L1 and L2 regularization in ElasticNet
      [Zou2005]_. Default: 0.5
  
  alpha : float, optional
      Sets the balance between least-squares error and L1/L2
      regularization in ElasticNet [Zou2005]_. Default: 0.001
  
  isotropic : IsotropicModel class instance
      This is a class that implements the function that calculates the
      value of the isotropic signal. This is a value of the signal that
      is independent of direction, and therefore removed from both sides
      of the SFM equation. The default is an instance of IsotropicModel,
      but other functions can be inherited from IsotropicModel to
      implement other fits to the aspects of the data that depend on
      b-value, but not on direction.
  
  Notes
  -----
  This is an implementation of the SFM, described in [Rokem2015]_.
  
  .. [Rokem2014] Ariel Rokem, Jason D. Yeatman, Franco Pestilli, Kendrick
     N. Kay, Aviv Mezer, Stefan van der Walt, Brian A. Wandell
     (2014). Evaluating the accuracy of diffusion MRI models in white
     matter. PLoS ONE 10(4): e0123272. doi:10.1371/journal.pone.0123272
  
  .. [Zou2005] Zou H, Hastie T (2005). Regularization and variable
     selection via the elastic net. J R Stat Soc B:301-320
docstr_tok: ["Initialize","a","Sparse","Fascicle","Model","Parameters","--","--","--","--","--","gtab",":","GradientTable","class","instance","sphere",":","Sphere","class","instance",",","optional","A","sphere","on","which","coefficients","will","be","estimated",".","Default",":","symmetric","sphere","with","362","points","(","from",":","mod",":","`","dipy.data","`",")",".","response",":","(","3",",",")","array-like",",","optional","The","eigenvalues","of","a","canonical","tensor","to","be","used","as","the","response","function","of","single-fascicle","signals",".","Default",":","[","0.0015",",","0.0005",",","0.0005","]","solver",":","string",",","or","initialized","linear","model","object",".","This","will","determine","the","algorithm","used","to","solve","the","set","of","linear","equations","underlying","this","model",".","If","it","is","a","string","it","needs","to","be","one","of","the","following",":","{","'ElasticNet","'",",","'NNLS","'","}",".","Otherwise",",","it","can","be","an","object","that","inherits","from","`","dipy.optimize.SKLearnLinearSolver","`","or","an","object","with","a","similar","interface","from","Scikit","Learn",":","`","sklearn.linear_model.ElasticNet","`",",","`","sklearn.linear_model.Lasso","`","or","`","sklearn.linear_model.Ridge","`","and","other","objects","that","inherit","from","`","sklearn.base.RegressorMixin","`",".","Default",":","'ElasticNet","'",".","l1_ratio",":","float",",","optional","Sets","the","balance","between","L1","and","L2","regularization","in","ElasticNet","[","Zou2005","]","_",".","Default",":","0.5","alpha",":","float",",","optional","Sets","the","balance","between","least-squares","error","and","L1\/L2","regularization","in","ElasticNet","[","Zou2005","]","_",".","Default",":","0.001","isotropic",":","IsotropicModel","class","instance","This","is","a","class","that","implements","the","function","that","calculates","the","value","of","the","isotropic","signal",".","This","is","a","value","of","the","signal","that","is","independent","of","direction",",","and","therefore","removed","from","both","sides","of","the","SFM","equation",".","The","default","is","an","instance","of","IsotropicModel",",","but","other","functions","can","be","inherited","from","IsotropicModel","to","implement","other","fits","to","the","aspects","of","the","data","that","depend","on","b-value",",","but","not","on","direction",".","Notes","--","--","-","This","is","an","implementation","of","the","SFM",",","described","in","[","Rokem2015","]","_",".","..","[","Rokem2014","]","Ariel","Rokem",",","Jason","D.","Yeatman",",","Franco","Pestilli",",","Kendrick","N.","Kay",",","Aviv","Mezer",",","Stefan","van","der","Walt",",","Brian","A.","Wandell","(","2014",")",".","Evaluating","the","accuracy","of","diffusion","MRI","models","in","white","matter",".","PLoS","ONE","10","(","4",")",":","e0123272",".","doi:10.1371\/journal.pone.0123272","..","[","Zou2005","]","Zou","H",",","Hastie","T","(","2005",")",".","Regularization","and","variable","selection","via","the","elastic","net",".","J","R","Stat","Soc","B:301-320"]
code: def __init__(
      self,
      gtab,
      sphere=None,
      response=(0.0015, 0.0005, 0.0005),
      solver="ElasticNet",
      l1_ratio=0.5,
      alpha=0.001,
      isotropic=None,
      seed=42,
  ):
      """
      Initialize a Sparse Fascicle Model
  
      Parameters
      ----------
      gtab : GradientTable class instance
  
      sphere : Sphere class instance, optional
          A sphere on which coefficients will be estimated. Default:
          symmetric sphere with 362 points (from :mod:`dipy.data`).
  
      response : (3,) array-like, optional
          The eigenvalues of a canonical tensor to be used as the response
          function of single-fascicle signals.
          Default:[0.0015, 0.0005, 0.0005]
  
      solver : string, or initialized linear model object.
          This will determine the algorithm used to solve the set of linear
          equations underlying this model. If it is a string it needs to be
          one of the following: {'ElasticNet', 'NNLS'}. Otherwise, it can be
          an object that inherits from `dipy.optimize.SKLearnLinearSolver`
          or an object with a similar interface from Scikit Learn:
          `sklearn.linear_model.ElasticNet`, `sklearn.linear_model.Lasso` or
          `sklearn.linear_model.Ridge` and other objects that inherit from
          `sklearn.base.RegressorMixin`.
          Default: 'ElasticNet'.
  
      l1_ratio : float, optional
          Sets the balance between L1 and L2 regularization in ElasticNet
          [Zou2005]_. Default: 0.5
  
      alpha : float, optional
          Sets the balance between least-squares error and L1/L2
          regularization in ElasticNet [Zou2005]_. Default: 0.001
  
      isotropic : IsotropicModel class instance
          This is a class that implements the function that calculates the
          value of the isotropic signal. This is a value of the signal that
          is independent of direction, and therefore removed from both sides
          of the SFM equation. The default is an instance of IsotropicModel,
          but other functions can be inherited from IsotropicModel to
          implement other fits to the aspects of the data that depend on
          b-value, but not on direction.
  
      Notes
      -----
      This is an implementation of the SFM, described in [Rokem2015]_.
  
      .. [Rokem2014] Ariel Rokem, Jason D. Yeatman, Franco Pestilli, Kendrick
         N. Kay, Aviv Mezer, Stefan van der Walt, Brian A. Wandell
         (2014). Evaluating the accuracy of diffusion MRI models in white
         matter. PLoS ONE 10(4): e0123272. doi:10.1371/journal.pone.0123272
  
      .. [Zou2005] Zou H, Hastie T (2005). Regularization and variable
         selection via the elastic net. J R Stat Soc B:301-320
      """
      ReconstModel.__init__(self, gtab)
  
      if sphere is None:
          sphere = dpd.get_sphere()
      self.sphere = sphere
      self.response = np.asarray(response)
      if isotropic is None:
          isotropic = IsotropicModel
  
      self.isotropic = isotropic
      if solver == "ElasticNet":
          self.solver = lm.ElasticNet(
              l1_ratio=l1_ratio,
              alpha=alpha,
              positive=True,
              warm_start=False,
              random_state=seed,
          )
      elif solver in ("NNLS", "nnls"):
          self.solver = opt.NonNegativeLeastSquares()
  
      elif (
          isinstance(solver, opt.SKLearnLinearSolver)
          or has_sklearn
          and isinstance(solver, sklearn.base.RegressorMixin)
      ):
          self.solver = solver
  
      else:
          # If sklearn is unavailable, we can fall back on nnls (but we also
          # warn the user that we are about to do that):
          if not has_sklearn:
              w = (
                  sklearn._msg
                  + "\nAlternatively, you can use 'nnls' method "
              )
              w += "to fit the SparseFascicleModel"
              warnings.warn(w)
          e_s = "The `solver` key-word argument needs to be: "
          e_s += "'ElasticNet', 'NNLS', or a "
          e_s += "`dipy.optimize.SKLearnLinearSolver` object"
          raise ValueError(e_s)
  
imports: import warnings
  import numpy
  import gc
  from collections import OrderedDict
  from dipy.utils.optpkg import optional_package
  from dipy.utils.multiproc import determine_num_processes
  import dipy.core.gradients
  import dipy.core.optimize
  import dipy.sims.voxel
  import dipy.data
  from dipy.reconst.base import ReconstModel, ReconstFit
  from dipy.reconst.cache import Cache
  from dipy.core.onetime import auto_attr
label_desc: Use image node_id 1 to create a new SparseFascicleModel object from inherited base classes: ReconstModel, Cache with example: obj = SparseFascicleModel(gtab, sphere, response, solver, l1_ratio, alpha, isotropic, seed)