Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Range for Int and Double values in Grid #1732

Merged
Merged
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
5 changes: 3 additions & 2 deletions pkg/suggestion/v1beta1/chocolate/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ def create_optimizer(self, algorithm_name):

for param in self.search_space.params:
key = BaseChocolateService.encode(param.name)
# Chocolate quantized_uniform distribution uses half-open interval: [low, high).
if param.type == INTEGER:
chocolate_search_space[key] = choco.quantized_uniform(
int(param.min), int(param.max), int(param.step))
int(param.min), int(param.max) + int(param.step), int(param.step))
elif param.type == DOUBLE:
chocolate_search_space[key] = choco.quantized_uniform(
float(param.min), float(param.max), float(param.step))
float(param.min), float(param.max) + float(param.step), float(param.step))
# For Categorical and Discrete insert indexes to DB from list of values
elif param.type == CATEGORICAL or param.type == DISCRETE:
chocolate_search_space[key] = choco.choice(
Expand Down
18 changes: 9 additions & 9 deletions pkg/suggestion/v1beta1/internal/search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

import logging
from pkg.apis.manager.v1beta1.python import api_pb2 as api

from pkg.suggestion.v1beta1.internal.constant import *
from pkg.apis.manager.v1beta1.python import api_pb2 as api
import pkg.suggestion.v1beta1.internal.constant as constant


logging.basicConfig(level=logging.DEBUG)
Expand All @@ -31,9 +31,9 @@ def __init__(self):
def convert(experiment):
search_space = HyperParameterSearchSpace()
if experiment.spec.objective.type == api.MAXIMIZE:
search_space.goal = MAX_GOAL
search_space.goal = constant.MAX_GOAL
elif experiment.spec.objective.type == api.MINIMIZE:
search_space.goal = MIN_GOAL
search_space.goal = constant.MIN_GOAL
for p in experiment.spec.parameter_specs.parameters:
search_space.params.append(
HyperParameterSearchSpace.convertParameter(p))
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, name, type_, min_, max_, list_, step):
self.step = step

def __str__(self):
if self.type == INTEGER or self.type == DOUBLE:
if self.type == constant.INTEGER or self.type == constant.DOUBLE:
return "HyperParameter(name: {}, type: {}, min: {}, max: {}, step: {})".format(
self.name, self.type, self.min, self.max, self.step)
else:
Expand All @@ -81,16 +81,16 @@ def __str__(self):

@staticmethod
def int(name, min_, max_, step):
return HyperParameter(name, INTEGER, min_, max_, [], step)
return HyperParameter(name, constant.INTEGER, min_, max_, [], step)

@staticmethod
def double(name, min_, max_, step):
return HyperParameter(name, DOUBLE, min_, max_, [], step)
return HyperParameter(name, constant.DOUBLE, min_, max_, [], step)

@staticmethod
def categorical(name, lst):
return HyperParameter(name, CATEGORICAL, 0, 0, [str(e) for e in lst], 0)
return HyperParameter(name, constant.CATEGORICAL, 0, 0, [str(e) for e in lst], 0)

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