QDpy
Loading...
Searching...
No Matches
simple_search.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2
4
5"""Run a seeded search on normalised Rastrigin."""
6
7import argparse
8
9from qdpy.benchmarks import illumination_rastrigin_normalised
10from qdpy.simple import map_elites, nslc, run
11
12
13
14def main():
15 """Run either search with the same evaluator and seed."""
16 parser = argparse.ArgumentParser(description=__doc__)
17 parser.add_argument("algorithm", choices=("map-elites", "nslc"))
18 parser.add_argument("--output-dir", help="Directory for the run manifest")
19 args = parser.parse_args()
20
21 settings = dict(
22 dimension=3, budget=24, batch_size=6,
23 fitness_domain=((0, 1),), features_domain=((0, 1), (0, 1)),
24 )
25 if args.algorithm == "map-elites":
26 search = map_elites(shape=(4, 4), **settings)
27 else:
28 search = nslc(k=3, threshold_novelty=0.15, **settings)
29 result = run(
30 search, illumination_rastrigin_normalised, seed=42,
31 batch_mode=args.algorithm == "map-elites", output_dir=args.output_dir,
32 )
33 print("Evaluations", result.evaluations)
34 print("Retained candidates", len(result.archive))
35 print("Best fitness", result.best.fitness.values[0])
36 if result.manifest_path is not None:
37 print("Run manifest", result.manifest_path)
38
39
40if __name__ == "__main__":
41 main()