code: def minimize(
      fcn,
      params,
      method="leastsq",
      args=None,
      kws=None,
      iter_cb=None,
      scale_covar=True,
      nan_policy="raise",
      reduce_fcn=None,
      calc_covar=True,
      max_nfev=None,
      **fit_kws,
  ):
      """Perform the minimization of the objective function.
  
      The minimize function takes an objective function to be minimized,
      a dictionary (:class:`~lmfit.parameter.Parameters` ; Parameters) containing
      the model parameters, and several optional arguments including the fitting
      method.
  
      Parameters
      ----------
      fcn : callable
          Objective function to be minimized. When method is `'leastsq'` or
          '`least_squares`', the objective function should return an array
          of residuals (difference between model and data) to be minimized
          in a least-squares sense. With the scalar methods the objective
          function can either return the residuals array or a single scalar
          value. The function must have the signature::
  
              fcn(params, *args, **kws)
  
      params : Parameters
          Contains the Parameters for the model.
      method : str, optional
          Name of the fitting method to use. Valid values are:
  
          - `'leastsq'`: Levenberg-Marquardt (default)
          - `'least_squares'`: Least-Squares minimization, using Trust Region Reflective method
          - `'differential_evolution'`: differential evolution
          - `'brute'`: brute force method
          - `'basinhopping'`: basinhopping
          - `'ampgo'`: Adaptive Memory Programming for Global Optimization
          - '`nelder`': Nelder-Mead
          - `'lbfgsb'`: L-BFGS-B
          - `'powell'`: Powell
          - `'cg'`: Conjugate-Gradient
          - `'newton'`: Newton-CG
          - `'cobyla'`: Cobyla
          - `'bfgs'`: BFGS
          - `'tnc'`: Truncated Newton
          - `'trust-ncg'`: Newton-CG trust-region
          - `'trust-exact'`: nearly exact trust-region
          - `'trust-krylov'`: Newton GLTR trust-region
          - `'trust-constr'`: trust-region for constrained optimization
          - `'dogleg'`: Dog-leg trust-region
          - `'slsqp'`: Sequential Linear Squares Programming
          - `'emcee'`: Maximum likelihood via Monte-Carlo Markov Chain
          - `'shgo'`: Simplicial Homology Global Optimization
          - `'dual_annealing'`: Dual Annealing optimization
  
          In most cases, these methods wrap and use the method of the same
          name from `scipy.optimize`, or use `scipy.optimize.minimize` with
          the same `method` argument. Thus `'leastsq'` will use
          `scipy.optimize.leastsq`, while `'powell'` will use
          `scipy.optimize.minimizer(..., method='powell')`
  
          For more details on the fitting methods please refer to the
          `SciPy docs <https://docs.scipy.org/doc/scipy/reference/optimize.html>`__.
  
      args : tuple, optional
          Positional arguments to pass to `fcn`.
      kws : dict, optional
          Keyword arguments to pass to `fcn`.
      iter_cb : callable, optional
          Function to be called at each fit iteration. This function should
          have the signature::
  
              iter_cb(params, iter, resid, *args, **kws),
  
          where `params` will have the current parameter values, `iter` the
          iteration number, `resid` the current residual array, and `*args`
          and `**kws` as passed to the objective function.
      scale_covar : bool, optional
          Whether to automatically scale the covariance matrix (default is
          True).
      nan_policy : {'raise', 'propagate', 'omit'}, optional
          Specifies action if `fcn` (or a Jacobian) returns NaN values. One
          of:
  
          - `'raise'` : a `ValueError` is raised
          - `'propagate'` : the values returned from `userfcn` are un-altered
          - `'omit'` : non-finite values are filtered
  
      reduce_fcn : str or callable, optional
          Function to convert a residual array to a scalar value for the
          scalar minimizers. See Notes in `Minimizer`.
      calc_covar : bool, optional
          Whether to calculate the covariance matrix (default is True) for
          solvers other than `'leastsq'` and `'least_squares'`. Requires the
          `numdifftools` package to be installed.
      max_nfev : int or None, optional
          Maximum number of function evaluations (default is None). The
          default value depends on the fitting method.
      **fit_kws : dict, optional
          Options to pass to the minimizer being used.
  
      Returns
      -------
      MinimizerResult
          Object containing the optimized parameters and several
          goodness-of-fit statistics.
  
  
      .. versionchanged:: 0.9.0
         Return value changed to :class:`MinimizerResult`.
  
  
      Notes
      -----
      The objective function should return the value to be minimized. For
      the Levenberg-Marquardt algorithm from leastsq(), this returned value
      must be an array, with a length greater than or equal to the number of
      fitting variables in the model. For the other methods, the return
      value can either be a scalar or an array. If an array is returned, the
      sum-of- squares of the array will be sent to the underlying fitting
      method, effectively doing a least-squares optimization of the return
      values.
  
      A common use for `args` and `kws` would be to pass in other data needed
      to calculate the residual, including such things as the data array,
      dependent variable, uncertainties in the data, and other data structures
      for the model calculation.
  
      On output, `params` will be unchanged. The best-fit values and, where
      appropriate, estimated uncertainties and correlations, will all be
      contained in the returned :class:`MinimizerResult`. See
      :ref:`fit-results-label` for further details.
  
      This function is simply a wrapper around :class:`Minimizer` and is
      equivalent to::
  
          fitter = Minimizer(fcn, params, fcn_args=args, fcn_kws=kws,
                             iter_cb=iter_cb, scale_covar=scale_covar,
                             nan_policy=nan_policy, reduce_fcn=reduce_fcn,
                             calc_covar=calc_covar, **fit_kws)
          fitter.minimize(method=method)
  
      """
      fitter = Minimizer(
          fcn,
          params,
          fcn_args=args,
          fcn_kws=kws,
          iter_cb=iter_cb,
          scale_covar=scale_covar,
          nan_policy=nan_policy,
          reduce_fcn=reduce_fcn,
          calc_covar=calc_covar,
          max_nfev=max_nfev,
          **fit_kws,
      )
      return fitter.minimize(method=method)
  
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 8 for calling a global function with example usage: minimize(fcn, params, method, args, kws, iter_cb, scale_covar, nan_policy, reduce_fcn, calc_covar, max_nfev) and returns: fitter