5"""Compare learned discounts and cell thresholds on shared CVT geometry."""
9from scipy.stats
import qmc
17DESCRIPTOR_DIMENSION = 6
20def evaluate(candidate):
21 """Use normalised Rastrigin and the first six genome coordinates."""
22 return rastrigin_normalised(candidate), tuple(candidate[:DESCRIPTOR_DIMENSION])
25def run_search(algorithm, centroids):
26 """Build a fresh reporting archive and run a seeded search."""
28 shape=len(centroids), centroids=centroids, fitness_domain=(UNIT,),
29 features_domain=(UNIT,) * DESCRIPTOR_DIMENSION,
32 archive, budget=24, x0=[0.5] * 8, sigma0=0.15, batch_size=4,
33 threshold_min=-1.0, learning_rate=0.1, ind_domain=UNIT,
35 result = run(search, evaluate, seed=42)
36 print(f
"{algorithm.__name__}: {result.evaluations} evaluations, "
37 f
"{archive.filled_bins}/{len(archive.solutions)} cells, "
38 f
"QD score {archive.qd_score():.4f}, best raw fitness {result.best.fitness.values[0]:.4f}")
42if __name__ ==
"__main__":
43 parser = argparse.ArgumentParser(description=__doc__)
44 parser.add_argument(
"--compare-cma-mae", action=
"store_true", help=
"Run CMA-MAE on the same CVT centroids.")
45 args = parser.parse_args()
47 centroids = qmc.Sobol(DESCRIPTOR_DIMENSION, scramble=
True, seed=42).random_base2(5)
48 search = run_search(DiscountModelSearch, centroids)
50 probes = [centroids[0], 0.95 * centroids[0] + 0.05 * centroids[1]]
51 cells = [int(search.container.index_grid(point)[0])
for point
in probes]
52 print(f
"Predicted discounts at points in cells {cells}: {search.predict_discount(probes).round(4)}")
53 if args.compare_cma_mae:
54 run_search(CMAMAE, centroids)