optimization Module

Overview

The optimization module contains optimization-related code used in other modules.

API Reference

Golden-section search. Adapted from https://en.wikipedia.org/wiki/Golden-section_search. This implementation reuses function evaluations, saving 1/2 of the evaluations per iteration, and returns a bounding interval.

Given a function f with a single local minimum in the interval [a, b], returns a point within tol of the minimizer.

Example:

>>> f = lambda x: (x-2)**2
>>> a = 1
>>> b = 5
>>> tol = 1e-5
>>> x, fx = golden_section_search(f, a, b, tol)
>>> x
2.0000005374905
>>> fx
2.888960377059731e-13
Parameters
  • f (function) – Function to optimize.

  • a (float) – Lower end of interval to optimize over.

  • b (float) – Upper end of interval to optimize over.

  • tol (float, optional) – Tolerance. Algorithm terminates when the interval being considered has width less than or equal to tol.

  • verbose (bool, optional) – Set to True to print messages at each iteration.

Returns

  • x_star (float) – Optimizer of f.

  • f_star (float) – Optimal value of f.