class_docstr: A general minimizer for curve fitting and optimization.
class_docstr_tok: ["A","general","minimizer","for","curve","fitting","and","optimization","."]
docstr: Find the global minimum of a multivariate function using AMPGO.
  
  AMPGO stands for 'Adaptive Memory Programming for Global
  Optimization' and is an efficient algorithm to find the global
  minimum.
  
  Parameters
  ----------
  params : Parameters, optional
      Contains the Parameters for the model. If None, then the
      Parameters used to initialize the Minimizer object are used.
  max_nfev : int, optional
      Maximum number of total function evaluations. If None
      (default), the optimization will stop after `totaliter` number
      of iterations (see below)..
  **kws : dict, optional
      Minimizer options to pass to the ampgo algorithm, the options
      are listed below::
  
          local: str, optional
              Name of the local minimization method. Valid options
              are:
              - `'L-BFGS-B'` (default)
              - `'Nelder-Mead'`
              - `'Powell'`
              - `'TNC'`
              - `'SLSQP'`
          local_opts: dict, optional
              Options to pass to the local minimizer (default is
              None).
          maxfunevals: int, optional
              Maximum number of function evaluations. If None
              (default), the optimization will stop after
              `totaliter` number of iterations (deprecated: use
              `max_nfev` instead).
          totaliter: int, optional
              Maximum number of global iterations (default is 20).
          maxiter: int, optional
              Maximum number of `Tabu Tunneling` iterations during
              each global iteration (default is 5).
          glbtol: float, optional
              Tolerance whether or not to accept a solution after a
              tunneling phase (default is 1e-5).
          eps1: float, optional
              Constant used to define an aspiration value for the
              objective function during the Tunneling phase (default
              is 0.02).
          eps2: float, optional
              Perturbation factor used to move away from the latest
              local minimum at the start of a Tunneling phase
              (default is 0.1).
          tabulistsize: int, optional
              Size of the (circular) tabu search list (default is 5).
          tabustrategy: {'farthest', 'oldest'}, optional
              Strategy to use when the size of the tabu list exceeds
              `tabulistsize`. It can be `'oldest'` to drop the oldest
              point from the tabu list or `'farthest'` (defauilt) to
              drop the element farthest from the last local minimum
              found.
          disp: bool, optional
              Set to True to print convergence messages (default is
              False).
  
  Returns
  -------
  MinimizerResult
      Object containing the parameters from the ampgo method, with
      fit parameters, statistics and such. The return values
      (``x0``, ``fval``, ``eval``, ``msg``, ``tunnel``) are stored
      as ``ampgo_<parname>`` attributes.
  
  
  .. versionadded:: 0.9.10
  
  
  Notes
  -----
  The Python implementation was written by Andrea Gavana in 2014
  (http://infinity77.net/global_optimization/index.html).
  
  The details of the AMPGO algorithm are described in the paper
  "Adaptive Memory Programming for Constrained Global Optimization"
  located here:
  
  http://leeds-faculty.colorado.edu/glover/fred%20pubs/416%20-%20AMP%20(TS)%20for%20Constrained%20Global%20Opt%20w%20Lasdon%20et%20al%20.pdf
docstr_tok: ["Find","the","global","minimum","of","a","multivariate","function","using","AMPGO",".","AMPGO","stands","for","'Adaptive","Memory","Programming","for","Global","Optimization","'","and","is","an","efficient","algorithm","to","find","the","global","minimum",".","Parameters","--","--","--","--","--","params",":","Parameters",",","optional","Contains","the","Parameters","for","the","model",".","If","None",",","then","the","Parameters","used","to","initialize","the","Minimizer","object","are","used",".","max_nfev",":","int",",","optional","Maximum","number","of","total","function","evaluations",".","If","None","(","default",")",",","the","optimization","will","stop","after","`","totaliter","`","number","of","iterations","(","see","below",")","..","*","*","kws",":","dict",",","optional","Minimizer","options","to","pass","to","the","ampgo","algorithm",",","the","options","are","listed","below",":",":","local",":","str",",","optional","Name","of","the","local","minimization","method",".","Valid","options","are",":","-","`","'","L-BFGS-B","'","`","(","default",")","-","`","'Nelder-Mead","'","`","-","`","'Powell","'","`","-","`","'TNC","'","`","-","`","'SLSQP","'","`","local_opts",":","dict",",","optional","Options","to","pass","to","the","local","minimizer","(","default","is","None",")",".","maxfunevals",":","int",",","optional","Maximum","number","of","function","evaluations",".","If","None","(","default",")",",","the","optimization","will","stop","after","`","totaliter","`","number","of","iterations","(","deprecated",":","use","`","max_nfev","`","instead",")",".","totaliter",":","int",",","optional","Maximum","number","of","global","iterations","(","default","is","20",")",".","maxiter",":","int",",","optional","Maximum","number","of","`","Tabu","Tunneling","`","iterations","during","each","global","iteration","(","default","is","5",")",".","glbtol",":","float",",","optional","Tolerance","whether","or","not","to","accept","a","solution","after","a","tunneling","phase","(","default","is","1e-5",")",".","eps1",":","float",",","optional","Constant","used","to","define","an","aspiration","value","for","the","objective","function","during","the","Tunneling","phase","(","default","is","0.02",")",".","eps2",":","float",",","optional","Perturbation","factor","used","to","move","away","from","the","latest","local","minimum","at","the","start","of","a","Tunneling","phase","(","default","is","0.1",")",".","tabulistsize",":","int",",","optional","Size","of","the","(","circular",")","tabu","search","list","(","default","is","5",")",".","tabustrategy",":","{","'farthest","'",",","'oldest","'","}",",","optional","Strategy","to","use","when","the","size","of","the","tabu","list","exceeds","`","tabulistsize","`",".","It","can","be","`","'oldest","'","`","to","drop","the","oldest","point","from","the","tabu","list","or","`","'farthest","'","`","(","defauilt",")","to","drop","the","element","farthest","from","the","last","local","minimum","found",".","disp",":","bool",",","optional","Set","to","True","to","print","convergence","messages","(","default","is","False",")",".","Returns","--","--","--","-","MinimizerResult","Object","containing","the","parameters","from","the","ampgo","method",",","with","fit","parameters",",","statistics","and","such",".","The","return","values","(","``","x0","``",",","``","fval","``",",","``","eval","``",",","``","msg","``",",","``","tunnel","``",")","are","stored","as","``","ampgo_","<","parname",">","``","attributes",".","..","versionadded",":",":","0.9.10","Notes","--","--","-","The","Python","implementation","was","written","by","Andrea","Gavana","in","2014","(","http",":","\/\/infinity77.net\/global_optimization\/index.html",")",".","The","details","of","the","AMPGO","algorithm","are","described","in","the","paper","''","Adaptive","Memory","Programming","for","Constrained","Global","Optimization","''","located","here",":","http",":","\/\/leeds-faculty.colorado.edu\/glover\/fred","%","20pubs\/416","%","20-","%","20AMP","%","20","(","TS",")","%","20for","%","20Constrained","%","20Global","%","20Opt","%","20w","%","20Lasdon","%","20et","%","20al","%","20.pdf"]
code: def ampgo(self, params=None, max_nfev=None, **kws):
      """Find the global minimum of a multivariate function using AMPGO.
  
      AMPGO stands for 'Adaptive Memory Programming for Global
      Optimization' and is an efficient algorithm to find the global
      minimum.
  
      Parameters
      ----------
      params : Parameters, optional
          Contains the Parameters for the model. If None, then the
          Parameters used to initialize the Minimizer object are used.
      max_nfev : int, optional
          Maximum number of total function evaluations. If None
          (default), the optimization will stop after `totaliter` number
          of iterations (see below)..
      **kws : dict, optional
          Minimizer options to pass to the ampgo algorithm, the options
          are listed below::
  
              local: str, optional
                  Name of the local minimization method. Valid options
                  are:
                  - `'L-BFGS-B'` (default)
                  - `'Nelder-Mead'`
                  - `'Powell'`
                  - `'TNC'`
                  - `'SLSQP'`
              local_opts: dict, optional
                  Options to pass to the local minimizer (default is
                  None).
              maxfunevals: int, optional
                  Maximum number of function evaluations. If None
                  (default), the optimization will stop after
                  `totaliter` number of iterations (deprecated: use
                  `max_nfev` instead).
              totaliter: int, optional
                  Maximum number of global iterations (default is 20).
              maxiter: int, optional
                  Maximum number of `Tabu Tunneling` iterations during
                  each global iteration (default is 5).
              glbtol: float, optional
                  Tolerance whether or not to accept a solution after a
                  tunneling phase (default is 1e-5).
              eps1: float, optional
                  Constant used to define an aspiration value for the
                  objective function during the Tunneling phase (default
                  is 0.02).
              eps2: float, optional
                  Perturbation factor used to move away from the latest
                  local minimum at the start of a Tunneling phase
                  (default is 0.1).
              tabulistsize: int, optional
                  Size of the (circular) tabu search list (default is 5).
              tabustrategy: {'farthest', 'oldest'}, optional
                  Strategy to use when the size of the tabu list exceeds
                  `tabulistsize`. It can be `'oldest'` to drop the oldest
                  point from the tabu list or `'farthest'` (defauilt) to
                  drop the element farthest from the last local minimum
                  found.
              disp: bool, optional
                  Set to True to print convergence messages (default is
                  False).
  
      Returns
      -------
      MinimizerResult
          Object containing the parameters from the ampgo method, with
          fit parameters, statistics and such. The return values
          (``x0``, ``fval``, ``eval``, ``msg``, ``tunnel``) are stored
          as ``ampgo_<parname>`` attributes.
  
  
      .. versionadded:: 0.9.10
  
  
      Notes
      -----
      The Python implementation was written by Andrea Gavana in 2014
      (http://infinity77.net/global_optimization/index.html).
  
      The details of the AMPGO algorithm are described in the paper
      "Adaptive Memory Programming for Constrained Global Optimization"
      located here:
  
      http://leeds-faculty.colorado.edu/glover/fred%20pubs/416%20-%20AMP%20(TS)%20for%20Constrained%20Global%20Opt%20w%20Lasdon%20et%20al%20.pdf
  
      """
      result = self.prepare_fit(params=params)
      self.set_max_nfev(max_nfev, 200000 * (result.nvarys + 1))
  
      ampgo_kws = dict(
          local="L-BFGS-B",
          local_opts=None,
          maxfunevals=None,
          totaliter=20,
          maxiter=5,
          glbtol=1e-5,
          eps1=0.02,
          eps2=0.1,
          tabulistsize=5,
          tabustrategy="farthest",
          disp=False,
      )
      ampgo_kws.update(self.kws)
      ampgo_kws.update(kws)
  
      values = result._init_vals_internal
      result.method = (
          f"ampgo, with {ampgo_kws['local']} as local solver"
      )
      result.call_kws = ampgo_kws
      try:
          ret = ampgo(self.penalty, values, **ampgo_kws)
      except AbortFitException:
          pass
  
      if not result.aborted:
          result.ampgo_x0 = ret[0]
          result.ampgo_fval = ret[1]
          result.ampgo_eval = ret[2]
          result.ampgo_msg = ret[3]
          result.ampgo_tunnel = ret[4]
  
          for i, par in enumerate(result.var_names):
              result.params[par].value = result.ampgo_x0[i]
  
          result.residual = self.__residual(result.ampgo_x0)
          result.nfev -= 1
      elif result.nfev > self.max_nfev - 5:
          result.nfev -= 2
          _best = result.last_internal_values
          result.residual = self.__residual(_best, False)
  
      result._calculate_statistics()
  
      # calculate the cov_x and estimate uncertainties/correlations
      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.ampgo_x0
          )
          if _covar_ndt is not None:
              result.covar = self._int2ext_cov_x(
                  _covar_ndt, result.ampgo_x0
              )
              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 19 for calling the Minimizer obj's underlying member method code with example usage: obj.ampgo(params, max_nfev) and returns: result