From d1ef70da1671284c1f8f3472dbcb8608510e59e6 Mon Sep 17 00:00:00 2001 From: Luca Cappelletti Date: Mon, 18 May 2020 22:10:43 +0200 Subject: [PATCH] [Tune] Added default values for utility kwargs (#8488) --- python/ray/tune/suggest/bayesopt.py | 18 ++++++++++++++---- python/ray/tune/tests/test_tune_restore.py | 6 +----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/python/ray/tune/suggest/bayesopt.py b/python/ray/tune/suggest/bayesopt.py index 2d3936ac0..1e743f653 100644 --- a/python/ray/tune/suggest/bayesopt.py +++ b/python/ray/tune/suggest/bayesopt.py @@ -32,8 +32,11 @@ class BayesOptSearch(Searcher): metric (str): The training result objective value attribute. mode (str): One of {min, max}. Determines whether objective is minimizing or maximizing the metric attribute. - utility_kwargs (dict): Parameters to define the utility function. Must - provide values for the keys `kind`, `kappa`, and `xi`. + utility_kwargs (dict): Parameters to define the utility function. + The default value is a dictionary with three keys: + - kind: ucb (Upper Confidence Bound) + - kappa: 2.576 + - xi: 0.0 random_state (int): Used to initialize BayesOpt. verbose (int): Sets verbosity level for BayesOpt packages. max_concurrent: Deprecated. @@ -66,8 +69,6 @@ class BayesOptSearch(Searcher): assert byo is not None, ( "BayesOpt must be installed!. You can install BayesOpt with" " the command: `pip install bayesian-optimization`.") - assert utility_kwargs is not None, ( - "Must define arguments for the utility function!") assert mode in ["min", "max"], "`mode` must be 'min' or 'max'!" self.max_concurrent = max_concurrent super(BayesOptSearch, self).__init__( @@ -76,6 +77,15 @@ class BayesOptSearch(Searcher): max_concurrent=max_concurrent, use_early_stopped_trials=use_early_stopped_trials) + if utility_kwargs is None: + # The defaults arguments are the same + # as in the package BayesianOptimization + utility_kwargs = dict( + kind="ucb", + kappa=2.576, + xi=0.0, + ) + if mode == "max": self._metric_op = 1. elif mode == "min": diff --git a/python/ray/tune/tests/test_tune_restore.py b/python/ray/tune/tests/test_tune_restore.py index ede7a0d38..ae0413a99 100644 --- a/python/ray/tune/tests/test_tune_restore.py +++ b/python/ray/tune/tests/test_tune_restore.py @@ -212,11 +212,7 @@ class BayesoptWarmStartTest(AbstractWarmStartTest, unittest.TestCase): space, metric="loss", mode="min", - utility_kwargs={ - "kind": "ucb", - "kappa": 2.5, - "xi": 0.0 - }) + ) return search_alg, cost