本文整理汇总了Python中ConfigSpace.UniformIntegerHyperparameter方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigSpace.UniformIntegerHyperparameter方法的具体用法?Python ConfigSpace.UniformIntegerHyperparameter怎么用?Python ConfigSpace.UniformIntegerHyperparameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSpace
的用法示例。
在下文中一共展示了ConfigSpace.UniformIntegerHyperparameter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def setUp(self):
self.configspace = CS.ConfigurationSpace()
self.HPs = []
self.HPs.append( CS.CategoricalHyperparameter('parent', [1,2,3]))
self.HPs.append( CS.CategoricalHyperparameter('child1_x1', ['foo','bar']))
self.HPs.append( CS.UniformFloatHyperparameter('child2_x1', lower=-1, upper=1))
self.HPs.append( CS.UniformIntegerHyperparameter('child3_x1', lower=-2, upper=5))
self.configspace.add_hyperparameters(self.HPs)
self.conditions = []
self.conditions += [CS.EqualsCondition(self.HPs[1], self.HPs[0], 1)]
self.conditions += [CS.EqualsCondition(self.HPs[2], self.HPs[0], 2)]
self.conditions += [CS.EqualsCondition(self.HPs[3], self.HPs[0], 3)]
[self.configspace.add_condition(cond) for cond in self.conditions]
示例2: create_configspace
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def create_configspace(parameter_config):
"""
Wrap the Worker's get_configspace() function for HpBandSter interface
"""
cs = CS.ConfigurationSpace()
params = []
for config in parameter_config:
p = AbstractProposer.parse_param_config(config)
if p['type'] == 'choice':
param = CS.CategoricalHyperparameter(p['name'], choices=p['range'])
else: # for int or float
param = dict(name=p['name'])
param['lower'], param['upper'] = min(p['range']), max(p['range'])
if p['type'] == 'int':
param = CS.UniformIntegerHyperparameter(**param)
else:
param = CS.UniformFloatHyperparameter(**param)
params.append(param)
cs.add_hyperparameters(params)
return cs
示例3: get_configuration_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_configuration_space():
cs = ConfigSpace.ConfigurationSpace()
ops_choices = ['conv1x1-bn-relu', 'conv3x3-bn-relu', 'maxpool3x3']
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("op_node_0", ops_choices))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("op_node_1", ops_choices))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("op_node_2", ops_choices))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("op_node_3", ops_choices))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("op_node_4", ops_choices))
cs.add_hyperparameter(ConfigSpace.UniformIntegerHyperparameter("num_edges", 0, MAX_EDGES))
for i in range(VERTICES * (VERTICES - 1) // 2):
cs.add_hyperparameter(ConfigSpace.UniformFloatHyperparameter("edge_%d" % i, 0, 1))
return cs
示例4: setUp
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def setUp(self):
self.configspace = CS.ConfigurationSpace(43)
HPs=[]
HPs.append( CS.UniformIntegerHyperparameter('int1', lower=-2, upper=2))
self.configspace.add_hyperparameters(HPs)
x_train_confs = [ self.configspace.sample_configuration() for i in range(self.n_train)]
self.x_train = np.array([c.get_array() for c in x_train_confs]).squeeze()
x_test_confs = [ self.configspace.sample_configuration() for i in range(self.n_test)]
self.x_test= np.array( [c.get_array() for c in x_test_confs]).squeeze()
示例5: add_hyperparameters
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def add_hyperparameters(self):
HP = CS.UniformIntegerHyperparameter('int1', lower=-2, upper=2)
self.configspace.add_hyperparameter(HP)
示例6: _get_types
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def _get_types(self):
""" extracts the needed types from the configspace for faster retrival later
type = 0 - numerical (continuous or integer) parameter
type >=1 - categorical parameter
TODO: figure out a way to properly handle ordinal parameters
"""
types = []
num_values = []
for hp in self.configspace.get_hyperparameters():
#print(hp)
if isinstance(hp, CS.CategoricalHyperparameter):
types.append('U')
num_values.append(len(hp.choices))
elif isinstance(hp, CS.UniformIntegerHyperparameter):
types.append('I')
num_values.append((hp.upper - hp.lower + 1))
elif isinstance(hp, CS.UniformFloatHyperparameter):
types.append('C')
num_values.append(np.inf)
elif isinstance(hp, CS.OrdinalHyperparameter):
types.append('O')
num_values.append(len(hp.sequence))
else:
raise ValueError('Unsupported Parametertype %s'%type(hp))
return(types, num_values)
示例7: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_config_space(
num_groups=(1, 9),
blocks_per_group=(1, 4),
max_units=((10, 1024), True),
activation=('sigmoid', 'tanh', 'relu'),
max_shake_drop_probability=(0, 1),
max_dropout=(0, 1.0),
resnet_shape=('funnel', 'long_funnel', 'diamond', 'hexagon', 'brick', 'triangle', 'stairs'),
use_dropout=(True, False),
use_shake_shake=(True, False),
use_shake_drop=(True, False)
):
cs = CS.ConfigurationSpace()
num_groups_hp = get_hyperparameter(CS.UniformIntegerHyperparameter, "num_groups", num_groups)
cs.add_hyperparameter(num_groups_hp)
blocks_per_group_hp = get_hyperparameter(CS.UniformIntegerHyperparameter, "blocks_per_group", blocks_per_group)
cs.add_hyperparameter(blocks_per_group_hp)
add_hyperparameter(cs, CS.CategoricalHyperparameter, "activation", activation)
use_dropout_hp = add_hyperparameter(cs, CS.CategoricalHyperparameter, "use_dropout", use_dropout)
add_hyperparameter(cs, CS.CategoricalHyperparameter, "use_shake_shake", use_shake_shake)
shake_drop_hp = add_hyperparameter(cs, CS.CategoricalHyperparameter, "use_shake_drop", use_shake_drop)
if True in use_shake_drop:
shake_drop_prob_hp = add_hyperparameter(cs, CS.UniformFloatHyperparameter, "max_shake_drop_probability",
max_shake_drop_probability)
cs.add_condition(CS.EqualsCondition(shake_drop_prob_hp, shake_drop_hp, True))
add_hyperparameter(cs, CSH.CategoricalHyperparameter, 'resnet_shape', resnet_shape)
add_hyperparameter(cs, CSH.UniformIntegerHyperparameter, "max_units", max_units)
if True in use_dropout:
max_dropout_hp = add_hyperparameter(cs, CSH.UniformFloatHyperparameter, "max_dropout", max_dropout)
cs.add_condition(CS.EqualsCondition(max_dropout_hp, use_dropout_hp, True))
return cs
示例8: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_config_space( nr_main_blocks=[1, 8], nr_residual_blocks=([1, 16], True), initial_filters=([8, 32], True), widen_factor=([0.5, 4], True),
res_branches=([1, 5], False), filters_size=[3, 3], **kwargs):
import ConfigSpace as CS
import ConfigSpace.hyperparameters as CSH
cs = CS.ConfigurationSpace()
nr_main_blocks_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "nr_main_blocks", nr_main_blocks)
cs.add_hyperparameter(nr_main_blocks_hp)
initial_filters_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "initial_filters", initial_filters)
cs.add_hyperparameter(initial_filters_hp)
# add_hyperparameter(cs, CSH.UniformIntegerHyperparameter, 'nr_convs', nr_convs, log=True)
death_rate_hp = get_hyperparameter(ConfigSpace.UniformFloatHyperparameter, "death_rate", ([0,1], False))
cs.add_hyperparameter(death_rate_hp)
if type(nr_main_blocks[0]) is int:
main_blocks_min = nr_main_blocks[0]
main_blocks_max = nr_main_blocks[1]
else:
main_blocks_min = nr_main_blocks[0][0]
main_blocks_max = nr_main_blocks[0][1]
for i in range(1, main_blocks_max + 1):
blocks_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'nr_residual_blocks_%d' % i, nr_residual_blocks)
blocks = cs.add_hyperparameter(blocks_hp)
widen_hp = get_hyperparameter(ConfigSpace.UniformFloatHyperparameter, 'widen_factor_%d' % i, widen_factor)
widen = cs.add_hyperparameter(widen_hp)
branches_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'res_branches_%d' % i, res_branches)
branches = cs.add_hyperparameter(branches_hp)
# filters = add_hyperparameter(cs, CSH.UniformIntegerHyperparameter, 'filters_size_%d' % i, filters_size, log=False)
if i > main_blocks_min:
cs.add_condition(CS.GreaterThanCondition(blocks_hp, nr_main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(widen_hp, nr_main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(branches_hp, nr_main_blocks_hp, i-1))
# cs.add_condition(CS.GreaterThanCondition(filters, main_blocks, i-1))
return cs
示例9: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_config_space(growth_rate_range=(12, 40), nr_blocks=(3, 4), layer_range=([1, 12], [6, 24], [12, 64], [12, 64]), num_init_features=(32, 128), **kwargs):
import ConfigSpace as CS
import ConfigSpace.hyperparameters as CSH
from autoPyTorch.utils.config_space_hyperparameter import add_hyperparameter
cs = CS.ConfigurationSpace()
growth_rate_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'growth_rate', growth_rate_range)
cs.add_hyperparameter(growth_rate_hp)
# add_hyperparameter(cs, CSH.UniformFloatHyperparameter, 'bn_size', [2, 4])
# add_hyperparameter(cs, CSH.UniformIntegerHyperparameter, 'num_init_features', num_init_features, log=True)
# add_hyperparameter(cs, CSH.CategoricalHyperparameter, 'bottleneck', [True, False])
blocks_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'blocks', nr_blocks)
cs.add_hyperparameter(blocks_hp)
use_dropout = add_hyperparameter(cs, CSH.CategoricalHyperparameter, 'use_dropout', [True, False])
dropout = add_hyperparameter(cs, CSH.UniformFloatHyperparameter, 'dropout', [0.0, 1.0])
cs.add_condition(CS.EqualsCondition(dropout, use_dropout, True))
if type(nr_blocks[0]) == int:
min_blocks = nr_blocks[0]
max_blocks = nr_blocks[1]
else:
min_blocks = nr_blocks[0][0]
max_blocks = nr_blocks[0][1]
for i in range(1, max_blocks+1):
layer_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'layer_in_block_%d' % i, layer_range[i-1])
cs.add_hyperparameter(layer_hp)
if i > min_blocks:
cs.add_condition(CS.GreaterThanCondition(layer_hp, blocks_hp, i-1))
return cs
示例10: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_config_space(
num_groups=((1, 9), False),
blocks_per_group=((1, 4), False),
num_units=((10, 1024), True),
activation=('sigmoid', 'tanh', 'relu'),
max_shake_drop_probability=(0, 1),
dropout=(0, 1.0),
use_shake_drop=(True, False),
use_shake_shake=(True, False),
use_dropout=(True, False),
**kwargs
):
cs = ConfigSpace.ConfigurationSpace()
num_groups_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "num_groups", num_groups)
cs.add_hyperparameter(num_groups_hp)
blocks_per_group_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "blocks_per_group", blocks_per_group)
cs.add_hyperparameter(blocks_per_group_hp)
add_hyperparameter(cs, ConfigSpace.CategoricalHyperparameter, "activation", activation)
use_dropout_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, "use_dropout", use_dropout)
cs.add_hyperparameter(use_dropout_hp)
add_hyperparameter(cs, ConfigSpace.CategoricalHyperparameter, "use_shake_shake", use_shake_shake)
use_shake_drop_hp = add_hyperparameter(cs, ConfigSpace.CategoricalHyperparameter, "use_shake_drop", use_shake_drop)
if True in use_shake_drop:
shake_drop_prob_hp = add_hyperparameter(cs, ConfigSpace.UniformFloatHyperparameter, "max_shake_drop_probability",
max_shake_drop_probability)
cs.add_condition(ConfigSpace.EqualsCondition(shake_drop_prob_hp, use_shake_drop_hp, True))
# it is the upper bound of the nr of groups, since the configuration will actually be sampled.
for i in range(0, num_groups[0][1] + 1):
n_units_hp = add_hyperparameter(cs, ConfigSpace.UniformIntegerHyperparameter,
"num_units_%d" % i, kwargs.pop("num_units_%d" % i, num_units))
if i > 1:
cs.add_condition(ConfigSpace.GreaterThanCondition(n_units_hp, num_groups_hp, i - 1))
if True in use_dropout:
dropout_hp = add_hyperparameter(cs, ConfigSpace.UniformFloatHyperparameter,
"dropout_%d" % i, kwargs.pop("dropout_%d" % i, dropout))
dropout_condition_1 = ConfigSpace.EqualsCondition(dropout_hp, use_dropout_hp, True)
if i > 1:
dropout_condition_2 = ConfigSpace.GreaterThanCondition(dropout_hp, num_groups_hp, i - 1)
cs.add_condition(ConfigSpace.AndConjunction(dropout_condition_1, dropout_condition_2))
else:
cs.add_condition(dropout_condition_1)
assert len(kwargs) == 0, "Invalid hyperparameter updates for resnet: %s" % str(kwargs)
return cs
示例11: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import UniformIntegerHyperparameter [as 别名]
def get_config_space( nr_main_blocks=[3, 7], initial_filters=([8, 32], True), nr_sub_blocks=([1, 4], False),
op_types = ["inverted_residual", "dwise_sep_conv"], kernel_sizes=[3, 5], strides=[1,2],
output_filters = [[12, 16, 20],
[18, 24, 30],
[24, 32, 40],
[48, 64, 80],
[72, 96, 120],
[120, 160, 200],
[240, 320, 400]], # the idea is to search for e.g. 0.75, 1, 1.25* output_filters(mainblock number)
skip_connection = [True, False], se_ratios = [0, 0.25], **kwargs):
import ConfigSpace as CS
import ConfigSpace.hyperparameters as CSH
cs = CS.ConfigurationSpace()
main_blocks_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "nr_main_blocks", nr_main_blocks)
initial_filters_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, "initial_filters", initial_filters)
cs.add_hyperparameter(main_blocks_hp)
cs.add_hyperparameter(initial_filters_hp)
if type(nr_main_blocks[0]) == int:
min_blocks = nr_main_blocks[0]
max_blocks = nr_main_blocks[1]
else:
min_blocks = nr_main_blocks[0][0]
max_blocks = nr_main_blocks[0][1]
for i in range(1, max_blocks + 1):
sub_blocks_hp = get_hyperparameter(ConfigSpace.UniformIntegerHyperparameter, 'nr_sub_blocks_%d' % i, nr_sub_blocks)
op_type_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, 'op_type_%d' % i, op_types)
kernel_size_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, 'kernel_size_%d' % i, kernel_sizes)
stride_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, 'stride_%d' % i, strides)
out_filters_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, 'out_filters_%d' % i, output_filters[i-1]) # take output_filters list i-1 as options
se_ratio_hp = get_hyperparameter(ConfigSpace.CategoricalHyperparameter, 'se_ratio_%d' % i, se_ratios)
cs.add_hyperparameter(sub_blocks_hp)
cs.add_hyperparameter(op_type_hp)
cs.add_hyperparameter(kernel_size_hp)
cs.add_hyperparameter(stride_hp)
cs.add_hyperparameter(out_filters_hp)
cs.add_hyperparameter(se_ratio_hp)
skip_con = cs.add_hyperparameter(CSH.CategoricalHyperparameter('skip_con_%d' % i, [True, False]))
if i > min_blocks:
cs.add_condition(CS.GreaterThanCondition(sub_blocks_hp, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(op_type_hp, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(kernel_size_hp, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(stride_hp, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(out_filters_hp, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(skip_con, main_blocks_hp, i-1))
cs.add_condition(CS.GreaterThanCondition(se_ratio_hp, main_blocks_hp, i-1))
return cs