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

Function visualize_es

rl3v2/visualize_es.py:33–54  ·  view source on GitHub ↗
(history, bounds, f, resolution=100)

Source from the content-addressed store, hash-verified

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

Callers 1

visualize_es.pyFile · 0.70

Calls 1

fFunction · 0.70

Tested by

no test coverage detected