当前位置: 首页>>代码示例>>Python>>正文


Python ConfigurationSpace.get_hyperparameters方法代码示例

本文整理汇总了Python中ConfigSpace.ConfigurationSpace.get_hyperparameters方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSpace.get_hyperparameters方法的具体用法?Python ConfigurationSpace.get_hyperparameters怎么用?Python ConfigurationSpace.get_hyperparameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigSpace.ConfigurationSpace的用法示例。


在下文中一共展示了ConfigurationSpace.get_hyperparameters方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_hyperparameters_topological_sort

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_hyperparameters [as 别名]
    def test_get_hyperparameters_topological_sort(self):
            # and now for something more complicated
            cs = ConfigurationSpace()
            hp1 = CategoricalHyperparameter("input1", [0, 1])
            hp2 = CategoricalHyperparameter("input2", [0, 1])
            hp3 = CategoricalHyperparameter("input3", [0, 1])
            hp4 = CategoricalHyperparameter("input4", [0, 1])
            hp5 = CategoricalHyperparameter("input5", [0, 1])
            hp6 = Constant("AND", "True")
            # More top-level hyperparameters
            hp7 = CategoricalHyperparameter("input7", [0, 1])
            # Somewhat shuffled
            hyperparameters = [hp1, hp2, hp3, hp4, hp5, hp6, hp7]

            for hp in hyperparameters:
                cs.add_hyperparameter(hp)

            cond1 = EqualsCondition(hp6, hp1, 1)
            cond2 = NotEqualsCondition(hp6, hp2, 1)
            cond3 = InCondition(hp6, hp3, [1])
            cond4 = EqualsCondition(hp5, hp3, 1)
            cond5 = EqualsCondition(hp4, hp5, 1)
            cond6 = EqualsCondition(hp6, hp4, 1)
            cond7 = EqualsCondition(hp6, hp5, 1)

            conj1 = AndConjunction(cond1, cond2)
            conj2 = OrConjunction(conj1, cond3)
            conj3 = AndConjunction(conj2, cond6, cond7)

            cs.add_condition(cond4)
            hps = cs.get_hyperparameters()
            # AND is moved to the front because of alphabetical sorting
            for hp, idx in zip(hyperparameters, [1, 2, 3, 4, 6, 0, 5]):
                self.assertEqual(hps.index(hp), idx)
                self.assertEqual(cs._hyperparameter_idx[hp.name], idx)
                self.assertEqual(cs._idx_to_hyperparameter[idx], hp.name)

            cs.add_condition(cond5)
            hps = cs.get_hyperparameters()
            for hp, idx in zip(hyperparameters, [1, 2, 3, 6, 5, 0, 4]):
                self.assertEqual(hps.index(hp), idx)
                self.assertEqual(cs._hyperparameter_idx[hp.name], idx)
                self.assertEqual(cs._idx_to_hyperparameter[idx], hp.name)

            cs.add_condition(conj3)
            hps = cs.get_hyperparameters()
            # print(hps, hyperparameters)
            for hp, idx in zip(hyperparameters, [0, 1, 2, 5, 4, 6, 3]):
                # print(hp, idx)
                self.assertEqual(hps.index(hp), idx)
                self.assertEqual(cs._hyperparameter_idx[hp.name], idx)
            self.assertEqual(cs._idx_to_hyperparameter[idx], hp.name)
开发者ID:automl,项目名称:ConfigSpace,代码行数:54,代码来源:test_configuration_space.py

示例2: test_get_hyperparamforbidden_clauseseters

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_hyperparameters [as 别名]
 def test_get_hyperparamforbidden_clauseseters(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())
开发者ID:automl,项目名称:ConfigSpace,代码行数:15,代码来源:test_configuration_space.py

