Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ax/metrics/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
lower_is_better: If True, lower curve values are considered better.
smoothing: If > 0, apply exponential weighted mean to the curve. This
is the same postprocessing as the "smoothing" slider in the
Tensorboard UI.
Tensorboard UI. Needs to be smaller than 1.0.
cumulative_best: If True, for each trial, apply cumulative best to
the curve (i.e., if lower is better, then we return a curve
representing the cumulative min of the raw curve).
Expand All @@ -68,6 +68,10 @@ def __init__(
"""
super().__init__(name=name, lower_is_better=lower_is_better)

if not (0 <= smoothing < 1):
raise ValueError(
f"smoothing must be in the range [0, 1), got {smoothing}."
)
self.smoothing = smoothing
self.tag = tag
self.cumulative_best = cumulative_best
Expand Down
13 changes: 13 additions & 0 deletions ax/metrics/tests/test_tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ def test_smoothing(self) -> None:

self.assertTrue(df.equals(expected_df))

# Test that smoothing must be in the range [0, 1).
# Valid smoothing values
for smoothing in [0, 0.5, 0.99]:
with self.subTest(f"smoothing={smoothing}"):
TensorboardMetric(name="loss", tag="loss", smoothing=smoothing)

# Invalid smoothing values
expected_str = r"smoothing must be in the range \[0, 1\)"
for smoothing in [1, 1.5, -0.1]:
with self.subTest(f"smoothing={smoothing}"):
with self.assertRaisesRegex(ValueError, expected_str):
TensorboardMetric(name="loss", tag="loss", smoothing=smoothing)

def test_cumulative_best(self) -> None:
fake_data = [4.0, 8.0, 2.0, 1.0]
cummin_data = pd.Series(fake_data).cummin().tolist()
Expand Down