code: def fmin(
      cost,
      x0,
      args=(),
      bounds=None,
      xtol=1e-4,
      ftol=1e-4,
      maxiter=None,
      maxfun=None,
      full_output=0,
      disp=1,
      retall=0,
      callback=None,
      **kwds,
  ):
      """Minimize a function using the downhill simplex algorithm.
  
      Uses a Nelder-Mead simplex algorithm to find the minimum of a function of one
      or more variables. This algorithm only uses function values, not derivatives or second derivatives. Mimics the ``scipy.optimize.fmin`` interface.
  
      This algorithm has a long history of successful use in applications. It will
      usually be slower than an algorithm that uses first or second derivative
      information. In practice it can have poor performance in high-dimensional
      problems and is not robust to minimizing complicated functions. Additionally,
      there currently is no complete theory describing when the algorithm will
      successfully converge to the minimum, or how fast it will if it does. Both the
      ftol and xtol criteria must be met for convergence.
  
      Args:
          cost (func): the function or method to be minimized: ``y = cost(x)``.
          x0 (ndarray): the initial guess parameter vector ``x``.
          args (tuple, default=()): extra arguments for cost.
          bounds (list(tuple), default=None): list of pairs of bounds (min,max),
              one for each parameter.
          xtol (float, default=1e-4): acceptable absolute error in ``xopt`` for
              convergence.
          ftol (float, default=1e-4): acceptable absolute error in ``cost(xopt)``
              for convergence.
          maxiter (int, default=None): the maximum number of iterations to perform.
          maxfun (int, default=None): the maximum number of function evaluations.
          full_output (bool, default=False): True if fval and warnflag are desired.
          disp (bool, default=True): if True, print convergence messages.
          retall (bool, default=False): True if allvecs is desired.
          callback (func, default=None): function to call after each iteration. The
              interface is ``callback(xk)``, with xk the current parameter vector.
          id (int, default=None): the ``id`` of the solver used in logging.
          handler (bool, default=False): if True, enable handling interrupt signals.
          itermon (monitor, default=None): override the default GenerationMonitor.
          evalmon (monitor, default=None): override the default EvaluationMonitor.
          constraints (func, default=None): a function ``xk' = constraints(xk)``,
              where xk is the current parameter vector, and xk' is a parameter
              vector that satisfies the encoded constraints.
          penalty (func, default=None): a function ``y = penalty(xk)``, where xk is
              the current parameter vector, and ``y' == 0`` when the encoded
              constraints are satisfied (and ``y' > 0`` otherwise).
          tightrange (bool, default=None): impose bounds and constraints concurrently.
          cliprange (bool, default=None): bounding constraints clip exterior values.
  
      Returns:
          ``(xopt, {fopt, iter, funcalls, warnflag}, {allvecs})``
  
      Notes:
          - xopt (*ndarray*): the minimizer of the cost function
          - fopt (*float*): value of cost function at minimum: ``fopt = cost(xopt)``
          - iter (*int*): number of iterations
          - funcalls (*int*): number of function calls
          - warnflag (*int*): warning flag
              - ``1 : Maximum number of function evaluations``
              - ``2 : Maximum number of iterations``
          - allvecs (*list*): a list of solutions at each iteration
      """
      handler = kwds["handler"] if "handler" in kwds else False
  
      from mystic.monitors import Monitor
  
      stepmon = kwds["itermon"] if "itermon" in kwds else Monitor()
      evalmon = kwds["evalmon"] if "evalmon" in kwds else Monitor()
  
      if (
          xtol
      ):  # if tolerance in x is provided, use CandidateRelativeTolerance
          from mystic.termination import (
              CandidateRelativeTolerance as CRT,
          )
  
          termination = CRT(xtol, ftol)
      else:
          from mystic.termination import VTRChangeOverGeneration
  
          termination = VTRChangeOverGeneration(ftol)
      solver = NelderMeadSimplexSolver(len(x0))
      solver.SetInitialPoints(x0)
      solver.SetEvaluationLimits(maxiter, maxfun)
      solver.SetEvaluationMonitor(evalmon)
      solver.SetGenerationMonitor(stepmon)
      if "id" in kwds:
          solver.id = int(kwds["id"])
      if "penalty" in kwds:
          solver.SetPenalty(kwds["penalty"])
      if "constraints" in kwds:
          solver.SetConstraints(kwds["constraints"])
      if bounds is not None:
          minb, maxb = unpair(bounds)
          tight = kwds["tightrange"] if "tightrange" in kwds else None
          clip = kwds["cliprange"] if "cliprange" in kwds else None
          solver.SetStrictRanges(minb, maxb, tight=tight, clip=clip)
  
      if handler:
          solver.enable_signal_handler()
      solver.Solve(
          cost,
          termination=termination,
          disp=disp,
          ExtraArgs=args,
          callback=callback,
      )
      solution = solver.Solution()
  
      # code below here pushes output to scipy.optimize.fmin interface
      # x = list(solver.bestSolution)
      x = solver.bestSolution
      fval = solver.bestEnergy
      warnflag = 0
      fcalls = solver.evaluations
      iterations = solver.generations
      allvecs = stepmon.x
  
      if fcalls >= solver._maxfun:
          warnflag = 1
      elif iterations >= solver._maxiter:
          warnflag = 2
  
      if full_output:
          retlist = x, fval, iterations, fcalls, warnflag
          if retall:
              retlist += (allvecs,)
      else:
          retlist = x
          if retall:
              retlist = (x, allvecs)
  
      return retlist
  
imports: from mystic.tools import wrap_function, unpair, wrap_nested
  from mystic.tools import wrap_bounds, wrap_penalty, reduced
  import numpy
  from numpy import eye, zeros, shape, asarray, absolute, asfarray
  from numpy import clip, squeeze
  from mystic._scipy060optimize import brent
  from mystic.abstract_solver import AbstractSolver
label_desc: Use image node_id 1 for calling a global function with example usage: fmin(cost, x0, args, bounds, xtol, ftol, maxiter, maxfun, full_output, disp, retall, callback) and returns: retlist