original_docstring: Minimize cost given minimum output constraint using golden section/binary search.
  
      Given discrete function f that monotonically increases then monotonically decreases,
      find the minimum integer x such that f(x) >= vmin.
  
      This method uses Fibonacci search to find the upper bound of x.  If the upper bound
      is found, a binary search is performed in the interval to find the solution.  If
      vmin is close to the maximum of f, a golden section search is performed to attempt
      to find x.
  
      Parameters
      ----------
      f : Callable[[int], float]
          a function that takes a single integer and output a scalar value.  Must monotonically
          increase then monotonically decrease.
      vmin : float
          the minimum output value.
      start : float
          the input lower bound.
      stop : float
          the input upper bound.
      tol : float
          the solution tolerance.
      maxiter : int
          maximum number of iterations to perform.
  
      Returns
      -------
      result : MinCostResult
          the MinCostResult named tuple, with attributes:
  
          x : Optional[int]
              the minimum integer such that f(x) >= vmin.  If no such x exists, this will be None.
          xmax : Optional[int]
              the value at which f achieves its maximum.  This is set only if x is None
          vmax : Optional[float]
              the maximum value of f.  This is set only if x is None.
          nfev : int
              total number of function calls made.
      
docstring: Minimize cost given minimum output constraint using golden section/binary search.
  Given discrete function f that monotonically increases then monotonically decreases,
  find the minimum integer x such that f(x) >= vmin.
  
  This method uses Fibonacci search to find the upper bound of x.  If the upper bound
  is found, a binary search is performed in the interval to find the solution.  If
  vmin is close to the maximum of f, a golden section search is performed to attempt
  to find x.
  
  Parameters
  
  f : Callable[[int], float]
  a function that takes a single integer and output a scalar value.  Must monotonically
  increase then monotonically decrease.
  vmin : float
  the minimum output value.
  start : float
  the input lower bound.
  stop : float
  the input upper bound.
  tol : float
  the solution tolerance.
  maxiter : int
  maximum number of iterations to perform.
  
  Returns
  
  result : MinCostResult
  the MinCostResult named tuple, with attributes.
  
  x : Optional[int]
  the minimum integer such that f(x) >= vmin.  If no such x exists, this will be None.
  xmax : Optional[int]
  the value at which f achieves its maximum.  This is set only if x is None
  vmax : Optional[float]
  the maximum value of f.  This is set only if x is None.
  nfev : int
  total number of function calls made.
