Commit 79a3ce9a authored by suiguoxin's avatar suiguoxin
Browse files

change quniform style in GridSearch to conform with other tuners

parent 88b75065
...@@ -90,12 +90,6 @@ All types of sampling strategies and their parameter are listed here: ...@@ -90,12 +90,6 @@ All types of sampling strategies and their parameter are listed here:
Known Limitations: 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 Metis Tuner only supports numerical `choice` now
* Note that for nested search space: * Note that for nested search space:
......
...@@ -43,9 +43,8 @@ class GridSearchTuner(Tuner): ...@@ -43,9 +43,8 @@ class GridSearchTuner(Tuner):
Type 'choice' will select one of the options. Note that it can also be nested. 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. Type 'quniform' will receive three values [low, high, q], where [low, high] specifies a range and 'q' specifies the interval
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 'interval' larger that the value in front of it.
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)] 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. and sample and then change the sampled value back.
...@@ -95,19 +94,16 @@ class GridSearchTuner(Tuner): ...@@ -95,19 +94,16 @@ class GridSearchTuner(Tuner):
def _parse_quniform(self, param_value): def _parse_quniform(self, param_value):
'''parse type of quniform parameter and return a list''' '''parse type of quniform parameter and return a list'''
if param_value[2] < 2: low, high, interval = param_value[0], param_value[1], param_value[2]
raise RuntimeError("The number of values sampled (q) should be at least 2") count = int(np.floor((high - low) / interval)) + 1
low, high, count = param_value[0], param_value[1], param_value[2] return [low + interval * i for i in range(count)]
interval = (high - low) / (count - 1)
return [float(low + interval * i) for i in range(count)]
def parse_qtype(self, param_type, param_value): def parse_qtype(self, param_type, param_value):
'''parse type of quniform or qloguniform''' '''parse type of quniform or qloguniform'''
if param_type == 'quniform': if param_type in ['quniform', 'qloguniform']:
return self._parse_quniform(param_value) # qloguniform has no difference from quniform,
if param_type == 'qloguniform': # since grid search does not consider possibility distribution
param_value[:2] = np.log(param_value[:2]) return self._parse_quniform(param_value)
return list(np.exp(self._parse_quniform(param_value)))
raise RuntimeError("Not supported type: %s" % param_type) raise RuntimeError("Not supported type: %s" % param_type)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment