MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / visualize_es

Function visualize_es

rl3v2/visualize_hill_climbing.py:35–56  ·  view source on GitHub ↗
(history, bounds, f, resolution=100)

Source from the content-addressed store, hash-verified

33
34# Visualization function
35def visualize_es(history, bounds, f, resolution=100):
36 x = np.linspace(bounds[0], bounds[1], resolution)
37 y = np.linspace(bounds[0], bounds[1], resolution)
38 X, Y = np.meshgrid(x, y)
39 Z = f(X, Y)
40
41 plt.figure(figsize=(8, 6))
42 for i, (pop, mu) in enumerate(history):
43 plt.clf()
44 plt.contourf(X, Y, Z, levels=50, cmap='viridis')
45 plt.colorbar(label="f(x, y)")
46 plt.scatter(pop[:, 0], pop[:, 1], c='white', s=20, label='Population')
47 plt.scatter(mu[0], mu[1], c='red', s=80, label='Mean', edgecolors='black')
48 plt.title(f"Hill Climbing - Step {i+1}")
49 plt.xlim(bounds[0], bounds[1])
50 plt.ylim(bounds[0], bounds[1])
51 plt.xlabel('x')
52 plt.ylabel('y')
53 plt.legend()
54 # plt.pause(0.1)
55 plt.waitforbuttonpress()
56 plt.show()
57
58# Run
59bounds = (-5, 5)

Callers 1

Calls 1

fFunction · 0.70

Tested by

no test coverage detected