From 3724cf4fa4943e6fcbf390af061e90f174f5a2f5 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Mon, 6 Nov 2023 02:53:01 +0100 Subject: [PATCH] Address comments by Alnusjaponica --- multi_objective/quadratic_simple.py | 4 ++-- quadratic_simple_constraint.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/multi_objective/quadratic_simple.py b/multi_objective/quadratic_simple.py index cbf10ff0..877dbf2d 100644 --- a/multi_objective/quadratic_simple.py +++ b/multi_objective/quadratic_simple.py @@ -2,8 +2,8 @@ Optuna example that optimizes simple quadratic functions. In this example, we optimize two objective values. -Unlike a single-objective optimization, an optimization gives the trade-off between two objectives. -As a result, we get best trade-offs between two objectives, a.k.a Pareto solutions. +Unlike single-objective optimization, an optimization gives a trade-off between two objectives. +As a result, we get the best trade-offs between two objectives, a.k.a Pareto solutions. """ diff --git a/quadratic_simple_constraint.py b/quadratic_simple_constraint.py index bae11d0a..c18c768a 100644 --- a/quadratic_simple_constraint.py +++ b/quadratic_simple_constraint.py @@ -46,17 +46,17 @@ def constraints(trial): print("Number of finished trials: ", len(study.trials)) - feasible_trial_ids = [ + feasible_trial_numbers = [ trial.number for trial in study.trials if all(c <= 0.0 for c in trial.system_attrs["constraints"]) ] - if len(feasible_trial_ids) == 0: + if len(feasible_trial_numbers) == 0: print("No trials satisfied all the constraints.") else: - best_trial_id = sorted(feasible_trial_ids, key=lambda i: study.trials[i].value)[0] - best_trial = study.trials[best_trial_id] - print(f"Best trial was found at Trial#{best_trial_id}") + best_trial_number = sorted(feasible_trial_numbers, key=lambda i: study.trials[i].value)[0] + best_trial = study.trials[best_trial_number] + print(f"Best trial was found at Trial#{best_trial_number}") print(f" Params: {best_trial.params}") print(f" Value: {best_trial.value}") c1, c2 = best_trial.system_attrs["constraints"]