1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Optimization in Python

Connected

Exercise

Using callback

You want to find the two highest maxima of a profit function and you have decided to use callback to collect the optima found and then select the top two values.

First, you will complete the callback function. You will check if the value of the objective currently examined by basinhopping is accepted as optimum, and if so, you will append it to a list opt_values. Afterwards you will run basinhopping with the callback function you just defined.

basinhopping has been imported for you. The initial guess, x0, kwargs, and profit, function have already been defined for you.

Instructions

100 XP
  • Fill in the callback function to check if the x candidate examined in the current iteration is indeed deemed an optimum.
  • Append the value of the minimized objective to list opt_values.
  • Run basinhopping with the appropriate callback function and find the top two maxima.