docstring_tokens: Minimize cost given minimum output constraint using golden section / binary search . Given discrete function f that monotonically increases then monotonically decreases find the minimum integer x such that f ( x ) > = vmin . This method uses Fibonacci search to find the upper bound of x . If the upper bound is found a binary search is performed in the interval to find the solution . If vmin is close to the maximum of f a golden section search is performed to attempt to find x . Parameters f : Callable [[ int ] float ] a function that takes a single integer and output a scalar value . Must monotonically increase then monotonically decrease . vmin : float the minimum output value . start : float the input lower bound . stop : float the input upper bound . tol : float the solution tolerance . maxiter : int maximum number of iterations to perform . Returns result : MinCostResult the MinCostResult named tuple with attributes . x : Optional [ int ] the minimum integer such that f ( x ) > = vmin . If no such x exists this will be None . xmax : Optional [ int ] the value at which f achieves its maximum . This is set only if x is None vmax : Optional [ float ] the maximum value of f . This is set only if x is None . nfev : int total number of function calls made .
code: def minimize_cost_golden_float(f, vmin, start, stop, tol=1e-8, maxiter=1000):
      # type: (Callable[[float], float], float, float, float, float, int) -> MinCostResult
      """Minimize cost given minimum output constraint using golden section/binary search.
  
      Given discrete function f that monotonically increases then monotonically decreases,
      find the minimum integer x such that f(x) >= vmin.
  
      This method uses Fibonacci search to find the upper bound of x.  If the upper bound
      is found, a binary search is performed in the interval to find the solution.  If
      vmin is close to the maximum of f, a golden section search is performed to attempt
      to find x.
  
      Parameters
      ----------
      f : Callable[[int], float]
          a function that takes a single integer and output a scalar value.  Must monotonically
          increase then monotonically decrease.
      vmin : float
          the minimum output value.
      start : float
          the input lower bound.
      stop : float
          the input upper bound.
      tol : float
          the solution tolerance.
      maxiter : int
          maximum number of iterations to perform.
  
      Returns
      -------
      result : MinCostResult
          the MinCostResult named tuple, with attributes:
  
          x : Optional[int]
              the minimum integer such that f(x) >= vmin.  If no such x exists, this will be None.
          xmax : Optional[int]
              the value at which f achieves its maximum.  This is set only if x is None
          vmax : Optional[float]
              the maximum value of f.  This is set only if x is None.
          nfev : int
              total number of function calls made.
      """
  
      fa = f(start)
      if fa >= vmin:
          # solution found at start
          return MinCostResult(x=start, xmax=None, vmax=None, nfev=1)
  
      fb = f(stop)  # type: Optional[float]
      if fb is None:
          raise TypeError("f(stop) returned None instead of float")
      if fb >= vmin:
          # found upper bound, use binary search to find answer
          return minimize_cost_binary_float(f, vmin, start, stop, tol=tol, save=stop, nfev=2)
  
      # solution is somewhere in middle
      gr = (5**0.5 + 1) / 2
      delta = (stop - start) / gr
      c = stop - delta
      d = start + delta
  
      fc = f(c)  # type: Optional[float]
      if fc is None:
          raise TypeError("f(c) returned None instead of float")
      if fc >= vmin:
          # found upper bound, use binary search to find answer
          return minimize_cost_binary_float(f, vmin, start, c, tol=tol, save=stop, nfev=3)
  
      fd = f(d)  # type: Optional[float]
      if fd is None:
          raise TypeError("f(d) returned None instead of float")
      if fd >= vmin:
          # found upper bound, use binary search to find answer
          return minimize_cost_binary_float(f, vmin, start, c, tol=tol, save=stop, nfev=4)
  
      if fc > fd:
          a, b, d = start, d, c
          c = b - (b - a) / gr
          fb, fc, fd = fd, None, fc
      else:
          a, b, c = c, stop, d
          d = a + (b - a) / gr
          fa, fc, fd = fc, fd, None
  
      nfev = 4
      while abs(b - a) > tol and nfev < maxiter:
          if fc is None:
              fc = f(c)
          else:
              fd = f(d)
          assert fc is not None, 'Either fc or fd was None and the above should have set it'
          assert fd is not None, 'Either fc or fd was None and the above should have set it'
          nfev += 1
          if fc > fd:
              if fc >= vmin:
                  return minimize_cost_binary_float(f, vmin, a, c, tol=tol, save=stop, nfev=nfev)
              b, d = d, c
              c = b - (b - a) / gr
              fb, fc, fd = fd, None, fc
          else:
              if fd >= vmin:
                  return minimize_cost_binary_float(f, vmin, a, d, tol=tol, save=stop, nfev=nfev)
              a, c = c, d
              d = a + (b - a) / gr
              fa, fc, fd = fc, fd, None
  
      test = (a + b) / 2
      vmax = f(test)
      nfev += 1
      if vmax >= vmin:
          return MinCostResult(x=test, xmax=test, vmax=vmax, nfev=nfev)
      else:
          return MinCostResult(x=None, xmax=test, vmax=vmax, nfev=nfev)
