Skip to content

Commit 0e17302

Browse files
authored
Fix Range for Int and Double values in Grid (#1732)
1 parent cffab07 commit 0e17302

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pkg/suggestion/v1beta1/chocolate/base_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ def create_optimizer(self, algorithm_name):
6161

6262
for param in self.search_space.params:
6363
key = BaseChocolateService.encode(param.name)
64+
# Chocolate quantized_uniform distribution uses half-open interval: [low, high).
6465
if param.type == INTEGER:
6566
chocolate_search_space[key] = choco.quantized_uniform(
66-
int(param.min), int(param.max), int(param.step))
67+
int(param.min), int(param.max) + int(param.step), int(param.step))
6768
elif param.type == DOUBLE:
6869
chocolate_search_space[key] = choco.quantized_uniform(
69-
float(param.min), float(param.max), float(param.step))
70+
float(param.min), float(param.max) + float(param.step), float(param.step))
7071
# For Categorical and Discrete insert indexes to DB from list of values
7172
elif param.type == CATEGORICAL or param.type == DISCRETE:
7273
chocolate_search_space[key] = choco.choice(

pkg/suggestion/v1beta1/internal/search_space.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
import logging
16-
from pkg.apis.manager.v1beta1.python import api_pb2 as api
1716

18-
from pkg.suggestion.v1beta1.internal.constant import *
17+
from pkg.apis.manager.v1beta1.python import api_pb2 as api
18+
import pkg.suggestion.v1beta1.internal.constant as constant
1919

2020

2121
logging.basicConfig(level=logging.DEBUG)
@@ -31,9 +31,9 @@ def __init__(self):
3131
def convert(experiment):
3232
search_space = HyperParameterSearchSpace()
3333
if experiment.spec.objective.type == api.MAXIMIZE:
34-
search_space.goal = MAX_GOAL
34+
search_space.goal = constant.MAX_GOAL
3535
elif experiment.spec.objective.type == api.MINIMIZE:
36-
search_space.goal = MIN_GOAL
36+
search_space.goal = constant.MIN_GOAL
3737
for p in experiment.spec.parameter_specs.parameters:
3838
search_space.params.append(
3939
HyperParameterSearchSpace.convertParameter(p))
@@ -72,7 +72,7 @@ def __init__(self, name, type_, min_, max_, list_, step):
7272
self.step = step
7373

7474
def __str__(self):
75-
if self.type == INTEGER or self.type == DOUBLE:
75+
if self.type == constant.INTEGER or self.type == constant.DOUBLE:
7676
return "HyperParameter(name: {}, type: {}, min: {}, max: {}, step: {})".format(
7777
self.name, self.type, self.min, self.max, self.step)
7878
else:
@@ -81,16 +81,16 @@ def __str__(self):
8181

8282
@staticmethod
8383
def int(name, min_, max_, step):
84-
return HyperParameter(name, INTEGER, min_, max_, [], step)
84+
return HyperParameter(name, constant.INTEGER, min_, max_, [], step)
8585

8686
@staticmethod
8787
def double(name, min_, max_, step):
88-
return HyperParameter(name, DOUBLE, min_, max_, [], step)
88+
return HyperParameter(name, constant.DOUBLE, min_, max_, [], step)
8989

9090
@staticmethod
9191
def categorical(name, lst):
92-
return HyperParameter(name, CATEGORICAL, 0, 0, [str(e) for e in lst], 0)
92+
return HyperParameter(name, constant.CATEGORICAL, 0, 0, [str(e) for e in lst], 0)
9393

9494
@staticmethod
9595
def discrete(name, lst):
96-
return HyperParameter(name, DISCRETE, 0, 0, [str(e) for e in lst], 0)
96+
return HyperParameter(name, constant.DISCRETE, 0, 0, [str(e) for e in lst], 0)

0 commit comments

Comments
 (0)