示例3: deactivate_inactive_hyperparameters

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_hyperparameters [as 别名]
def deactivate_inactive_hyperparameters(configuration: dict,
                                        configuration_space: ConfigurationSpace):
    hyperparameters = configuration_space.get_hyperparameters()
    configuration = Configuration(configuration_space=configuration_space,
                                  values=configuration,
                                  allow_inactive_with_values=True)

    hps = deque()

    unconditional_hyperparameters = configuration_space.get_all_unconditional_hyperparameters()
    hyperparameters_with_children = list()
    for uhp in unconditional_hyperparameters:
        children = configuration_space._children_of[uhp]
        if len(children) > 0:
            hyperparameters_with_children.append(uhp)
    hps.extendleft(hyperparameters_with_children)

    inactive = set()

    while len(hps) > 0:
        hp = hps.pop()
        children = configuration_space._children_of[hp]
        for child in children:
            conditions = configuration_space._parent_conditions_of[child.name]
            for condition in conditions:
                if not condition.evaluate_vector(configuration.get_array()):
                    dic = configuration.get_dictionary()
                    try:
                        del dic[child.name]
                    except KeyError:
                        continue
                    configuration = Configuration(
                        configuration_space=configuration_space,
                        values=dic,
                        allow_inactive_with_values=True)
                    inactive.add(child.name)
                hps.appendleft(child.name)

    for hp in hyperparameters:
        if hp.name in inactive:
            dic = configuration.get_dictionary()
            try:
                del dic[hp.name]
            except KeyError:
                continue
            configuration = Configuration(
                configuration_space=configuration_space,
                values=dic,
                allow_inactive_with_values=True)

    return Configuration(configuration_space, values=configuration.get_dictionary())
开发者ID:smohsinali,项目名称:ConfigSpace,代码行数:53,代码来源:util.py

示例4: test_check_configuration

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_hyperparameters [as 别名]
    def test_check_configuration(self):
        # TODO this is only a smoke test
        # TODO actually, this rather tests the evaluate methods in the
        # conditions module!
        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)
        # This automatically checks the configuration!
        Configuration(cs, dict(parent=0, child=5))

        # and now for something more complicated
        cs = ConfigurationSpace()
        hp1 = CategoricalHyperparameter("input1", [0, 1])
        cs.add_hyperparameter(hp1)
        hp2 = CategoricalHyperparameter("input2", [0, 1])
        cs.add_hyperparameter(hp2)
        hp3 = CategoricalHyperparameter("input3", [0, 1])
        cs.add_hyperparameter(hp3)
        hp4 = CategoricalHyperparameter("input4", [0, 1])
        cs.add_hyperparameter(hp4)
        hp5 = CategoricalHyperparameter("input5", [0, 1])
        cs.add_hyperparameter(hp5)
        hp6 = Constant("AND", "True")
        cs.add_hyperparameter(hp6)

        cond1 = EqualsCondition(hp6, hp1, 1)
        cond2 = NotEqualsCondition(hp6, hp2, 1)
        cond3 = InCondition(hp6, hp3, [1])
        cond4 = EqualsCondition(hp6, hp4, 1)
        cond5 = EqualsCondition(hp6, hp5, 1)

        conj1 = AndConjunction(cond1, cond2)
        conj2 = OrConjunction(conj1, cond3)
        conj3 = AndConjunction(conj2, cond4, cond5)
        cs.add_condition(conj3)

        expected_outcomes = [False, False, False, False, False,
                             False, False, True, False, False,
                             False, False, False, False, False,
                             True, False, False, False, True,
                             False, False, False, True, False,
                             False, False, False, False, False,
                             False, True]

        for idx, values in enumerate(product([0, 1], repeat=5)):
            # The hyperparameters aren't sorted, but the test assumes them to
            #  be sorted.
            hyperparameters = sorted(cs.get_hyperparameters(),
                                     key=lambda t: t.name)
            instantiations = {hyperparameters[jdx+1].name: values[jdx]
                              for jdx in range(len(values))}

            evaluation = conj3.evaluate(instantiations)
            self.assertEqual(expected_outcomes[idx], evaluation)

            if not evaluation:
                self.assertRaisesRegex(ValueError,
                                       r"Inactive hyperparameter 'AND' must "
                                       r"not be specified, but has the vector value: "
                                       r"'0.0'.",
                                       Configuration, cs, values={
                                            "input1": values[0],
                                            "input2": values[1],
                                            "input3": values[2],
                                            "input4": values[3],
                                            "input5": values[4],
                                            "AND": "True"})
            else:
                Configuration(cs, values={"input1": values[0],
                                          "input2": values[1],
                                          "input3": values[2],
                                          "input4": values[3],
                                          "input5": values[4],
                                          "AND": "True"})
开发者ID:automl,项目名称:ConfigSpace,代码行数:80,代码来源:test_configuration_space.py


注:本文中的ConfigSpace.ConfigurationSpace.get_hyperparameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。