5"""Write a spherical archive figure from a fixed set of unit directions."""
8from pathlib
import Path
10import matplotlib.pyplot
as plt
19 """Use 64 Fibonacci directions as the stored CVT geometry."""
21 z = 1 - (2 * steps + 1) / len(steps)
22 phi = np.pi * (3 - np.sqrt(5)) * steps
23 radius = np.sqrt(1 - z ** 2)
24 directions = np.column_stack((radius * np.cos(phi), radius * np.sin(phi), z))
25 archive = CVTGrid(shape=len(directions), centroids=directions,
26 features_domain=((-1, 1),) * 3, fitness_domain=((0, 1),))
27 for cell, direction
in enumerate(directions):
29 value = (1 + direction @ np.array([0.4, 0.5, 0.7])) / 2
30 archive.add(Individual([cell], fitness=Fitness((value,)), features=Features(direction)))
34if __name__ ==
"__main__":
35 parser = argparse.ArgumentParser(description=__doc__)
36 parser.add_argument(
"output", type=Path)
37 args = parser.parse_args()
38 axes = plot_archive(example_archive(), view=
"sphere")
39 args.output.parent.mkdir(parents=
True, exist_ok=
True)
40 axes.figure.savefig(args.output, dpi=140)
41 plt.close(axes.figure)