本文整理汇总了Python中HPOlibConfigSpace.configuration_space.ConfigurationSpace.add_condition方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSpace.add_condition方法的具体用法?Python ConfigurationSpace.add_condition怎么用?Python ConfigurationSpace.add_condition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HPOlibConfigSpace.configuration_space.ConfigurationSpace
的用法示例。
在下文中一共展示了ConfigurationSpace.add_condition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
C = UniformFloatHyperparameter("C", 0.03125, 32768, log=True, default=1.0)
# No linear kernel here, because we have liblinear
kernel = CategoricalHyperparameter(name="kernel", choices=["rbf", "poly", "sigmoid"], default="rbf")
degree = UniformIntegerHyperparameter("degree", 1, 5, default=3)
gamma = UniformFloatHyperparameter("gamma", 3.0517578125e-05, 8, log=True, default=0.1)
# TODO this is totally ad-hoc
coef0 = UniformFloatHyperparameter("coef0", -1, 1, default=0)
# probability is no hyperparameter, but an argument to the SVM algo
shrinking = CategoricalHyperparameter("shrinking", ["True", "False"], default="True")
tol = UniformFloatHyperparameter("tol", 1e-5, 1e-1, default=1e-4, log=True)
# cache size is not a hyperparameter, but an argument to the program!
max_iter = UnParametrizedHyperparameter("max_iter", -1)
cs = ConfigurationSpace()
cs.add_hyperparameter(C)
cs.add_hyperparameter(kernel)
cs.add_hyperparameter(degree)
cs.add_hyperparameter(gamma)
cs.add_hyperparameter(coef0)
cs.add_hyperparameter(shrinking)
cs.add_hyperparameter(tol)
cs.add_hyperparameter(max_iter)
degree_depends_on_poly = EqualsCondition(degree, kernel, "poly")
coef0_condition = InCondition(coef0, kernel, ["poly", "sigmoid"])
cs.add_condition(degree_depends_on_poly)
cs.add_condition(coef0_condition)
return cs
示例2: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
cs = ConfigurationSpace()
loss = cs.add_hyperparameter(CategoricalHyperparameter(
"loss", ["ls", "lad", "huber", "quantile"], default="ls"))
learning_rate = cs.add_hyperparameter(UniformFloatHyperparameter(
name="learning_rate", lower=0.0001, upper=1, default=0.1, log=True))
n_estimators = cs.add_hyperparameter(Constant("n_estimators", 100))
max_depth = cs.add_hyperparameter(UniformIntegerHyperparameter(
name="max_depth", lower=1, upper=10, default=3))
min_samples_split = cs.add_hyperparameter(UniformIntegerHyperparameter(
name="min_samples_split", lower=2, upper=20, default=2, log=False))
min_samples_leaf = cs.add_hyperparameter(UniformIntegerHyperparameter(
name="min_samples_leaf", lower=1, upper=20, default=1, log=False))
min_weight_fraction_leaf = cs.add_hyperparameter(
UnParametrizedHyperparameter("min_weight_fraction_leaf", 0.))
subsample = cs.add_hyperparameter(UniformFloatHyperparameter(
name="subsample", lower=0.01, upper=1.0, default=1.0, log=False))
max_features = cs.add_hyperparameter(UniformFloatHyperparameter(
"max_features", 0.5, 5, default=1))
max_leaf_nodes = cs.add_hyperparameter(UnParametrizedHyperparameter(
name="max_leaf_nodes", value="None"))
alpha = cs.add_hyperparameter(UniformFloatHyperparameter(
"alpha", lower=0.75, upper=0.99, default=0.9))
cs.add_condition(InCondition(alpha, loss, ['huber', 'quantile']))
return cs
示例3: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
cs = ConfigurationSpace()
use_minimum_fraction = cs.add_hyperparameter(CategoricalHyperparameter(
"use_minimum_fraction", ["True", "False"], default="True"))
minimum_fraction = cs.add_hyperparameter(UniformFloatHyperparameter(
"minimum_fraction", lower=.0001, upper=0.5, default=0.01, log=True))
cs.add_condition(EqualsCondition(minimum_fraction,
use_minimum_fraction, 'True'))
return cs
示例4: test_hyperparameters_with_valid_condition
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_hyperparameters_with_valid_condition(self):
cs = ConfigurationSpace()
hp1 = CategoricalHyperparameter("parent", [0, 1])
cs.add_hyperparameter(hp1)
hp2 = UniformIntegerHyperparameter("child", 0, 10)
cs.add_hyperparameter(hp2)
cond = EqualsCondition(hp2, hp1, 0)
cs.add_condition(cond)
self.assertEqual(len(cs._hyperparameters), 2)
示例5: test_get_conditions
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_get_conditions(self):
cs = ConfigurationSpace()
hp1 = CategoricalHyperparameter("parent", [0, 1])
cs.add_hyperparameter(hp1)
hp2 = UniformIntegerHyperparameter("child", 0, 10)
cs.add_hyperparameter(hp2)
self.assertEqual([], cs.get_conditions())
cond1 = EqualsCondition(hp2, hp1, 0)
cs.add_condition(cond1)
self.assertEqual([cond1], cs.get_conditions())
示例6: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
cs = ConfigurationSpace()
shrinkage = cs.add_hyperparameter(
CategoricalHyperparameter("shrinkage", ["None", "auto", "manual"], default="None")
)
shrinkage_factor = cs.add_hyperparameter(UniformFloatHyperparameter("shrinkage_factor", 0.0, 1.0, 0.5))
n_components = cs.add_hyperparameter(UniformIntegerHyperparameter("n_components", 1, 250, default=10))
tol = cs.add_hyperparameter(UniformFloatHyperparameter("tol", 1e-5, 1e-1, default=1e-4, log=True))
cs.add_condition(EqualsCondition(shrinkage_factor, shrinkage, "manual"))
return cs
示例7: test_condition_with_cycles
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_condition_with_cycles(self):
cs = ConfigurationSpace()
hp1 = CategoricalHyperparameter("parent", [0, 1])
cs.add_hyperparameter(hp1)
hp2 = UniformIntegerHyperparameter("child", 0, 10)
cs.add_hyperparameter(hp2)
cond1 = EqualsCondition(hp2, hp1, 0)
cs.add_condition(cond1)
cond2 = EqualsCondition(hp1, hp2, 0)
self.assertRaisesRegexp(ValueError, "Hyperparameter configuration "
"contains a cycle \[\['child', 'parent'\]\]",
cs.add_condition, cond2)
示例8: test_get_hyperparameters
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_get_hyperparameters(self):
cs = ConfigurationSpace()
self.assertEqual(0, len(cs.get_hyperparameters()))
hp1 = CategoricalHyperparameter("parent", [0, 1])
cs.add_hyperparameter(hp1)
self.assertEqual([hp1], cs.get_hyperparameters())
hp2 = UniformIntegerHyperparameter("child", 0, 10)
cs.add_hyperparameter(hp2)
cond1 = EqualsCondition(hp2, hp1, 1)
cs.add_condition(cond1)
self.assertEqual([hp1, hp2], cs.get_hyperparameters())
# TODO: I need more tests for the topological sort!
self.assertEqual([hp1, hp2], cs.get_hyperparameters())
示例9: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
# Copied from libsvm_c
C = UniformFloatHyperparameter(
name="C", lower=0.03125, upper=32768, log=True, default=1.0)
kernel = CategoricalHyperparameter(
name="kernel", choices=['linear', 'poly', 'rbf', 'sigmoid'],
default="rbf")
degree = UniformIntegerHyperparameter(
name="degree", lower=1, upper=5, default=3)
# Changed the gamma value to 0.0 (is 0.1 for classification)
gamma = UniformFloatHyperparameter(
name="gamma", lower=3.0517578125e-05, upper=8, log=True, default=0.1)
# TODO this is totally ad-hoc
coef0 = UniformFloatHyperparameter(
name="coef0", lower=-1, upper=1, default=0)
# probability is no hyperparameter, but an argument to the SVM algo
shrinking = CategoricalHyperparameter(
name="shrinking", choices=["True", "False"], default="True")
tol = UniformFloatHyperparameter(
name="tol", lower=1e-5, upper=1e-1, default=1e-3, log=True)
max_iter = UnParametrizedHyperparameter("max_iter", -1)
# Random Guess
epsilon = UniformFloatHyperparameter(name="epsilon", lower=0.001,
upper=1, default=0.1, log=True)
cs = ConfigurationSpace()
cs.add_hyperparameter(C)
cs.add_hyperparameter(kernel)
cs.add_hyperparameter(degree)
cs.add_hyperparameter(gamma)
cs.add_hyperparameter(coef0)
cs.add_hyperparameter(shrinking)
cs.add_hyperparameter(tol)
cs.add_hyperparameter(max_iter)
cs.add_hyperparameter(epsilon)
degree_depends_on_kernel = InCondition(child=degree, parent=kernel,
values=('poly', 'rbf', 'sigmoid'))
gamma_depends_on_kernel = InCondition(child=gamma, parent=kernel,
values=('poly', 'rbf'))
coef0_depends_on_kernel = InCondition(child=coef0, parent=kernel,
values=('poly', 'sigmoid'))
cs.add_condition(degree_depends_on_kernel)
cs.add_condition(gamma_depends_on_kernel)
cs.add_condition(coef0_depends_on_kernel)
return cs
示例10: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
cs = ConfigurationSpace()
n_components = cs.add_hyperparameter(UniformIntegerHyperparameter(
"n_components", 10, 2000, default=100))
algorithm = cs.add_hyperparameter(CategoricalHyperparameter('algorithm',
['parallel', 'deflation'], 'parallel'))
whiten = cs.add_hyperparameter(CategoricalHyperparameter('whiten',
['False', 'True'], 'False'))
fun = cs.add_hyperparameter(CategoricalHyperparameter(
'fun', ['logcosh', 'exp', 'cube'], 'logcosh'))
cs.add_condition(EqualsCondition(n_components, whiten, "True"))
return cs
示例11: get_hyperparameter_search_space
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def get_hyperparameter_search_space(dataset_properties=None):
cs = ConfigurationSpace()
loss = cs.add_hyperparameter(CategoricalHyperparameter("loss",
["squared_loss", "huber", "epsilon_insensitive", "squared_epsilon_insensitive"],
default="squared_loss"))
penalty = cs.add_hyperparameter(CategoricalHyperparameter(
"penalty", ["l1", "l2", "elasticnet"], default="l2"))
alpha = cs.add_hyperparameter(UniformFloatHyperparameter(
"alpha", 10e-7, 1e-1, log=True, default=0.01))
l1_ratio = cs.add_hyperparameter(UniformFloatHyperparameter(
"l1_ratio", 1e-9, 1., log=True, default=0.15))
fit_intercept = cs.add_hyperparameter(UnParametrizedHyperparameter(
"fit_intercept", "True"))
n_iter = cs.add_hyperparameter(UniformIntegerHyperparameter(
"n_iter", 5, 1000, log=True, default=20))
epsilon = cs.add_hyperparameter(UniformFloatHyperparameter(
"epsilon", 1e-5, 1e-1, default=1e-4, log=True))
learning_rate = cs.add_hyperparameter(CategoricalHyperparameter(
"learning_rate", ["optimal", "invscaling", "constant"],
default="optimal"))
eta0 = cs.add_hyperparameter(UniformFloatHyperparameter(
"eta0", 10 ** -7, 0.1, default=0.01))
power_t = cs.add_hyperparameter(UniformFloatHyperparameter(
"power_t", 1e-5, 1, default=0.5))
average = cs.add_hyperparameter(CategoricalHyperparameter(
"average", ["False", "True"], default="False"))
# TODO add passive/aggressive here, although not properly documented?
elasticnet = EqualsCondition(l1_ratio, penalty, "elasticnet")
epsilon_condition = InCondition(epsilon, loss,
["huber", "epsilon_insensitive", "squared_epsilon_insensitive"])
# eta0 seems to be always active according to the source code; when
# learning_rate is set to optimial, eta0 is the starting value:
# https://github.com/scikit-learn/scikit-learn/blob/0.15.X/sklearn/linear_model/sgd_fast.pyx
# eta0_and_inv = EqualsCondition(eta0, learning_rate, "invscaling")
#eta0_and_constant = EqualsCondition(eta0, learning_rate, "constant")
#eta0_condition = OrConjunction(eta0_and_inv, eta0_and_constant)
power_t_condition = EqualsCondition(power_t, learning_rate,
"invscaling")
cs.add_condition(elasticnet)
cs.add_condition(epsilon_condition)
cs.add_condition(power_t_condition)
return cs
示例12: test_repr
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_repr(self):
cs1 = ConfigurationSpace()
retval = cs1.__str__()
self.assertEqual("Configuration space object:\n Hyperparameters:\n",
retval)
hp1 = CategoricalHyperparameter("parent", [0, 1])
cs1.add_hyperparameter(hp1)
retval = cs1.__str__()
self.assertEqual("Configuration space object:\n Hyperparameters:\n"
" %s\n" % str(hp1), retval)
hp2 = UniformIntegerHyperparameter("child", 0, 10)
cond1 = EqualsCondition(hp2, hp1, 0)
cs1.add_hyperparameter(hp2)
cs1.add_condition(cond1)
retval = cs1.__str__()
self.assertEqual("Configuration space object:\n Hyperparameters:\n"
" %s\n %s\n Conditions:\n %s\n" %
(str(hp2), str(hp1), str(cond1)), retval)
示例13: test_add_conjunction
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_add_conjunction(self):
hp1 = CategoricalHyperparameter("input1", [0, 1])
hp2 = CategoricalHyperparameter("input2", [0, 1])
hp3 = CategoricalHyperparameter("input3", [0, 1])
hp4 = Constant("And", "True")
cond1 = EqualsCondition(hp4, hp1, 1)
cond2 = EqualsCondition(hp4, hp2, 1)
cond3 = EqualsCondition(hp4, hp3, 1)
andconj1 = AndConjunction(cond1, cond2, cond3)
cs = ConfigurationSpace()
cs.add_hyperparameter(hp1)
cs.add_hyperparameter(hp2)
cs.add_hyperparameter(hp3)
cs.add_hyperparameter(hp4)
cs.add_condition(andconj1)
self.assertNotIn(hp4, cs.get_all_uncoditional_hyperparameters())
示例14: test_add_second_condition_wo_conjunction
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_add_second_condition_wo_conjunction(self):
hp1 = CategoricalHyperparameter("input1", [0, 1])
hp2 = CategoricalHyperparameter("input2", [0, 1])
hp3 = Constant("And", "True")
cond1 = EqualsCondition(hp3, hp1, 1)
cond2 = EqualsCondition(hp3, hp2, 1)
cs = ConfigurationSpace()
cs.add_hyperparameter(hp1)
cs.add_hyperparameter(hp2)
cs.add_hyperparameter(hp3)
cs.add_condition(cond1)
self.assertRaisesRegexp(ValueError,
"Adding a second condition \(different\) for a "
"hyperparameter is ambigouos and "
"therefore forbidden. Add a conjunction "
"instead!",
cs.add_condition, cond2)
示例15: test_check_configuration2
# 需要导入模块: from HPOlibConfigSpace.configuration_space import ConfigurationSpace [as 别名]
# 或者: from HPOlibConfigSpace.configuration_space.ConfigurationSpace import add_condition [as 别名]
def test_check_configuration2(self):
# Test that hyperparameters which are not active must not be set and
# that evaluating forbidden clauses does not choke on missing
# hyperparameters
cs = ConfigurationSpace()
classifier = CategoricalHyperparameter("classifier",
["k_nearest_neighbors", "extra_trees"])
metric = CategoricalHyperparameter("metric", ["minkowski", "other"])
p = CategoricalHyperparameter("k_nearest_neighbors:p", [1, 2])
metric_depends_on_classifier = EqualsCondition(metric, classifier,
"k_nearest_neighbors")
p_depends_on_metric = EqualsCondition(p, metric, "minkowski")
cs.add_hyperparameter(metric)
cs.add_hyperparameter(p)
cs.add_hyperparameter(classifier)
cs.add_condition(metric_depends_on_classifier)
cs.add_condition(p_depends_on_metric)
forbidden = ForbiddenEqualsClause(metric, "other")
cs.add_forbidden_clause(forbidden)
configuration = Configuration(cs, dict(classifier="extra_trees"))