class_docstr: A general minimizer for curve fitting and optimization.
class_docstr_tok: ["A","general","minimizer","for","curve","fitting","and","optimization","."]
docstr: Use the `brute` method to find the global minimum of a function.
  
  The following parameters are passed to :scipydoc:`optimize.brute`
  and cannot be changed:
  
  +-------------------+-------+------------------------------------+
  | :meth:`brute` arg | Value | Description                        |
  +===================+=======+====================================+
  |  `full_output`    | 1     | Return the evaluation grid and the |
  |                   |       | objective function's values on it. |
  +-------------------+-------+------------------------------------+
  |  `finish`         | None  | No "polishing" function is to be   |
  |                   |       | used after the grid search.        |
  +-------------------+-------+------------------------------------+
  |  `disp`           | False | Do not print convergence messages  |
  |                   |       | (when finish is not None).         |
  +-------------------+-------+------------------------------------+
  
  It assumes that the input Parameters have been initialized, and a
  function to minimize has been properly set up.
  
  Parameters
  ----------
  params : Parameters, optional
      Contains the Parameters for the model. If None, then the
      Parameters used to initialize the Minimizer object are used.
  Ns : int, optional
      Number of grid points along the axes, if not otherwise
      specified (see Notes).
  keep : int, optional
      Number of best candidates from the brute force method that are
      stored in the :attr:`candidates` attribute. If `'all'`, then
      all grid points from :scipydoc:`optimize.brute` are stored as
      candidates.
  workers : int or map-like callable, optional
      For parallel evaluation of the grid (see :scipydoc:`optimize.brute`
      for more details).
  max_nfev : int or None, optional
      Maximum number of function evaluations (default is None). Defaults
      to ``200000*(nvarys+1)``.
  
  Returns
  -------
  MinimizerResult
      Object containing the parameters from the brute force method.
      The return values (``x0``, ``fval``, ``grid``, ``Jout``) from
      :scipydoc:`optimize.brute` are stored as ``brute_<parname>``
      attributes. The `MinimizerResult` also contains the
      :attr:``candidates`` attribute and :meth:`show_candidates`
      method. The :attr:`candidates` attribute contains the
      parameters and chisqr from the brute force method as a
      namedtuple, ``('Candidate', ['params', 'score'])`` sorted on
      the (lowest) chisqr value. To access the values for a
      particular candidate one can use ``result.candidate[#].params``
      or ``result.candidate[#].score``, where a lower # represents a
      better candidate. The :meth:`show_candidates` method uses the
      :meth:`pretty_print` method to show a specific candidate-# or
      all candidates when no number is specified.
  
  
  .. versionadded:: 0.9.6
  
  
  Notes
  -----
  The :meth:`brute` method evaluates the function at each point of a
  multidimensional grid of points. The grid points are generated from
  the parameter ranges using `Ns` and (optional) `brute_step`.
  The implementation in :scipydoc:`optimize.brute` requires finite
  bounds and the ``range`` is specified as a two-tuple ``(min, max)``
  or slice-object ``(min, max, brute_step)``. A slice-object is used
  directly, whereas a two-tuple is converted to a slice object that
  interpolates `Ns` points from ``min`` to ``max``, inclusive.
  
  In addition, the :meth:`brute` method in lmfit, handles three other
  scenarios given below with their respective slice-object:
  
      - lower bound (:attr:`min`) and :attr:`brute_step` are specified:
          ``range = (min, min + Ns * brute_step, brute_step)``.
      - upper bound (:attr:`max`) and :attr:`brute_step` are specified:
          ``range = (max - Ns * brute_step, max, brute_step)``.
      - numerical value (:attr:`value`) and :attr:`brute_step` are specified:
          ``range = (value - (Ns//2) * brute_step`, value +
          (Ns//2) * brute_step, brute_step)``.
docstr_tok: ["Use","the","`","brute","`","method","to","find","the","global","minimum","of","a","function",".","The","following","parameters","are","passed","to",":","scipydoc",":","`","optimize.brute","`","and","can","not","be","changed",":","+","--","--","--","--","--","--","--","--","--","-+","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","|",":","meth",":","`","brute","`","arg","|","Value","|","Description","|","+===================+=======+====================================+","|","`","full_output","`","|","1","|","Return","the","evaluation","grid","and","the","|","|","|","|","objective","function","'s","values","on","it",".","|","+","--","--","--","--","--","--","--","--","--","-+","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","|","`","finish","`","|","None","|","No","``","polishing","''","function","is","to","be","|","|","|","|","used","after","the","grid","search",".","|","+","--","--","--","--","--","--","--","--","--","-+","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","|","`","disp","`","|","False","|","Do","not","print","convergence","messages","|","|","|","|","(","when","finish","is","not","None",")",".","|","+","--","--","--","--","--","--","--","--","--","-+","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","It","assumes","that","the","input","Parameters","have","been","initialized",",","and","a","function","to","minimize","has","been","properly","set","up",".","Parameters","--","--","--","--","--","params",":","Parameters",",","optional","Contains","the","Parameters","for","the","model",".","If","None",",","then","the","Parameters","used","to","initialize","the","Minimizer","object","are","used",".","Ns",":","int",",","optional","Number","of","grid","points","along","the","axes",",","if","not","otherwise","specified","(","see","Notes",")",".","keep",":","int",",","optional","Number","of","best","candidates","from","the","brute","force","method","that","are","stored","in","the",":","attr",":","`","candidates","`","attribute",".","If","`","'all","'","`",",","then","all","grid","points","from",":","scipydoc",":","`","optimize.brute","`","are","stored","as","candidates",".","workers",":","int","or","map-like","callable",",","optional","For","parallel","evaluation","of","the","grid","(","see",":","scipydoc",":","`","optimize.brute","`","for","more","details",")",".","max_nfev",":","int","or","None",",","optional","Maximum","number","of","function","evaluations","(","default","is","None",")",".","Defaults","to","``","200000","*","(","nvarys+1",")","``",".","Returns","--","--","--","-","MinimizerResult","Object","containing","the","parameters","from","the","brute","force","method",".","The","return","values","(","``","x0","``",",","``","fval","``",",","``","grid","``",",","``","Jout","``",")","from",":","scipydoc",":","`","optimize.brute","`","are","stored","as","``","brute_","<","parname",">","``","attributes",".","The","`","MinimizerResult","`","also","contains","the",":","attr",":","``","candidates","``","attribute","and",":","meth",":","`","show_candidates","`","method",".","The",":","attr",":","`","candidates","`","attribute","contains","the","parameters","and","chisqr","from","the","brute","force","method","as","a","namedtuple",",","``","(","'Candidate","'",",","[","'params","'",",","'score","'","]",")","``","sorted","on","the","(","lowest",")","chisqr","value",".","To","access","the","values","for","a","particular","candidate","one","can","use","``","result.candidate","[","#","]",".params","``","or","``","result.candidate","[","#","]",".score","``",",","where","a","lower","#","represents","a","better","candidate",".","The",":","meth",":","`","show_candidates","`","method","uses","the",":","meth",":","`","pretty_print","`","method","to","show","a","specific","candidate-","#","or","all","candidates","when","no","number","is","specified",".","..","versionadded",":",":","0.9.6","Notes","--","--","-","The",":","meth",":","`","brute","`","method","evaluates","the","function","at","each","point","of","a","multidimensional","grid","of","points",".","The","grid","points","are","generated","from","the","parameter","ranges","using","`","Ns","`","and","(","optional",")","`","brute_step","`",".","The","implementation","in",":","scipydoc",":","`","optimize.brute","`","requires","finite","bounds","and","the","``","range","``","is","specified","as","a","two-tuple","``","(","min",",","max",")","``","or","slice-object","``","(","min",",","max",",","brute_step",")","``",".","A","slice-object","is","used","directly",",","whereas","a","two-tuple","is","converted","to","a","slice","object","that","interpolates","`","Ns","`","points","from","``","min","``","to","``","max","``",",","inclusive",".","In","addition",",","the",":","meth",":","`","brute","`","method","in","lmfit",",","handles","three","other","scenarios","given","below","with","their","respective","slice-object",":","-","lower","bound","(",":","attr",":","`","min","`",")","and",":","attr",":","`","brute_step","`","are","specified",":","``","range","=","(","min",",","min","+","Ns","*","brute_step",",","brute_step",")","``",".","-","upper","bound","(",":","attr",":","`","max","`",")","and",":","attr",":","`","brute_step","`","are","specified",":","``","range","=","(","max","-","Ns","*","brute_step",",","max",",","brute_step",")","``",".","-","numerical","value","(",":","attr",":","`","value","`",")","and",":","attr",":","`","brute_step","`","are","specified",":","``","range","=","(","value","-","(","Ns\/\/2",")","*","brute_step","`",",","value","+","(","Ns\/\/2",")","*","brute_step",",","brute_step",")","``","."]
code: def brute(
      self, params=None, Ns=20, keep=50, workers=1, max_nfev=None
  ):
      """Use the `brute` method to find the global minimum of a function.
  
      The following parameters are passed to :scipydoc:`optimize.brute`
      and cannot be changed:
  
      +-------------------+-------+------------------------------------+
      | :meth:`brute` arg | Value | Description                        |
      +===================+=======+====================================+
      |  `full_output`    | 1     | Return the evaluation grid and the |
      |                   |       | objective function's values on it. |
      +-------------------+-------+------------------------------------+
      |  `finish`         | None  | No "polishing" function is to be   |
      |                   |       | used after the grid search.        |
      +-------------------+-------+------------------------------------+
      |  `disp`           | False | Do not print convergence messages  |
      |                   |       | (when finish is not None).         |
      +-------------------+-------+------------------------------------+
  
      It assumes that the input Parameters have been initialized, and a
      function to minimize has been properly set up.
  
      Parameters
      ----------
      params : Parameters, optional
          Contains the Parameters for the model. If None, then the
          Parameters used to initialize the Minimizer object are used.
      Ns : int, optional
          Number of grid points along the axes, if not otherwise
          specified (see Notes).
      keep : int, optional
          Number of best candidates from the brute force method that are
          stored in the :attr:`candidates` attribute. If `'all'`, then
          all grid points from :scipydoc:`optimize.brute` are stored as
          candidates.
      workers : int or map-like callable, optional
          For parallel evaluation of the grid (see :scipydoc:`optimize.brute`
          for more details).
      max_nfev : int or None, optional
          Maximum number of function evaluations (default is None). Defaults
          to ``200000*(nvarys+1)``.
  
      Returns
      -------
      MinimizerResult
          Object containing the parameters from the brute force method.
          The return values (``x0``, ``fval``, ``grid``, ``Jout``) from
          :scipydoc:`optimize.brute` are stored as ``brute_<parname>``
          attributes. The `MinimizerResult` also contains the
          :attr:``candidates`` attribute and :meth:`show_candidates`
          method. The :attr:`candidates` attribute contains the
          parameters and chisqr from the brute force method as a
          namedtuple, ``('Candidate', ['params', 'score'])`` sorted on
          the (lowest) chisqr value. To access the values for a
          particular candidate one can use ``result.candidate[#].params``
          or ``result.candidate[#].score``, where a lower # represents a
          better candidate. The :meth:`show_candidates` method uses the
          :meth:`pretty_print` method to show a specific candidate-# or
          all candidates when no number is specified.
  
  
      .. versionadded:: 0.9.6
  
  
      Notes
      -----
      The :meth:`brute` method evaluates the function at each point of a
      multidimensional grid of points. The grid points are generated from
      the parameter ranges using `Ns` and (optional) `brute_step`.
      The implementation in :scipydoc:`optimize.brute` requires finite
      bounds and the ``range`` is specified as a two-tuple ``(min, max)``
      or slice-object ``(min, max, brute_step)``. A slice-object is used
      directly, whereas a two-tuple is converted to a slice object that
      interpolates `Ns` points from ``min`` to ``max``, inclusive.
  
      In addition, the :meth:`brute` method in lmfit, handles three other
      scenarios given below with their respective slice-object:
  
          - lower bound (:attr:`min`) and :attr:`brute_step` are specified:
              ``range = (min, min + Ns * brute_step, brute_step)``.
          - upper bound (:attr:`max`) and :attr:`brute_step` are specified:
              ``range = (max - Ns * brute_step, max, brute_step)``.
          - numerical value (:attr:`value`) and :attr:`brute_step` are specified:
              ``range = (value - (Ns//2) * brute_step`, value +
              (Ns//2) * brute_step, brute_step)``.
  
      """
      result = self.prepare_fit(params=params)
      result.method = "brute"
      self.set_max_nfev(max_nfev, 200000 * (result.nvarys + 1))
  
      brute_kws = dict(
          full_output=1, finish=None, disp=False, Ns=Ns, workers=workers
      )
  
      varying = np.asarray([par.vary for par in self.params.values()])
      replace_none = lambda x, sign: sign * np.inf if x is None else x
      lower_bounds = np.asarray(
          [replace_none(i.min, -1) for i in self.params.values()]
      )[varying]
      upper_bounds = np.asarray(
          [replace_none(i.max, 1) for i in self.params.values()]
      )[varying]
      value = np.asarray([i.value for i in self.params.values()])[
          varying
      ]
      stepsize = np.asarray(
          [i.brute_step for i in self.params.values()]
      )[varying]
  
      ranges = []
      for i, step in enumerate(stepsize):
          if np.all(np.isfinite([lower_bounds[i], upper_bounds[i]])):
              # lower AND upper bounds are specified (brute_step optional)
              par_range = (
                  (lower_bounds[i], upper_bounds[i], step)
                  if step
                  else (lower_bounds[i], upper_bounds[i])
              )
          elif np.isfinite(lower_bounds[i]) and step:
              # lower bound AND brute_step are specified
              par_range = (
                  lower_bounds[i],
                  lower_bounds[i] + Ns * step,
                  step,
              )
          elif np.isfinite(upper_bounds[i]) and step:
              # upper bound AND brute_step are specified
              par_range = (
                  upper_bounds[i] - Ns * step,
                  upper_bounds[i],
                  step,
              )
          elif np.isfinite(value[i]) and step:
              # no bounds, but an initial value is specified
              par_range = (
                  value[i] - (Ns // 2) * step,
                  value[i] + (Ns // 2) * step,
                  step,
              )
          else:
              raise ValueError(
                  "Not enough information provided for the brute "
                  "force method. Please specify bounds or at "
                  "least an initial value and brute_step for "
                  'parameter "{}".'.format(result.var_names[i])
              )
          ranges.append(par_range)
      result.call_kws = brute_kws
      try:
          ret = scipy_brute(self.penalty, tuple(ranges), **brute_kws)
      except AbortFitException:
          pass
  
      if not result.aborted:
          result.brute_x0 = ret[0]
          result.brute_fval = ret[1]
          result.brute_grid = ret[2]
          result.brute_Jout = ret[3]
  
          # sort the results of brute and populate .candidates attribute
          grid_score = ret[3].ravel()  # chisqr
          grid_points = [par.ravel() for par in ret[2]]
  
          if len(result.var_names) == 1:
              grid_result = np.array(
                  [res for res in zip(zip(grid_points), grid_score)],
                  dtype=[("par", "O"), ("score", "float")],
              )
          else:
              grid_result = np.array(
                  [res for res in zip(zip(*grid_points), grid_score)],
                  dtype=[("par", "O"), ("score", "float")],
              )
          grid_result_sorted = grid_result[
              grid_result.argsort(order="score")
          ]
  
          result.candidates = []
  
          if keep == "all":
              keep_candidates = len(grid_result_sorted)
          else:
              keep_candidates = min(len(grid_result_sorted), keep)
  
          for data in grid_result_sorted[:keep_candidates]:
              pars = deepcopy(self.params)
              for i, par in enumerate(result.var_names):
                  pars[par].value = data[0][i]
              result.candidates.append(
                  Candidate(params=pars, score=data[1])
              )
  
          result.params = result.candidates[0].params
          result.residual = self.__residual(
              result.brute_x0, apply_bounds_transformation=False
          )
          result.nfev = len(result.brute_Jout.ravel())
      elif result.nfev > self.max_nfev - 5:
          result.nfev -= 2
          _best = result.last_internal_values
          result.residual = self.__residual(_best, False)
      result._calculate_statistics()
  
      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 18 for calling the Minimizer obj's underlying member method code with example usage: obj.brute(params, Ns, keep, workers, max_nfev) and returns: result