basin_hopping
Builtin index · Signal processing
result = basin_hopping(f, x0, [grad=], [n_iter=100], [step_size=1.0], [temperature=1.0], [seed=])
Input: f, x0, grad, n_iter, step_size, temperature, seed · Output: result
What it is
f: a string naming f(params) as in minimize; x0: a length-P vector; grad (optional string); n_iter (optional number, number of hops); step_size/temperature (optional numbers); seed (optional number, RNG seed).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = basin_hopping(f, x0, [grad=], [n_iter=100], [step_size=1.0], [temperature=1.0], [seed=]) | f stringf: a string naming f(params) as in minimize.x0 vectorx0: a length-P vector.grad string, optionalgrad (optional string).n_iter number, optional (default 100)n_iter (optional number, number of hops).step_size number, optional (default 1.0)step_size/temperature (optional numbers).temperature number, optional (default 1.0)step_size/temperature (optional numbers).seed number, optionalseed (optional number, RNG seed). | Model —kind "minimize", same fields as minimize | Returns a Model (kind "minimize", same fields as minimize). Global optimization: repeats random perturbation + local minimize from there, accepting a worse local minimum with Metropolis probability exp(-(new-old)/temperature) so the search can escape the first local minimum found. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
wavy(p) := -0.5*exp(-(p[0]+2)^2) - 2*exp(-(p[0]-3)^2/2) # shallow local
# min at -2,
# deeper global
# min at 3
stuck = minimize("wavy", [-2]) # stays at the shallow one
found = basin_hopping("wavy", [-2], n_iter=60, step_size=3) # finds the deep one
from numerics-dsp
How it works
basin_hopping(f, x0, [grad=], [n_iter=100], [step_size=1.0], [temperature=1.0], [seed=]) — global optimization: repeats random perturbation + local minimize from there, accepting a worse local minimum with Metropolis probability exp(-(new-old)/temperature) instead of always rejecting it, so the search can escape the first local minimum it finds. grad=, same convention as minimize, is forwarded to every local search in place of the default finite-difference gradient. Model kind "minimize" (same fields as minimize, since it's the same underlying result shape).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.