parameters: (func, x0, args=(), callback=None,
                       xtol=1e-4, ftol=1e-4, maxiter=None, maxfev=None,
                       disp=False, direc=None, return_all=False,
                       **unknown_options)
return_statement: return result
docstring: Minimization of scalar function of one or more variables using the
      modified Powell algorithm.
  
      Options
      -------
      disp : bool
          Set to True to print convergence messages.
      xtol : float
          Relative error in solution `xopt` acceptable for convergence.
      ftol : float
          Relative error in ``fun(xopt)`` acceptable for convergence.
      maxiter, maxfev : int
          Maximum allowed number of iterations and function evaluations.
          Will default to ``N*1000``, where ``N`` is the number of
          variables, if neither `maxiter` or `maxfev` is set. If both
          `maxiter` and `maxfev` are set, minimization will stop at the
          first reached.
      direc : ndarray
          Initial set of direction vectors for the Powell method.
docstring_summary: Minimization of scalar function of one or more variables using the
      modified Powell algorithm.
docstring_tokens: Minimization of scalar function of one or more variables using the modified Powell algorithm .
function: def _minimize_powell(func, x0, args=(), callback=None,
                       xtol=1e-4, ftol=1e-4, maxiter=None, maxfev=None,
                       disp=False, direc=None, return_all=False,
                       **unknown_options):
      """
      Minimization of scalar function of one or more variables using the
      modified Powell algorithm.
  
      Options
      -------
      disp : bool
          Set to True to print convergence messages.
      xtol : float
          Relative error in solution `xopt` acceptable for convergence.
      ftol : float
          Relative error in ``fun(xopt)`` acceptable for convergence.
      maxiter, maxfev : int
          Maximum allowed number of iterations and function evaluations.
          Will default to ``N*1000``, where ``N`` is the number of
          variables, if neither `maxiter` or `maxfev` is set. If both
          `maxiter` and `maxfev` are set, minimization will stop at the
          first reached.
      direc : ndarray
          Initial set of direction vectors for the Powell method.
  
      """
      _check_unknown_options(unknown_options)
      maxfun = maxfev
      retall = return_all
      # we need to use a mutable object here that we can update in the
      # wrapper function
      fcalls, func = wrap_function(func, args)
      x = asarray(x0).flatten()
      if retall:
          allvecs = [x]
      N = len(x)
      # If neither are set, then set both to default
      if maxiter is None and maxfun is None:
          maxiter = N * 1000
          maxfun = N * 1000
      elif maxiter is None:
          # Convert remaining Nones, to np.inf, unless the other is np.inf, in
          # which case use the default to avoid unbounded iteration
          if maxfun == np.inf:
              maxiter = N * 1000
          else:
              maxiter = np.inf
      elif maxfun is None:
          if maxiter == np.inf:
              maxfun = N * 1000
          else:
              maxfun = np.inf
  
      if direc is None:
          direc = eye(N, dtype=float)
      else:
          direc = asarray(direc, dtype=float)
  
      fval = squeeze(func(x))
      x1 = x.copy()
      iter = 0
      ilist = list(range(N))
      while True:
          fx = fval
          bigind = 0
          delta = 0.0
          for i in ilist:
              direc1 = direc[i]
              fx2 = fval
              fval, x, direc1 = _linesearch_powell(func, x, direc1,
                                                   tol=xtol * 100)
              if (fx2 - fval) > delta:
                  delta = fx2 - fval
                  bigind = i
          iter += 1
          if callback is not None:
              callback(x)
          if retall:
              allvecs.append(x)
          bnd = ftol * (numpy.abs(fx) + numpy.abs(fval)) + 1e-20
          if 2.0 * (fx - fval) <= bnd:
              break
          if fcalls[0] >= maxfun:
              break
          if iter >= maxiter:
              break
  
          # Construct the extrapolated point
          direc1 = x - x1
          x2 = 2*x - x1
          x1 = x.copy()
          fx2 = squeeze(func(x2))
  
          if (fx > fx2):
              t = 2.0*(fx + fx2 - 2.0*fval)
              temp = (fx - fval - delta)
              t *= temp*temp
              temp = fx - fx2
              t -= delta*temp*temp
              if t < 0.0:
                  fval, x, direc1 = _linesearch_powell(func, x, direc1,
                                                       tol=xtol*100)
                  direc[bigind] = direc[-1]
                  direc[-1] = direc1
  
      warnflag = 0
      if fcalls[0] >= maxfun:
          warnflag = 1
          msg = _status_message['maxfev']
          if disp:
              print("Warning: " + msg)
      elif iter >= maxiter:
          warnflag = 2
          msg = _status_message['maxiter']
          if disp:
              print("Warning: " + msg)
      else:
          msg = _status_message['success']
          if disp:
              print(msg)
              print("         Current function value: %f" % fval)
              print("         Iterations: %d" % iter)
              print("         Function evaluations: %d" % fcalls[0])
  
      x = squeeze(x)
  
      result = OptimizeResult(fun=fval, direc=direc, nit=iter, nfev=fcalls[0],
                              status=warnflag, success=(warnflag == 0),
                              message=msg, x=x)
      if retall:
          result['allvecs'] = allvecs
      return result
