Skip to content

Commit

Permalink
Merge pull request #5422 from not522/fix-normalize-value
Browse files Browse the repository at this point in the history
Fix `_normalize_value` for incomplete trials
  • Loading branch information
nabenabe0928 committed May 7, 2024
2 parents 3d8e199 + 818bd98 commit f290095
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion optuna/study/_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _dominates(

def _normalize_value(value: float | None, direction: StudyDirection) -> float:
if value is None:
value = float("inf")
return float("inf")

if direction is StudyDirection.MAXIMIZE:
value = -value
Expand Down
8 changes: 8 additions & 0 deletions tests/study_tests/test_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from optuna.study import StudyDirection
from optuna.study._multi_objective import _dominates
from optuna.study._multi_objective import _fast_non_domination_rank
from optuna.study._multi_objective import _normalize_value
from optuna.trial import create_trial
from optuna.trial import TrialState

Expand Down Expand Up @@ -161,3 +162,10 @@ def test_fast_non_domination_rank_invalid() -> None:
_fast_non_domination_rank(
np.array([[1.0, 2.0], [3.0, 4.0]]), penalty=np.array([1.0, 2.0, 3.0])
)


def test_normalize_value() -> None:
assert _normalize_value(1.0, StudyDirection.MINIMIZE) == 1.0
assert _normalize_value(1.0, StudyDirection.MAXIMIZE) == -1.0
assert _normalize_value(None, StudyDirection.MINIMIZE) == float("inf")
assert _normalize_value(None, StudyDirection.MAXIMIZE) == float("inf")

0 comments on commit f290095

Please sign in to comment.