Skip to content

Commit 16dc030

Browse files
added support for NORMAL and LOG_NORMAL in hyperopt suggestion service
Signed-off-by: Shashank Mittal <[email protected]>
1 parent 08b01ac commit 16dc030

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

pkg/suggestion/v1beta1/hyperopt/base_service.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,36 @@ def create_hyperopt_domain(self):
9292
hyperopt_search_space[param.name] = hyperopt.hp.loguniform(
9393
param.name, float(param.min), float(param.max)
9494
)
95-
# else:
96-
# hyperopt_search_space[param.name] = hyperopt.hp.uniform(
97-
# param.name, float(param.min), float(param.max)
98-
# )
95+
elif param.distribution == api_pb2.NORMAL:
96+
sigma = 1
97+
if param.step:
98+
hyperopt_search_space[param.name] = hyperopt.hp.qnormal(
99+
param.name,
100+
float((float(param.min) + float(param.max)) / 2),
101+
float(sigma),
102+
float(param.step),
103+
)
104+
else:
105+
hyperopt_search_space[param.name] = hyperopt.hp.normal(
106+
param.name,
107+
float((float(param.min) + float(param.max)) / 2),
108+
float(sigma),
109+
)
110+
elif param.distribution == api_pb2.LOG_NORMAL:
111+
sigma = 1
112+
if param.step:
113+
hyperopt_search_space[param.name] = hyperopt.hp.qlognormal(
114+
param.name,
115+
float((float(param.min) + float(param.max)) / 2),
116+
float(sigma),
117+
float(param.step),
118+
)
119+
else:
120+
hyperopt_search_space[param.name] = hyperopt.hp.lognormal(
121+
param.name,
122+
float((float(param.min) + float(param.max)) / 2),
123+
float(sigma),
124+
)
99125
elif param.type == CATEGORICAL or param.type == DISCRETE:
100126
hyperopt_search_space[param.name] = hyperopt.hp.choice(
101127
param.name, param.list

pkg/suggestion/v1beta1/internal/search_space.py

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def convert(experiment):
4343
search_space.goal = constant.MIN_GOAL
4444
for p in experiment.spec.parameter_specs.parameters:
4545
search_space.params.append(HyperParameterSearchSpace.convert_parameter(p))
46-
print(search_space)
4746
return search_space
4847

4948
@staticmethod

test/unit/v1beta1/suggestion/test_hyperopt_service.py

+12
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ def test_get_suggestion(self):
201201
parameter_type=api_pb2.DOUBLE,
202202
feasible_space=api_pb2.FeasibleSpace(
203203
max="10", min="5", list=[], distribution=api_pb2.UNIFORM)
204+
),
205+
api_pb2.ParameterSpec(
206+
name="param-9",
207+
parameter_type=api_pb2.DOUBLE,
208+
feasible_space=api_pb2.FeasibleSpace(
209+
max="10", min="5", list=[], step="0.8", distribution=api_pb2.NORMAL)
210+
),
211+
api_pb2.ParameterSpec(
212+
name="param-10",
213+
parameter_type=api_pb2.DOUBLE,
214+
feasible_space=api_pb2.FeasibleSpace(
215+
max="10", min="5", list=[], step="0.8", distribution=api_pb2.LOG_NORMAL)
204216
)
205217
]
206218
)

0 commit comments

Comments
 (0)