Generation

generate functionThu, 20 Apr 2023

When seed=42 is fixed, try experimenting with the differential_evolution algorithm parameters: strategy, popsize, mutation. import numpy as np from scipy.optimize import differential_evolution import matplotlib.pyplot as plt %matplotlib inline def ackley(x): arg1 = -0.2 * np.sqrt(0.5 * (x[0] ** 2 + x[1] ** 2)) arg2 = 0.5 * (np.cos(2. * np.pi * x[0]) + np.cos(2. * np.pi * x[1])) return -20. * np.exp(arg1) - np.exp(arg2) + 20. + np.e bounds = [(-10, 10), (-10, 10)] result = differential_evolution(ackley, bounds, seed=42) ###YOUR CODE HERE

artificial parameters def ackley(x): arg1 = -0.2 * np.sqrt(0.5 * (x[0] ** 2 + x[1] ** 2)) arg2 = 0.5 * (np.cos(2. * np.pi * x[0]) + np.cos(2. * np.pi * x[1])) return -20. * np.exp(arg1) - np.exp(arg2) + 20. + np.e bounds = [(-10, 10), (-10, 10)] def plot_optimisation(strategy): result = differential_evolution(ackley, bounds, strategy=strategy, seed=42) x = np.linspace(-10, 10, 100) y = np.linspace(-10, 10, 100) X, Y = np.meshgrid(x, y) Z = np.array([ackley([x, y]) for x, y in zip(np.ravel(X), np.ravel(Y))

Questions about programming?Chat with your personal AI assistant