Challenge - 5 Problems
Simulated Annealing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of dual_annealing on a simple quadratic function
What is the output of the following code snippet using
scipy.optimize.dual_annealing on a quadratic function?SciPy
from scipy.optimize import dual_annealing def func(x): return (x[0] - 3)**2 + (x[1] + 1)**2 bounds = [(-5, 5), (-5, 5)] result = dual_annealing(func, bounds) print((round(result.x[0], 1), round(result.x[1], 1)))
Attempts:
2 left
💡 Hint
The function has its minimum where both squared terms are zero.
✗ Incorrect
The function is minimized when x[0] = 3 and x[1] = -1, so the optimizer should find values close to these.
❓ data_output
intermediate2:00remaining
Number of iterations in dual_annealing result
After running
dual_annealing on a function, what is the value of result.nit representing the number of iterations?SciPy
from scipy.optimize import dual_annealing import numpy as np def func(x): return np.sin(x[0]) + np.cos(x[1]) bounds = [(0, 10), (0, 10)] result = dual_annealing(func, bounds) print(result.nit)
Attempts:
2 left
💡 Hint
Check the documentation for
result.nit attribute.✗ Incorrect
result.nit is the number of iterations the algorithm ran before stopping, always an integer >= 0.🔧 Debug
advanced2:00remaining
Identify the error in dual_annealing usage
What error will this code raise when running
dual_annealing with incorrect bounds?SciPy
from scipy.optimize import dual_annealing def func(x): return x[0]**2 bounds = [(0, 5), (1, 0)] # Note the second bound is reversed result = dual_annealing(func, bounds)
Attempts:
2 left
💡 Hint
Bounds must be specified with lower bound less than upper bound.
✗ Incorrect
The second bound (1, 0) is invalid because the lower bound is greater than the upper bound, causing a ValueError.
🧠 Conceptual
advanced2:00remaining
Why use dual_annealing over other optimizers?
Which reason best explains why
dual_annealing is chosen for optimization problems?Attempts:
2 left
💡 Hint
Think about how simulated annealing helps avoid local traps.
✗ Incorrect
dual_annealing uses a combination of stochastic sampling and local search to escape local minima and find better solutions.🚀 Application
expert3:00remaining
Interpreting dual_annealing output for a noisy function
Given this noisy function and dual_annealing output, what is the best interpretation of the result's
fun value?SciPy
from scipy.optimize import dual_annealing import numpy as np def noisy_func(x): noise = np.random.normal(0, 0.1) return (x[0] - 2)**2 + noise bounds = [(0, 4)] result = dual_annealing(noisy_func, bounds) print(round(result.fun, 2))
Attempts:
2 left
💡 Hint
Consider how noise affects function evaluations during optimization.
✗ Incorrect
Because the function includes random noise, the
fun value is an approximation and may vary slightly each run.