本文整理汇总了Python中ConfigSpace.CategoricalHyperparameter方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigSpace.CategoricalHyperparameter方法的具体用法?Python ConfigSpace.CategoricalHyperparameter怎么用?Python ConfigSpace.CategoricalHyperparameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSpace
的用法示例。
在下文中一共展示了ConfigSpace.CategoricalHyperparameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [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 CategoricalHyperparameter [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_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_config_space(
num_layers=(1, 15),
max_units=((10, 1024), True),
activation=('sigmoid', 'tanh', 'relu'),
mlp_shape=('funnel', 'long_funnel', 'diamond', 'hexagon', 'brick', 'triangle', 'stairs'),
max_dropout=(0, 1.0),
use_dropout=(True, False)
):
cs = CS.ConfigurationSpace()
mlp_shape_hp = get_hyperparameter(CSH.CategoricalHyperparameter, 'mlp_shape', mlp_shape)
cs.add_hyperparameter(mlp_shape_hp)
num_layers_hp = get_hyperparameter(CSH.UniformIntegerHyperparameter, 'num_layers', num_layers)
cs.add_hyperparameter(num_layers_hp)
max_units_hp = get_hyperparameter(CSH.UniformIntegerHyperparameter, "max_units", max_units)
cs.add_hyperparameter(max_units_hp)
use_dropout_hp = add_hyperparameter(cs, CS.CategoricalHyperparameter, "use_dropout", 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))
add_hyperparameter(cs, CSH.CategoricalHyperparameter, 'activation', activation)
return cs
示例4: get_configuration_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_configuration_space():
cs = ConfigSpace.ConfigurationSpace()
cs.add_hyperparameter(ConfigSpace.OrdinalHyperparameter("n_units_1", [16, 32, 64, 128, 256, 512]))
cs.add_hyperparameter(ConfigSpace.OrdinalHyperparameter("n_units_2", [16, 32, 64, 128, 256, 512]))
cs.add_hyperparameter(ConfigSpace.OrdinalHyperparameter("dropout_1", [0.0, 0.3, 0.6]))
cs.add_hyperparameter(ConfigSpace.OrdinalHyperparameter("dropout_2", [0.0, 0.3, 0.6]))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("activation_fn_1", ["tanh", "relu"]))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("activation_fn_2", ["tanh", "relu"]))
cs.add_hyperparameter(
ConfigSpace.OrdinalHyperparameter("init_lr", [5 * 1e-4, 1e-3, 5 * 1e-3, 1e-2, 5 * 1e-2, 1e-1]))
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("lr_schedule", ["cosine", "const"]))
cs.add_hyperparameter(ConfigSpace.OrdinalHyperparameter("batch_size", [8, 16, 32, 64]))
return cs
示例5: get_configuration_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [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))
for i in range(VERTICES * (VERTICES - 1) // 2):
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("edge_%d" % i, [0, 1]))
return cs
示例6: setUp
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def setUp(self):
self.configspace = CS.ConfigurationSpace(43)
HPs=[]
HPs.append( CS.CategoricalHyperparameter('cat1', choices=['foo', 'bar', 'baz']))
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_train_confs]).squeeze()
示例7: add_hyperparameters
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def add_hyperparameters(self):
HPs=[]
HPs.append( CS.CategoricalHyperparameter('cat1', choices=['foo', 'bar', 'baz']))
self.configspace.add_hyperparameters(HPs)
示例8: _get_types
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [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)
示例9: get_configuration_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_configuration_space(self):
cs = ConfigSpace.ConfigurationSpace()
for node in list(self.num_parents_per_node.keys())[1:-1]:
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter("choice_block_{}_op".format(node),
[CONV1X1, CONV3X3, MAXPOOL3X3]))
for choice_block_index, num_parents in list(self.num_parents_per_node.items())[1:]:
cs.add_hyperparameter(
ConfigSpace.CategoricalHyperparameter(
"choice_block_{}_parents".format(choice_block_index),
parent_combinations(node=choice_block_index, num_parents=num_parents)))
return cs
示例10: get_configuration_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_configuration_space(max_nodes, search_space):
cs = ConfigSpace.ConfigurationSpace()
#edge2index = {}
for i in range(1, max_nodes):
for j in range(i):
node_str = '{:}<-{:}'.format(i, j)
cs.add_hyperparameter(ConfigSpace.CategoricalHyperparameter(node_str, search_space))
return cs
示例11: setUp
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def setUp(self):
logging.basicConfig(level=logging.ERROR)
np.random.seed(123)
self.X = np.random.uniform(-5, 5, 100)
self.y = np.random.normal(self.X, 1)
self.opt_func = lambda x, y, w, budget: np.mean(
(y[:int(budget)] - w * x[:int(budget)]) ** 2)
self.cs = CS.ConfigurationSpace()
self.cs.add_hyperparameter(
CS.CategoricalHyperparameter('w', [0, 1])
)
示例12: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [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
示例13: get_config_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_config_space(
num_layers=((1, 15), False),
num_units=((10, 1024), True),
activation=('sigmoid', 'tanh', 'relu'),
dropout=(0.0, 0.8),
use_dropout=(True, False),
**kwargs
):
cs = CS.ConfigurationSpace()
num_layers_hp = get_hyperparameter(CSH.UniformIntegerHyperparameter, 'num_layers', num_layers)
cs.add_hyperparameter(num_layers_hp)
use_dropout_hp = add_hyperparameter(cs, CS.CategoricalHyperparameter, "use_dropout", use_dropout)
for i in range(1, num_layers[0][1] + 1):
n_units_hp = get_hyperparameter(CSH.UniformIntegerHyperparameter, "num_units_%d" % i, kwargs.pop("num_units_%d" % i, num_units))
cs.add_hyperparameter(n_units_hp)
if i > num_layers[0][0]:
cs.add_condition(CS.GreaterThanCondition(n_units_hp, num_layers_hp, i - 1))
if True in use_dropout:
dropout_hp = get_hyperparameter(CSH.UniformFloatHyperparameter, "dropout_%d" % i, kwargs.pop("dropout_%d" % i, dropout))
cs.add_hyperparameter(dropout_hp)
dropout_condition_1 = CS.EqualsCondition(dropout_hp, use_dropout_hp, True)
if i > num_layers[0][0]:
dropout_condition_2 = CS.GreaterThanCondition(dropout_hp, num_layers_hp, i - 1)
cs.add_condition(CS.AndConjunction(dropout_condition_1, dropout_condition_2))
else:
cs.add_condition(dropout_condition_1)
add_hyperparameter(cs, CSH.CategoricalHyperparameter,'activation', activation)
assert len(kwargs) == 0, "Invalid hyperparameter updates for mlpnet: %s" % str(kwargs)
return(cs)
示例14: get_hyperparameter_search_space
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_hyperparameter_search_space(
initialize_bias=("Yes", "No", "Zero")
):
cs = ConfigSpace.ConfigurationSpace()
add_hyperparameter(cs, ConfigSpace.CategoricalHyperparameter, "initialize_bias", initialize_bias)
return cs
示例15: get_ndarray_bounds
# 需要导入模块: import ConfigSpace [as 别名]
# 或者: from ConfigSpace import CategoricalHyperparameter [as 别名]
def get_ndarray_bounds(self) -> List[Tuple[float, float]]:
bounds = []
final_bound = None
for hp in self.config_space.get_hyperparameters():
if isinstance(hp, CS.CategoricalHyperparameter):
if not self._fix_attribute_value(hp.name):
bound = [(0., 1.)] * len(hp.choices)
else:
bound = [(0., 0.)] * len(hp.choices)
bound[int(self.value_for_last_pos)] = (1., 1.)
else:
if not self._fix_attribute_value(hp.name):
bound = [(0., 1.)]
else:
val_int = float(hp._inverse_transform(
np.array([self.value_for_last_pos])).item())
bound = [(val_int, val_int)]
if hp.name == self.name_last_pos:
final_bound = bound
else:
bounds.extend(bound)
if final_bound is not None:
bounds.extend(final_bound)
return bounds
# NOTE: Assumes that config argument not used afterwards...