Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

change quniform/qloguniform style in GridSearch to conform with other tuners #1379

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions docs/en_US/Tutorial/SearchSpaceSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ All types of sampling strategies and their parameter are listed here:

Known Limitations:

* Note that In Grid Search Tuner, for users' convenience, the definition of `quniform` and `qloguniform` change, where q here specifies the number of values that will be sampled. Details about them are listed as follows

* Type 'quniform' will receive three values [low, high, q], where [low, high] specifies a range and 'q' specifies the number of values that will be sampled evenly. Note that q should be at least 2. It will be sampled in a way that the first sampled value is 'low', and each of the following values is (high-low)/q larger that the value in front of it.

* Type 'qloguniform' behaves like 'quniform' except that it will first change the range to [log(low), log(high)] and sample and then change the sampled value back.

* Note that Metis Tuner only supports numerical `choice` now

* Note that for nested search space:
Expand Down
22 changes: 9 additions & 13 deletions src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class GridSearchTuner(Tuner):

Type 'choice' will select one of the options. Note that it can also be nested.

Type 'quniform' will receive three values [low, high, q], where [low, high] specifies a range and 'q' specifies the number of values that will be sampled evenly.
Note that q should be at least 2.
It will be sampled in a way that the first sampled value is 'low', and each of the following values is (high-low)/q larger that the value in front of it.
Type 'quniform' will receive three values [low, high, q], where [low, high] specifies a range and 'q' specifies the interval
It will be sampled in a way that the first sampled value is 'low', and each of the following values is 'interval' larger that the value in front of it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

larger than

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


Type 'qloguniform' behaves like 'quniform' except that it will first change the range to [log(low), log(high)]
and sample and then change the sampled value back.
Expand Down Expand Up @@ -95,19 +94,16 @@ def json2parameter(self, ss_spec):

def _parse_quniform(self, param_value):
'''parse type of quniform parameter and return a list'''
if param_value[2] < 2:
raise RuntimeError("The number of values sampled (q) should be at least 2")
low, high, count = param_value[0], param_value[1], param_value[2]
interval = (high - low) / (count - 1)
return [float(low + interval * i) for i in range(count)]
low, high, interval = param_value[0], param_value[1], param_value[2]
count = int(np.floor((high - low) / interval)) + 1
return [low + interval * i for i in range(count)]

def parse_qtype(self, param_type, param_value):
'''parse type of quniform or qloguniform'''
if param_type == 'quniform':
return self._parse_quniform(param_value)
if param_type == 'qloguniform':
param_value[:2] = np.log(param_value[:2])
return list(np.exp(self._parse_quniform(param_value)))
if param_type in ['quniform', 'qloguniform']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot deal with quniform and qloguniform in the same way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference ?

# qloguniform has no difference from quniform,
# since grid search does not consider possibility distribution
return self._parse_quniform(param_value)

raise RuntimeError("Not supported type: %s" % param_type)

Expand Down