function_tokens: def _minimize_powell ( func , x0 , args = ( ) , callback = None , xtol = 1e-4 , ftol = 1e-4 , maxiter = None , maxfev = None , disp = False , direc = None , return_all = False , * * unknown_options ) : _check_unknown_options ( unknown_options ) maxfun = maxfev retall = return_all # we need to use a mutable object here that we can update in the # wrapper function fcalls , func = wrap_function ( func , args ) x = asarray ( x0 ) . flatten ( ) if retall : allvecs = [ x ] N = len ( x ) # If neither are set, then set both to default if maxiter is None and maxfun is None : maxiter = N * 1000 maxfun = N * 1000 elif maxiter is None : # Convert remaining Nones, to np.inf, unless the other is np.inf, in # which case use the default to avoid unbounded iteration if maxfun == np . inf : maxiter = N * 1000 else : maxiter = np . inf elif maxfun is None : if maxiter == np . inf : maxfun = N * 1000 else : maxfun = np . inf if direc is None : direc = eye ( N , dtype = float ) else : direc = asarray ( direc , dtype = float ) fval = squeeze ( func ( x ) ) x1 = x . copy ( ) iter = 0 ilist = list ( range ( N ) ) while True : fx = fval bigind = 0 delta = 0.0 for i in ilist : direc1 = direc [ i ] fx2 = fval fval , x , direc1 = _linesearch_powell ( func , x , direc1 , tol = xtol * 100 ) if ( fx2 - fval ) > delta : delta = fx2 - fval bigind = i iter += 1 if callback is not None : callback ( x ) if retall : allvecs . append ( x ) bnd = ftol * ( numpy . abs ( fx ) + numpy . abs ( fval ) ) + 1e-20 if 2.0 * ( fx - fval ) <= bnd : break if fcalls [ 0 ] >= maxfun : break if iter >= maxiter : break # Construct the extrapolated point direc1 = x - x1 x2 = 2 * x - x1 x1 = x . copy ( ) fx2 = squeeze ( func ( x2 ) ) if ( fx > fx2 ) : t = 2.0 * ( fx + fx2 - 2.0 * fval ) temp = ( fx - fval - delta ) t *= temp * temp temp = fx - fx2 t -= delta * temp * temp if t < 0.0 : fval , x , direc1 = _linesearch_powell ( func , x , direc1 , tol = xtol * 100 ) direc [ bigind ] = direc [ - 1 ] direc [ - 1 ] = direc1 warnflag = 0 if fcalls [ 0 ] >= maxfun : warnflag = 1 msg = _status_message [ 'maxfev' ] if disp : print ( "Warning: " + msg ) elif iter >= maxiter : warnflag = 2 msg = _status_message [ 'maxiter' ] if disp : print ( "Warning: " + msg ) else : msg = _status_message [ 'success' ] if disp : print ( msg ) print ( "         Current function value: %f" % fval ) print ( "         Iterations: %d" % iter ) print ( "         Function evaluations: %d" % fcalls [ 0 ] ) x = squeeze ( x ) result = OptimizeResult ( fun = fval , direc = direc , nit = iter , nfev = fcalls [ 0 ] , status = warnflag , success = ( warnflag == 0 ) , message = msg , x = x ) if retall : result [ 'allvecs' ] = allvecs return result