Add _compute_3d for hypervolume computation#6112
Add _compute_3d for hypervolume computation#6112HideakiImamura merged 3 commits intooptuna:masterfrom
_compute_3d for hypervolume computation#6112Conversation
_compute_3d for hypervolume computation
|
Thank you for your PR! I confirmed this PR makes the following scripts faster. import optuna
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_int("y", -100, 100)
return x**2 + y**2, (x - 2) ** 2 + (y - 2) ** 2, (x + 2) ** 2 + (y + 2) ** 2
sampler = optuna.samplers.TPESampler(seed=42)
study = optuna.create_study(sampler=sampler, directions=["minimize"]*3)
study.optimize(objective, n_trials=1000)import optuna
def objective(trial):
x = trial.suggest_float("x", 0, 1)
y = trial.suggest_float("y", 0, 1)
z = trial.suggest_float("z", 0, 1)
trial.set_user_attr("constraints", [x ** 2 + y ** 2 + z ** 2 - 1])
return x, y, z
def constraints_func(trial):
return trial.user_attrs["constraints"]
sampler = optuna.samplers.NSGAIISampler(seed=42, constraints_func=constraints_func)
study = optuna.create_study(directions=["maximize", "maximize", "maximize"], sampler=sampler)
study.optimize(objective, n_trials=10000)
reference_point=[0, 0, 0]
optuna.visualization.plot_hypervolume_history(study, reference_point) |
|
Could you check the following points?
|
|
Precomputation (
Thus I think we may keep the precomputation. |
|
Note
|
|
I completely misunderstood. I didn't run
import optuna
import time
optuna.logging.set_verbosity(optuna.logging.WARNING)
def test_pr6112():
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_int("y", -100, 100)
return x**2 + y**2, (x - 2) ** 2 + (y - 2) ** 2, (x + 2) ** 2 + (y + 2) ** 2
sampler = optuna.samplers.TPESampler(seed=42)
study = optuna.create_study(sampler=sampler, directions=["minimize"]*3)
start = time.time()
study.optimize(objective, n_trials=1000)
end = time.time()
print(f"Time taken: {end - start} seconds for optimization without constraints")
def test_pr6112_with_constraints():
def objective(trial):
x = trial.suggest_float("x", 0, 1)
y = trial.suggest_float("y", 0, 1)
z = trial.suggest_float("z", 0, 1)
trial.set_user_attr("constraints", [x ** 2 + y ** 2 + z ** 2 - 1])
return x, y, z
def constraints_func(trial):
return trial.user_attrs["constraints"]
sampler = optuna.samplers.NSGAIISampler(seed=42, constraints_func=constraints_func)
study = optuna.create_study(directions=["maximize", "maximize", "maximize"], sampler=sampler)
start = time.time()
study.optimize(objective, n_trials=10000)
end = time.time()
print(f"Time taken: {end - start} seconds for optimization with constraints")
reference_point=[0, 0, 0]
start = time.time()
fig = optuna.visualization.plot_hypervolume_history(study, reference_point)
end = time.time()
print(f"Time taken for hypervolume plot: {end - start} seconds")
fig.write_image("/path/to/hypervolume_plot.png")
if __name__ == "__main__":
test_pr6112()
test_pr6112_with_constraints()
|
Motivation
_compute_hvhas room of improvement on 3D points.Description of the changes
I implemented a dedicated function for 3D points (
_compute_3d)