Skip to Content

BASIN_HOPPING

Overview

The BASIN_HOPPING function provides a robust global optimization method for single-variable functions using the basinhopping algorithm from SciPy. Basinhopping is a stochastic global optimization technique that combines random perturbations with local minimization to escape local minima and search for the global minimum of a scalar function. It is especially useful for non-convex optimization problems where the objective function may have multiple local minima or complex landscapes.

The basinhopping algorithm seeks to solve

minxf(x)\min_x f(x)

where f(x)f(x) is the objective function. At each iteration, the algorithm performs a random displacement:

xtrial=xcurrent+δx_{\text{trial}} = x_{\text{current}} + \delta

where δ\delta is a random vector (with user-defined step size). A local minimization is then performed starting from xtrialx_{\text{trial}} to find:

xmin=argminxf(x)x_{\text{min}} = \operatorname{argmin}_x f(x)

The new minimum is accepted with probability

P={1if Δf0exp(Δf/T)if Δf>0P = \begin{cases} 1 & \text{if } \Delta f \leq 0 \\ \exp(-\Delta f / T) & \text{if } \Delta f > 0 \end{cases}

where Δf=f(xmin)f(xcurrent)\Delta f = f(x_{\text{min}}) - f(x_{\text{current}}) and TT is the temperature parameter. This approach allows the algorithm to escape local minima by occasionally accepting worse solutions, similar to simulated annealing, and increases the chance of finding the global minimum.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=BASIN_HOPPING(func_expr, x_zero, [niter], [T], [stepsize], [minimizer_method])
  • func_expr (string, required): Math expression as a string which accepts a single scalar argument and returns a scalar value. Example: "x**2 + 10*sin(x)"
  • x_zero (float, required): Initial guess for the variable. Example: 0
  • niter (int, optional): Number of basinhopping iterations. Example: 200
  • T (float, optional): Temperature parameter for the acceptance test. Example: 1.0
  • stepsize (float, optional): Step size for random displacement. Example: 0.5
  • minimizer_method (string, optional): Local minimization method to use (e.g., "L-BFGS-B", "BFGS", "Powell"). Example: "L-BFGS-B"

The function returns a 2D list: [[minimum, x_min]], where the first value is the minimum found and the second value is the location of the minimum.

Examples

Example 1: Global Minimum of a Sine-Modified Quadratic

In Excel:

=BASIN_HOPPING("x**2 + 10*sin(x)", 0, 200, 1.0, 0.5, "L-BFGS-B")

Expected output:

Minimum Valuex_min
-7.945-1.306

This means the minimum value is approximately -7.945 at x1.306x \approx -1.306.

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on