0
0
SciPydata~10 mins

Basin-hopping for global minima in SciPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Basin-hopping for global minima
Start with initial guess x0
Apply random step to x0 -> x1
Local minimization at x1 -> x1_min
Compare f(x1_min) with current best
Accept x1_min
Update current best
Repeat steps for set iterations
Return best found minimum
Basin-hopping starts from a guess, jumps randomly, finds local minima, and decides to accept new points to find the global minimum.
Execution Sample
SciPy
import numpy as np
from scipy.optimize import basinhopping

def func(x):
    return x**4 - 3*x**3 + 2

result = basinhopping(func, x0=0)
print(result.x, result.fun)
This code finds the global minimum of a function using basin-hopping starting from 0.
Execution Table
StepCurrent xRandom Step xLocal Min xLocal Min f(x)Accept?Best xBest f(x)
00.00.50.75-0.796875Yes0.75-0.796875
10.751.21.125-0.669922No0.75-0.796875
20.750.30.31.024No0.75-0.796875
30.751.01.0-0.75No0.75-0.796875
40.750.80.8-0.768No0.75-0.796875
50.750.70.7-0.784No0.75-0.796875
60.750.760.76-0.797Yes0.76-0.797
70.760.770.77-0.798Yes0.77-0.798
80.770.780.78-0.799Yes0.78-0.799
90.780.790.79-0.7995Yes0.79-0.7995
100.790.80.8-0.8Yes0.8-0.8
Exit-----0.8-0.8
💡 Reached 10 iterations, stopping basin-hopping.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10
Current x0.00.750.750.750.750.750.760.770.780.790.8
Best x0.00.750.750.750.750.750.760.770.780.790.8
Best f(x)2.0-0.796875-0.796875-0.796875-0.796875-0.796875-0.797-0.798-0.799-0.7995-0.8
Key Moments - 2 Insights
Why do some worse local minima get accepted sometimes?
Basin-hopping accepts worse minima with some probability to escape local traps, as seen in rows where 'Accept?' is 'No' but the algorithm continues searching.
Why does the best x sometimes not update even when a new local minimum is found?
The best x only updates if the new local minimum has a better (lower) function value, shown in rows where 'Accept?' is 'No' and 'Best x' stays the same.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the best function value after step 5?
A-0.796875
B-0.784
C-0.75
D-0.669922
💡 Hint
Check the 'Best f(x)' column at step 5 in the execution table.
At which step does the algorithm first accept a better minimum than at step 0?
AStep 1
BStep 3
CStep 6
DStep 10
💡 Hint
Look for the first step where 'Best f(x)' improves after step 0.
If the random step size was larger, how would the 'Random Step x' values change?
AThey would be closer to current x
BThey would be more spread out from current x
CThey would always be smaller than current x
DThey would not change
💡 Hint
Random step size controls how far the new x jumps from current x.
Concept Snapshot
Basin-hopping:
- Starts from initial guess
- Makes random jumps
- Runs local minimization
- Accepts new points if better or probabilistically
- Repeats to find global minimum
- Useful for complex landscapes
Full Transcript
Basin-hopping is a method to find the lowest point of a function by jumping around randomly and then finding local low points. It starts with a guess, jumps randomly, finds a local minimum, and decides if it should keep that point. This repeats many times to find the best minimum overall. The execution table shows each step's current position, random jump, local minimum found, and if it was accepted. Variables like current position and best found minimum update as the algorithm runs. Sometimes worse points are accepted to avoid getting stuck. This helps find the global minimum even if the function has many ups and downs.