code_tokens: def minimize_cost_golden_float ( f , vmin , start , stop , tol = 1e-8 , maxiter = 1000 ) : fa = f ( start ) if fa >= vmin : return MinCostResult ( x = start , xmax = None , vmax = None , nfev = 1 ) fb = f ( stop ) if fb is None : raise TypeError ( "f(stop) returned None instead of float" ) if fb >= vmin : return minimize_cost_binary_float ( f , vmin , start , stop , tol = tol , save = stop , nfev = 2 ) gr = ( 5 ** 0.5 + 1 ) / 2 delta = ( stop - start ) / gr c = stop - delta d = start + delta fc = f ( c ) if fc is None : raise TypeError ( "f(c) returned None instead of float" ) if fc >= vmin : return minimize_cost_binary_float ( f , vmin , start , c , tol = tol , save = stop , nfev = 3 ) fd = f ( d ) if fd is None : raise TypeError ( "f(d) returned None instead of float" ) if fd >= vmin : return minimize_cost_binary_float ( f , vmin , start , c , tol = tol , save = stop , nfev = 4 ) if fc > fd : a , b , d = start , d , c c = b - ( b - a ) / gr fb , fc , fd = fd , None , fc else : a , b , c = c , stop , d d = a + ( b - a ) / gr fa , fc , fd = fc , fd , None nfev = 4 while abs ( b - a ) > tol and nfev < maxiter : if fc is None : fc = f ( c ) else : fd = f ( d ) assert fc is not None , 'Either fc or fd was None and the above should have set it' assert fd is not None , 'Either fc or fd was None and the above should have set it' nfev += 1 if fc > fd : if fc >= vmin : return minimize_cost_binary_float ( f , vmin , a , c , tol = tol , save = stop , nfev = nfev ) b , d = d , c c = b - ( b - a ) / gr fb , fc , fd = fd , None , fc else : if fd >= vmin : return minimize_cost_binary_float ( f , vmin , a , d , tol = tol , save = stop , nfev = nfev ) a , c = c , d d = a + ( b - a ) / gr fa , fc , fd = fc , fd , None test = ( a + b ) / 2 vmax = f ( test ) nfev += 1 if vmax >= vmin : return MinCostResult ( x = test , xmax = test , vmax = vmax , nfev = nfev ) else : return MinCostResult ( x = None , xmax = test , vmax = vmax , nfev = nfev )
short_docstring: Minimize cost given minimum output constraint using golden section/binary search.
short_docstring_tokens: Minimize cost given minimum output constraint using golden section / binary search .
comment: # type: (Callable[[float], float], float, float, float, float, int) -> MinCostResult$SEP$"""Minimize cost given minimum output constraint using golden section/binary search.
  
      Given discrete function f that monotonically increases then monotonically decreases,
      find the minimum integer x such that f(x) >= vmin.
  
      This method uses Fibonacci search to find the upper bound of x.  If the upper bound
      is found, a binary search is performed in the interval to find the solution.  If
      vmin is close to the maximum of f, a golden section search is performed to attempt
      to find x.
  
      Parameters
      ----------
      f : Callable[[int], float]
          a function that takes a single integer and output a scalar value.  Must monotonically
          increase then monotonically decrease.
      vmin : float
          the minimum output value.
      start : float
          the input lower bound.
      stop : float
          the input upper bound.
      tol : float
          the solution tolerance.
      maxiter : int
          maximum number of iterations to perform.
  
      Returns
      -------
      result : MinCostResult
          the MinCostResult named tuple, with attributes:
  
          x : Optional[int]
              the minimum integer such that f(x) >= vmin.  If no such x exists, this will be None.
          xmax : Optional[int]
              the value at which f achieves its maximum.  This is set only if x is None
          vmax : Optional[float]
              the maximum value of f.  This is set only if x is None.
          nfev : int
              total number of function calls made.
      """$SEP$# solution found at start$SEP$# type: Optional[float]$SEP$# found upper bound, use binary search to find answer$SEP$# solution is somewhere in middle$SEP$# type: Optional[float]$SEP$# found upper bound, use binary search to find answer$SEP$# type: Optional[float]$SEP$# found upper bound, use binary search to find answer