0
0
SciPydata~10 mins

Simulated annealing (dual_annealing) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the dual_annealing function from scipy.optimize.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Adual_annealing
Banneal
Cminimize
Dbasinhopping
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'anneal' which is deprecated.
Importing 'minimize' which is for other optimization methods.
Importing 'basinhopping' which is a different algorithm.
2fill in blank
medium

Complete the code to define the objective function that returns the sum of squares of x.

SciPy
def objective(x):
    return [1]
Drag options to blanks, or click blank then click option'
Asum(x)
Bsum(x**2)
Cmax(x)
Dmin(x)
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum(x) which sums elements but not squared.
Using max(x) or min(x) which do not represent sum of squares.
3fill in blank
hard

Fix the error in the bounds definition to correctly specify bounds for two variables between -5 and 5.

SciPy
bounds = [[1], [1]]
Drag options to blanks, or click blank then click option'
A[-5, 5]
B(5, -5)
C(-5, 5)
D[5, -5]
Attempts:
3 left
💡 Hint
Common Mistakes
Using lists instead of tuples for bounds.
Reversing the order of bounds as (5, -5).
4fill in blank
hard

Fill both blanks to run dual_annealing with the objective function and bounds, storing the result in 'result'.

SciPy
result = [1](objective, [2])
Drag options to blanks, or click blank then click option'
Adual_annealing
Bobjective
Cbounds
Dminimize
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the objective function as the second argument.
Using 'minimize' instead of 'dual_annealing'.
5fill in blank
hard

Fill all three blanks to print the minimum value found and the corresponding variables from the result.

SciPy
print('Minimum value:', result.[1])
print('At variables:', result.[2])
print('Number of function evaluations:', result.[3])
Drag options to blanks, or click blank then click option'
Ax
Bfun
Cnfev
Dsuccess
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'x' and 'fun' attributes.
Using 'success' which is a boolean, not a value.