Skip to content

Commit

Permalink
Always winsorize when no objective thresholds are specified (facebook…
Browse files Browse the repository at this point in the history
…#1614)

Summary:
Pull Request resolved: facebook#1614

Winsorize a `MultiObjective` when the objective thresholds aren't specified.

Reviewed By: saitcakmak

Differential Revision: D45581780

fbshipit-source-id: 257a308cd23e396b9616ebb6c08130847f5f1092
  • Loading branch information
David Eriksson authored and facebook-github-bot committed May 9, 2023
1 parent 8afb2e9 commit 874cdcb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
16 changes: 8 additions & 8 deletions ax/modelbridge/tests/test_winsorize_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def test_winsorization_with_optimization_config(self) -> None:
f"manually if you want to winsorize metric m{['1', '3'][i]}."
in [str(w.message) for w in ws]
)
# Multi-objective without objective thresholds (should print a warning)
# Multi-objective without objective thresholds should warn and winsorize
moo_objective = MultiObjective(
[Objective(m1, minimize=False), Objective(m2, minimize=True)]
)
Expand All @@ -507,15 +507,15 @@ def test_winsorization_with_optimization_config(self) -> None:
observation_data=deepcopy(all_obsd),
optimization_config=optimization_config,
)
for i in range(2):
for _ in range(2):
self.assertTrue(
"Automatic winsorization isn't supported for an objective in "
"`MultiObjective` without objective thresholds. Specify the "
"winsorization settings manually if you want to winsorize "
f"metric m{i + 1}." in [str(w.message) for w in ws]
"Encountered a `MultiObjective` without objective thresholds. We "
"will winsorize each objective separately. We strongly recommend "
"specifying the objective thresholds when using multi-objective "
"optimization." in [str(w.message) for w in ws]
)
self.assertEqual(transform.cutoffs["m1"], (-float("inf"), float("inf")))
self.assertEqual(transform.cutoffs["m2"], (-float("inf"), float("inf")))
self.assertEqual(transform.cutoffs["m1"], (-6.5, float("inf")))
self.assertEqual(transform.cutoffs["m2"], (-float("inf"), 10.0))
self.assertEqual(transform.cutoffs["m3"], (-float("inf"), float("inf")))
# Add relative objective thresholds (should raise an error)
objective_thresholds = [
Expand Down
24 changes: 17 additions & 7 deletions ax/modelbridge/transforms/winsorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, Union

import numpy as np
from ax.core.objective import ScalarizedObjective
from ax.core.objective import MultiObjective, ScalarizedObjective
from ax.core.observation import Observation, ObservationData
from ax.core.optimization_config import (
MultiObjectiveOptimizationConfig,
Expand Down Expand Up @@ -272,12 +272,22 @@ def _get_auto_winsorization_cutoffs_multi_objective(
metric_values=metric_values,
outcome_constraints=objective_threshold,
)
warnings.warn(
"Automatic winsorization isn't supported for an objective in `MultiObjective` "
"without objective thresholds. Specify the winsorization settings manually if "
f"you want to winsorize metric {metric_name}."
)
return DEFAULT_CUTOFFS # Don't winsorize if there is no threshold
else:
warnings.warn(
"Encountered a `MultiObjective` without objective thresholds. We will "
"winsorize each objective separately. We strongly recommend specifying "
"the objective thresholds when using multi-objective optimization."
)
objectives = checked_cast(MultiObjective, optimization_config.objective)
minimize = [
objective.minimize
for objective in objectives.objectives
if objective.metric.name == metric_name
][0]
return _get_auto_winsorization_cutoffs_single_objective(
metric_values=metric_values,
minimize=minimize,
)


def _obtain_cutoffs_from_outcome_constraints(
Expand Down

0 comments on commit 874cdcb

Please sign in to comment.