From 16dc03032fff962fa236dc05827a43f9c6cfe93b Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Sat, 7 Sep 2024 20:07:55 +0530 Subject: [PATCH] added support for NORMAL and LOG_NORMAL in hyperopt suggestion service Signed-off-by: Shashank Mittal --- .../v1beta1/hyperopt/base_service.py | 34 ++++++++++++++++--- .../v1beta1/internal/search_space.py | 1 - .../suggestion/test_hyperopt_service.py | 12 +++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/pkg/suggestion/v1beta1/hyperopt/base_service.py b/pkg/suggestion/v1beta1/hyperopt/base_service.py index 53b632d4219..0d65ecd77e0 100644 --- a/pkg/suggestion/v1beta1/hyperopt/base_service.py +++ b/pkg/suggestion/v1beta1/hyperopt/base_service.py @@ -92,10 +92,36 @@ def create_hyperopt_domain(self): hyperopt_search_space[param.name] = hyperopt.hp.loguniform( param.name, float(param.min), float(param.max) ) - # else: - # hyperopt_search_space[param.name] = hyperopt.hp.uniform( - # param.name, float(param.min), float(param.max) - # ) + elif param.distribution == api_pb2.NORMAL: + sigma = 1 + if param.step: + hyperopt_search_space[param.name] = hyperopt.hp.qnormal( + param.name, + float((float(param.min) + float(param.max)) / 2), + float(sigma), + float(param.step), + ) + else: + hyperopt_search_space[param.name] = hyperopt.hp.normal( + param.name, + float((float(param.min) + float(param.max)) / 2), + float(sigma), + ) + elif param.distribution == api_pb2.LOG_NORMAL: + sigma = 1 + if param.step: + hyperopt_search_space[param.name] = hyperopt.hp.qlognormal( + param.name, + float((float(param.min) + float(param.max)) / 2), + float(sigma), + float(param.step), + ) + else: + hyperopt_search_space[param.name] = hyperopt.hp.lognormal( + param.name, + float((float(param.min) + float(param.max)) / 2), + float(sigma), + ) elif param.type == CATEGORICAL or param.type == DISCRETE: hyperopt_search_space[param.name] = hyperopt.hp.choice( param.name, param.list diff --git a/pkg/suggestion/v1beta1/internal/search_space.py b/pkg/suggestion/v1beta1/internal/search_space.py index 13573ed540d..2a11ba2cb22 100644 --- a/pkg/suggestion/v1beta1/internal/search_space.py +++ b/pkg/suggestion/v1beta1/internal/search_space.py @@ -43,7 +43,6 @@ def convert(experiment): search_space.goal = constant.MIN_GOAL for p in experiment.spec.parameter_specs.parameters: search_space.params.append(HyperParameterSearchSpace.convert_parameter(p)) - print(search_space) return search_space @staticmethod diff --git a/test/unit/v1beta1/suggestion/test_hyperopt_service.py b/test/unit/v1beta1/suggestion/test_hyperopt_service.py index c2d79ca92ac..15fb252fdbd 100644 --- a/test/unit/v1beta1/suggestion/test_hyperopt_service.py +++ b/test/unit/v1beta1/suggestion/test_hyperopt_service.py @@ -201,6 +201,18 @@ def test_get_suggestion(self): parameter_type=api_pb2.DOUBLE, feasible_space=api_pb2.FeasibleSpace( max="10", min="5", list=[], distribution=api_pb2.UNIFORM) + ), + api_pb2.ParameterSpec( + name="param-9", + parameter_type=api_pb2.DOUBLE, + feasible_space=api_pb2.FeasibleSpace( + max="10", min="5", list=[], step="0.8", distribution=api_pb2.NORMAL) + ), + api_pb2.ParameterSpec( + name="param-10", + parameter_type=api_pb2.DOUBLE, + feasible_space=api_pb2.FeasibleSpace( + max="10", min="5", list=[], step="0.8", distribution=api_pb2.LOG_NORMAL) ) ] )