Discount Model Search¶
Search eight decision variables using the first six as descriptors.
qdpy.algorithms.DiscountModelSearch learns a continuous
discount over those descriptors with a CPU PyTorch model. The CMA
emitter ranks candidates by improvement over the predicted discount.
The result archive stores the best measured solution in each CVT cell.
Install the dms extra and run the script from the repository root. To use a CPU-only PyTorch wheel, install it first in the same environment. PyTorch installation instructions
python examples/discount_model_search.py
python examples/discount_model_search.py --compare-cma-mae
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Use a learned discount and a fixed CVT result archive.
"""Compare learned discounts and cell thresholds on shared CVT geometry."""
import argparse
from scipy.stats import qmc
from qdpy.algorithms import CMAMAE, DiscountModelSearch
from qdpy.benchmarks import rastrigin_normalised
from qdpy.containers import CVTGrid
from qdpy.simple import run
UNIT = (0.0, 1.0)
DESCRIPTOR_DIMENSION = 6
def evaluate(candidate):
"""Use normalised Rastrigin and the first six genome coordinates."""
return rastrigin_normalised(candidate), tuple(candidate[:DESCRIPTOR_DIMENSION])
def run_search(algorithm, centroids):
"""Build a fresh reporting archive and run a seeded search."""
archive = CVTGrid(
shape=len(centroids), centroids=centroids, fitness_domain=(UNIT,),
features_domain=(UNIT,) * DESCRIPTOR_DIMENSION,
)
search = algorithm(
archive, budget=24, x0=[0.5] * 8, sigma0=0.15, batch_size=4,
threshold_min=-1.0, learning_rate=0.1, ind_domain=UNIT,
)
result = run(search, evaluate, seed=42)
print(f"{algorithm.__name__}: {result.evaluations} evaluations, "
f"{archive.filled_bins}/{len(archive.solutions)} cells, "
f"QD score {archive.qd_score():.4f}, best raw fitness {result.best.fitness.values[0]:.4f}")
return search
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--compare-cma-mae", action="store_true", help="Run CMA-MAE on the same CVT centroids.")
args = parser.parse_args()
centroids = qmc.Sobol(DESCRIPTOR_DIMENSION, scramble=True, seed=42).random_base2(5)
search = run_search(DiscountModelSearch, centroids)
probes = [centroids[0], 0.95 * centroids[0] + 0.05 * centroids[1]]
cells = [int(search.container.index_grid(point)[0]) for point in probes]
print(f"Predicted discounts at points in cells {cells}: {search.predict_discount(probes).round(4)}")
if args.compare_cma_mae:
run_search(CMAMAE, centroids)
The example uses 32 fixed Sobol points as CVT centroids. Supply
qdpy.containers.CVTGrid one row per cell and one column per
descriptor, in the raw units returned by the evaluator. Omit
centroids to let the archive fit them. The comparison starts
CMA-MAE with a fresh archive on the same centroids and gives each
method 24 attempts. Read coverage and QD score on that shared geometry.
The short budget is for inspecting the interface. See
Differentiable, Bayesian, and high-dimensional QD pilots for results across five seeds.
threshold_min is the target discount at the sampled initial centres.
Use signed quality units, so -1.0 corresponds to raw cost 1.0
for the default minimisation weight. Predictions can fall below this
initial target. Keep signed quality within the model’s float32 training
range. Rescale an objective or its comparison weight if DMS reports an
out-of-range target. DMS freezes its predictions while
ranking a generation, then trains the model using measured descriptors
and sampled empty centres. The example passes two nearby descriptor
vectors to search.predict_discount(points). In the seeded run both
land in cell zero, with predictions around -1.08 and -1.02.
To inspect measured fitness, read the elites stored in
search.container.
See Tjanaka et al. (2026) and the authors’ reference code.