class_docstr: A general minimizer for curve fitting and optimization.
class_docstr_tok: ["A","general","minimizer","for","curve","fitting","and","optimization","."]
docstr: Scalar minimization using :scipydoc:`optimize.minimize`.
  
  Perform fit with any of the scalar minimization algorithms
  supported by :scipydoc:`optimize.minimize`. Default argument
  values are:
  
  +-------------------------+---------------+-----------------------+
  | :meth:`scalar_minimize` | Default Value | Description           |
  | arg                     |               |                       |
  +=========================+===============+=======================+
  |  `method`               | 'Nelder-Mead' | fitting method        |
  +-------------------------+---------------+-----------------------+
  |  `tol`                  | 1.e-7         | fitting and parameter |
  |                         |               | tolerance             |
  +-------------------------+---------------+-----------------------+
  |  `hess`                 | None          | Hessian of objective  |
  |                         |               | function              |
  +-------------------------+---------------+-----------------------+
  
  
  Parameters
  ----------
  method : str, optional
      Name of the fitting method to use. One of:
  
      - `'Nelder-Mead'` (default)
      - `'L-BFGS-B'`
      - `'Powell'`
      - `'CG'`
      - `'Newton-CG'`
      - `'COBYLA'`
      - `'BFGS'`
      - `'TNC'`
      - `'trust-ncg'`
      - `'trust-exact'`
      - `'trust-krylov'`
      - `'trust-constr'`
      - `'dogleg'`
      - `'SLSQP'`
      - `'differential_evolution'`
  
  params : Parameters, optional
      Parameters to use as starting point.
  max_nfev : int or None, optional
      Maximum number of function evaluations. Defaults to
      ``2000*(nvars+1)``, where ``nvars`` is the number of variable
      parameters.
  **kws : dict, optional
      Minimizer options pass to :scipydoc:`optimize.minimize`.
  
  Returns
  -------
  MinimizerResult
      Object containing the optimized parameters and several
      goodness-of-fit statistics.
  
  
  .. versionchanged:: 0.9.0
     Return value changed to :class:`MinimizerResult`.
  
  
  Notes
  -----
  If the objective function returns a NumPy array instead of the
  expected scalar, the sum-of-squares of the array will be used.
  
  Note that bounds and constraints can be set on Parameters for any
  of these methods, so are not supported separately for those
  designed to use bounds. However, if you use the
  ``differential_evolution`` method you must specify finite
  ``(min, max)`` for each varying Parameter.
