QDpy
Loading...
Searching...
No Matches
mome.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2
4
5"""Use a separate Pareto front in each descriptor cell."""
6
7from qdpy.algorithms import MOME
8from qdpy.containers import ParetoGrid
9from qdpy.simple import run
10
11
12def evaluate(candidate):
13 """Return two conflicting costs and one descriptor."""
14 x, descriptor = candidate
15 return (x ** 2, (1 - x) ** 2), (descriptor,)
16
17
18if __name__ == "__main__":
19 unit = (0.0, 1.0)
20 grid = ParetoGrid(
21 shape=4, max_items_per_bin=5, fitness_domain=(unit, unit),
22 features_domain=(unit,), fitness_weights=(-1.0, -1.0),
23 )
24 search = MOME(grid, budget=24, dimension=2, batch_size=4)
25 result = run(search, evaluate, seed=42)
26
27 cell = max(grid.solutions, key=lambda index: len(grid.front(index)))
28 reference = (1.0, 1.0)
29 tradeoffs = sorted(tuple(round(float(cost), 4) for cost in ind.fitness.values)
30 for ind in grid.front(cell))
31 print(f"Evaluations: {result.evaluations}")
32 print(f"Occupied cells: {grid.filled_bins}/{len(grid.solutions)}")
33 print(f"Raw cost pairs in cell {cell}: {tradeoffs}")
34 print(f"Cell hypervolume: {grid.cell_hypervolume(cell, reference):.4f}")
35 print(f"QD hypervolume: {grid.qd_hypervolume(reference):.4f}")
36 print(f"Global hypervolume: {grid.global_hypervolume(reference):.4f}")