Question: Download the file eggholder.py. This file contains a single function eggholder which takes in an x and y value, and returns a single value. A


Download the file eggholder.py. This file contains a single function eggholder which takes in an x and y value, and returns a single value. A visualization of the function is shown here: Eggholder function 750 500 250 0 -250 -500 -750 z N -400 -200 0 400 200 0 -200 Y -400 200 400 The goal here is to use fmin to see how well it can optimize this function. Put all of your code inside the same file eggholder.py. Write a function minimize_eggholder (guess, max_calls=100) which takes in an (x,y) guess as guess, and then uses the fmin function from scipy to attempt to minimize the function. It should set maxfun equal to max_calls to limit the number of function evaluations. It should return two values: The (x,y) coordinate which minimizes the function, followed by the actual value at the minimum. . On the interval [-512,512] x [-512,512], the global minimum of the function is at (512, 404.2319). Write some code which randomly generates 1000 points in the range [-512,512] x [-512,512) and runs minimize_eggholder with those points as an initial guess. It should then plot a histogram of the absolute difference between the minimum obtained python 3 Lab 7 Numpy Applications Due: March 2nd, 2022 from minimize_eggholder versus the true global minimum. Set bins=25. Label your axes and include your plot in your submission import numpy as np def eggholder(x, y): Takes in either a scalar x and y, or a 1-D numpy array for both x and y. if (isinstance(x, np.ndarray) and not isinstance(y, np.ndarray)) or ( isinstance(y, np.ndarray) and not isinstance(x, np.ndarray)): pass result = -(y + 47) * np.sin(np.sqrt(np.abs(x / 2 + (y + 47)))) - X * np.sin(np. sqrt(np.abs(x - (y + 47)))) if isinstance(x, np.ndarray): outside = (np.abs(x) > 512) | (np.abs(y) > 512) result[outside] = 2000 return result else: return 2000 if (abs(x) > 512 or abs(y) > 512) else result
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
