Skip to content

Commit

Permalink
covered all parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
John Platt authored and jdplatt committed Feb 26, 2019
1 parent 2e6101b commit 7235302
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/suggestion/bayesianoptimization/src/algorithm_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def deal_with_discrete(feasible_values, current_value):

def deal_with_categorical(feasible_values, one_hot_values):
""" function to do the one hot encoding of the categorical values """
#index = np.argmax(one_hot_values)
index = one_hot_values.argmax()
index = np.argmax(one_hot_values)
#index = one_hot_values.argmax()
return feasible_values[int(index)]


Expand Down
8 changes: 6 additions & 2 deletions pkg/suggestion/tests/parameter_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ parameters:
- - name: "x"
value: 1.0
- name: "y"
value: 1.0
value: 1
- name: "fake_discrete"
value: 2
- name: "fake_categorical"
value: "true"
- - name: "x"
value: 1.0
- name: "y"
value: 1.0
value: 1
- name: "fake_discrete"
value: 3
- name: "fake_categorical"
value: "false"
metrics:
- 1.0
- 1.0
12 changes: 9 additions & 3 deletions pkg/suggestion/tests/study_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ parameter_configs:
feasible:
min: -5.0
max: 5.0
- parameter_type: 1 # Code for DOUBLE
- parameter_type: 2 # Code for INT
name: "y"
feasible:
min: -5.0
max: 5.0
min: -5
max: 5
- parameter_type: 3 # Code for DISCRETE
name: "fake_discrete"
feasible:
list:
- 2
- 3
- 5
- parameter_type: 4 # Code for DISCRETE
name: "fake_categorical"
feasible:
list:
- "true"
- "false"
21 changes: 12 additions & 9 deletions pkg/suggestion/tests/test_algorithm_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ def observations():

def test_algorithm_manager(study_config, observations):
study_id = "test_id"
x_next = [1.0, 1.0, 5]
x_next = [1.0, 1, 5, "true"]
manager = AlgorithmManager(study_id, study_config,
observations.parameters, observations.metrics)
assert manager.study_id == study_id
assert manager.study_config == study_config
assert manager.goal == api_pb2.MAXIMIZE
assert manager.types == [api_pb2.DOUBLE, api_pb2.DOUBLE, api_pb2.DISCRETE]
assert manager.names == ["x", "y", "fake_discrete"]
assert manager.dim == 3
assert manager.lower_bound == [-5.0, -5.0, 2]
assert manager.upper_bound == [5.0, 5.0, 5]
assert manager.types == [api_pb2.DOUBLE, api_pb2.INT, api_pb2.DISCRETE, api_pb2.CATEGORICAL]
assert manager.names == ["x", "y", "fake_discrete", "fake_categorical"]
assert manager.dim == 5
assert manager.lower_bound == [-5.0, -5, 2, 0, 0]
assert manager.upper_bound == [5.0, 5, 5, 1, 1]
assert manager.discrete_info == [{"name": "fake_discrete", "values": [2, 3, 5]}]
assert np.allclose(manager.X_train, np.array([[1.0, 1.0, 2], [1.0, 1.0, 3]]))
assert manager.categorical_info == \
[{"name": "fake_categorical", "values": ["true", "false"], "number": 2}]
assert np.allclose(manager.X_train, np.array([[1.0, 1, 2, 1, 0], [1.0, 1, 3, 0, 1]]))
assert np.allclose(manager.y_train, np.array([1.0, 1.0]))
parsed_x_next = manager.parse_x_next(x_next)
x_next_dict = manager.convert_to_dict(parsed_x_next)
assert x_next_dict == \
[{"name": "x", "value": 1.0, "type": api_pb2.DOUBLE},
{"name": "y", "value": 1.0, "type": api_pb2.DOUBLE},
{"name": "fake_discrete", "value": 5, "type": api_pb2.DISCRETE}]
{"name": "y", "value": 1, "type": api_pb2.INT},
{"name": "fake_discrete", "value": 5, "type": api_pb2.DISCRETE},
{"name": "fake_categorical", "value": "true", "type": api_pb2.CATEGORICAL}]

0 comments on commit 7235302

Please sign in to comment.