Challenge - 5 Problems
Basin-Hopping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of basin-hopping on a simple function
What is the output of the following code that uses basin-hopping to find the minimum of a quadratic function?
SciPy
import numpy as np from scipy.optimize import basinhopping def func(x): return (x[0] - 3)**2 + (x[1] + 1)**2 initial_guess = [0, 0] result = basinhopping(func, initial_guess, niter=10) print(result.x.round(2))
Attempts:
2 left
💡 Hint
Think about where the quadratic function reaches its lowest value.
✗ Incorrect
The function has a minimum at x=3 and y=-1. Basin-hopping finds this global minimum starting from [0,0].
❓ data_output
intermediate1:30remaining
Number of iterations performed
After running basin-hopping with niter=15 on the function below, how many iterations does the result report?
SciPy
import numpy as np from scipy.optimize import basinhopping def func(x): return np.sin(x[0]) + (x[1] - 2)**2 result = basinhopping(func, [0, 0], niter=15) print(result.nit)
Attempts:
2 left
💡 Hint
The nit attribute shows the number of iterations performed.
✗ Incorrect
The niter parameter sets the number of basin-hopping iterations. The result.nit matches this value.
🧠 Conceptual
advanced1:30remaining
Understanding the role of the 'stepsize' parameter
What effect does increasing the 'stepsize' parameter have in the basin-hopping algorithm?
Attempts:
2 left
💡 Hint
Think about how the algorithm explores the search space.
✗ Incorrect
The 'stepsize' controls how far the algorithm jumps randomly to explore new areas, helping to avoid getting stuck.
🔧 Debug
advanced1:30remaining
Identify the error in basin-hopping usage
What error will this code raise when executed?
SciPy
from scipy.optimize import basinhopping def f(x): return x**2 result = basinhopping(f, 5, niter='10')
Attempts:
2 left
💡 Hint
Check the type of the niter parameter.
✗ Incorrect
The niter parameter must be an integer, but a string was passed, causing a TypeError.
🚀 Application
expert2:30remaining
Choosing the best initial guess for basin-hopping
You want to find the global minimum of a function with many local minima. Which initial guess strategy is best to improve basin-hopping results?
Attempts:
2 left
💡 Hint
Think about how to avoid getting stuck in local minima.
✗ Incorrect
Starting from multiple points increases the chance of finding the global minimum in complex landscapes.