docstr_tok: ["Scalar","minimization","using",":","scipydoc",":","`","optimize.minimize","`",".","Perform","fit","with","any","of","the","scalar","minimization","algorithms","supported","by",":","scipydoc",":","`","optimize.minimize","`",".","Default","argument","values","are",":","+","--","--","--","--","--","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","-+","|",":","meth",":","`","scalar_minimize","`","|","Default","Value","|","Description","|","|","arg","|","|","|","+=========================+===============+=======================+","|","`","method","`","|","'Nelder-Mead","'","|","fitting","method","|","+","--","--","--","--","--","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","-+","|","`","tol","`","|","1.e-7","|","fitting","and","parameter","|","|","|","|","tolerance","|","+","--","--","--","--","--","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","-+","|","`","hess","`","|","None","|","Hessian","of","objective","|","|","|","|","function","|","+","--","--","--","--","--","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","-+","Parameters","--","--","--","--","--","method",":","str",",","optional","Name","of","the","fitting","method","to","use",".","One","of",":","-","`","'Nelder-Mead","'","`","(","default",")","-","`","'","L-BFGS-B","'","`","-","`","'Powell","'","`","-","`","'CG","'","`","-","`","'Newton-CG","'","`","-","`","'COBYLA","'","`","-","`","'BFGS","'","`","-","`","'TNC","'","`","-","`","'trust-ncg","'","`","-","`","'trust-exact","'","`","-","`","'trust-krylov","'","`","-","`","'trust-constr","'","`","-","`","'dogleg","'","`","-","`","'SLSQP","'","`","-","`","'differential_evolution","'","`","params",":","Parameters",",","optional","Parameters","to","use","as","starting","point",".","max_nfev",":","int","or","None",",","optional","Maximum","number","of","function","evaluations",".","Defaults","to","``","2000","*","(","nvars+1",")","``",",","where","``","nvars","``","is","the","number","of","variable","parameters",".","*","*","kws",":","dict",",","optional","Minimizer","options","pass","to",":","scipydoc",":","`","optimize.minimize","`",".","Returns","--","--","--","-","MinimizerResult","Object","containing","the","optimized","parameters","and","several","goodness-of-fit","statistics",".","..","versionchanged",":",":","0.9.0","Return","value","changed","to",":","class",":","`","MinimizerResult","`",".","Notes","--","--","-","If","the","objective","function","returns","a","NumPy","array","instead","of","the","expected","scalar",",","the","sum-of-squares","of","the","array","will","be","used",".","Note","that","bounds","and","constraints","can","be","set","on","Parameters","for","any","of","these","methods",",","so","are","not","supported","separately","for","those","designed","to","use","bounds",".","However",",","if","you","use","the","``","differential_evolution","``","method","you","must","specify","finite","``","(","min",",","max",")","``","for","each","varying","Parameter","."]
code: def scalar_minimize(
      self, method="Nelder-Mead", params=None, max_nfev=None, **kws
  ):
      """Scalar minimization using :scipydoc:`optimize.minimize`.
  
      Perform fit with any of the scalar minimization algorithms
      supported by :scipydoc:`optimize.minimize`. Default argument
      values are:
  
      +-------------------------+---------------+-----------------------+
      | :meth:`scalar_minimize` | Default Value | Description           |
      | arg                     |               |                       |
      +=========================+===============+=======================+
      |  `method`               | 'Nelder-Mead' | fitting method        |
      +-------------------------+---------------+-----------------------+
      |  `tol`                  | 1.e-7         | fitting and parameter |
      |                         |               | tolerance             |
      +-------------------------+---------------+-----------------------+
      |  `hess`                 | None          | Hessian of objective  |
      |                         |               | function              |
      +-------------------------+---------------+-----------------------+
  
  
      Parameters
      ----------
      method : str, optional
          Name of the fitting method to use. One of:
  
          - `'Nelder-Mead'` (default)
          - `'L-BFGS-B'`
          - `'Powell'`
          - `'CG'`
          - `'Newton-CG'`
          - `'COBYLA'`
          - `'BFGS'`
          - `'TNC'`
          - `'trust-ncg'`
          - `'trust-exact'`
          - `'trust-krylov'`
          - `'trust-constr'`
          - `'dogleg'`
          - `'SLSQP'`
          - `'differential_evolution'`
  
      params : Parameters, optional
          Parameters to use as starting point.
      max_nfev : int or None, optional
          Maximum number of function evaluations. Defaults to
          ``2000*(nvars+1)``, where ``nvars`` is the number of variable
          parameters.
      **kws : dict, optional
          Minimizer options pass to :scipydoc:`optimize.minimize`.
  
      Returns
      -------
      MinimizerResult
          Object containing the optimized parameters and several
          goodness-of-fit statistics.
  
  
      .. versionchanged:: 0.9.0
         Return value changed to :class:`MinimizerResult`.
  
  
      Notes
      -----
      If the objective function returns a NumPy array instead of the
      expected scalar, the sum-of-squares of the array will be used.
  
      Note that bounds and constraints can be set on Parameters for any
      of these methods, so are not supported separately for those
      designed to use bounds. However, if you use the
      ``differential_evolution`` method you must specify finite
      ``(min, max)`` for each varying Parameter.
  
      """
      result = self.prepare_fit(params=params)
      result.method = method
      variables = result._init_vals_internal
      params = result.params
  
      self.set_max_nfev(max_nfev, 2000 * (result.nvarys + 1))
  
      fmin_kws = dict(
          method=method, options={"maxiter": 2 * self.max_nfev}
      )
      if method == "L-BFGS-B":
          fmin_kws["options"]["maxfun"] = 2 * self.max_nfev
      elif method == "COBYLA":
          # for this method, we explicitly let the solver reach
          # the users max nfev, and do not abort in _residual
          fmin_kws["options"]["maxiter"] = self.max_nfev
          self.max_nfev = 5 * self.max_nfev
      fmin_kws.update(self.kws)
  
      if "maxiter" in kws:
          warnings.warn(
              maxeval_warning.format("maxiter", thisfuncname()),
              RuntimeWarning,
          )
          kws.pop("maxiter")
      fmin_kws.update(kws)
  
      # hess supported only in some methods
      if "hess" in fmin_kws and method not in (
          "Newton-CG",
          "dogleg",
          "trust-constr",
          "trust-ncg",
          "trust-krylov",
          "trust-exact",
      ):
          fmin_kws.pop("hess")
  
      # Accept Jacobians given as Dfun argument
      if (
          "jac" not in fmin_kws
          and fmin_kws.get("Dfun", None) is not None
      ):
          fmin_kws["jac"] = fmin_kws.pop("Dfun")
  
      # Wrap Jacobian function to deal with bounds
      if "jac" in fmin_kws:
          self.jacfcn = fmin_kws.pop("jac")
          fmin_kws["jac"] = self.__jacobian
  
      # Ignore jac argument for methods that do not support it
      if "jac" in fmin_kws and method not in (
          "CG",
          "BFGS",
          "Newton-CG",
          "L-BFGS-B",
          "TNC",
          "SLSQP",
          "dogleg",
          "trust-ncg",
          "trust-krylov",
          "trust-exact",
      ):
          self.jacfcn = None
          fmin_kws.pop("jac")
  
      # workers / updating keywords only supported in differential_evolution
      for kwd in ("workers", "updating"):
          if kwd in fmin_kws and method != "differential_evolution":
              fmin_kws.pop(kwd)
  
      if method == "differential_evolution":
          for par in params.values():
              if par.vary and not (
                  np.isfinite(par.min) and np.isfinite(par.max)
              ):
                  raise ValueError(
                      "differential_evolution requires finite "
                      "bound for all varying parameters"
                  )
  
          _bounds = [(-np.pi / 2.0, np.pi / 2.0)] * len(variables)
          kwargs = dict(
              args=(),
              strategy="best1bin",
              maxiter=self.max_nfev,
              popsize=15,
              tol=0.01,
              mutation=(0.5, 1),
              recombination=0.7,
              seed=None,
              callback=None,
              disp=False,
              polish=True,
              init="latinhypercube",
              atol=0,
              updating="immediate",
              workers=1,
          )
  
          for k, v in fmin_kws.items():
              if k in kwargs:
                  kwargs[k] = v
  
          fmin_kws = kwargs
          result.call_kws = fmin_kws
          try:
              ret = differential_evolution(
                  self.penalty, _bounds, **fmin_kws
              )
          except AbortFitException:
              pass
  
      else:
          result.call_kws = fmin_kws
          try:
              ret = scipy_minimize(self.penalty, variables, **fmin_kws)
          except AbortFitException:
              pass
  
      if not result.aborted:
          if isinstance(ret, dict):
              for attr, value in ret.items():
                  setattr(result, attr, value)
          else:
              for attr in dir(ret):
                  if not attr.startswith("_"):
                      setattr(result, attr, getattr(ret, attr))
  
          result.x = np.atleast_1d(result.x)
          result.residual = self.__residual(result.x)
          result.nfev -= 1
      else:
          result.x = result.last_internal_values
          self.result.nfev -= 2
          self._abort = False
          result.residual = self.__residual(result.x)
          result.nfev += 1
  
      result._calculate_statistics()
  
      # calculate the cov_x and estimate uncertainties/correlations
      self.result.uvars = None
      if (
          not result.aborted
          and self.calc_covar
          and HAS_NUMDIFFTOOLS
          and len(result.residual) > len(result.var_names)
      ):
          _covar_ndt = self._calculate_covariance_matrix(result.x)
          if _covar_ndt is not None:
              result.covar = self._int2ext_cov_x(_covar_ndt, result.x)
              self._calculate_uncertainties_correlations()
  
      return result
  
imports: from collections import namedtuple
  from copy import deepcopy
  import inspect
  import multiprocessing
  import numbers
  import warnings
  import numpy
  from scipy.linalg import LinAlgError, inv
  from scipy.optimize import basinhopping
  from scipy.optimize import brute
  from scipy.optimize import differential_evolution
  from scipy.optimize import dual_annealing
  from scipy.optimize import least_squares
  from scipy.optimize import leastsq
  from scipy.optimize import minimize
  from scipy.optimize import shgo
  from scipy.sparse import issparse
  from scipy.sparse.linalg import LinearOperator
  from scipy.stats import cauchy
  from scipy.stats import norm
  from ._ampgo import ampgo
  from .parameter import Parameter, Parameters
  from .printfuncs import fitreport_html_table
label_desc: Use image node_id 12 for calling the Minimizer obj's underlying member method code with example usage: obj.scalar_minimize(method, params, max_nfev) and returns: result