Skip to content

Instantly share code, notes, and snippets.

@nabenabe0928
Last active August 7, 2024 02:38
Show Gist options
  • Save nabenabe0928/4a4eb4807dd8ca18eb2ca5dc431edf79 to your computer and use it in GitHub Desktop.
Save nabenabe0928/4a4eb4807dd8ca18eb2ca5dc431edf79 to your computer and use it in GitHub Desktop.
Speed up benchmarking of `optuna.samplers.TPESampler` in multi-objective setups
"""
The article for this experiment is available in:
https://medium.com/optuna/significant-speed-up-of-multi-objective-tpesampler-in-optuna-v4-0-0-2bacdcd1d99b
"""
import numpy as np
import optuna
def objective(trial, n_objectives):
centers = [0.0, 2.0, -2.0, 4.0, -4.0][:n_objectives]
X = np.asarray([trial.suggest_float(f"x{i}", -5, 5) for i in range(2)])
return [np.sum((X - c) ** 2) for c in centers]
seed = 0 # 5 random seeds from 0 to 4 in the experiments.
n_objectives = 3 # 1 to 5 objectives in the experiments.
sampler = optuna.samplers.TPESampler(seed=seed, multivariate=True)
study = optuna.create_study(sampler=sampler, directions=["minimize"]*n_objectives)
study.optimize(lambda trial: objective(
trial, n_objectives), n_trials=10000, timeout=3600
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment