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


Python ConfigurationSpace.get_default_configuration方法代码示例

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


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

示例1: test_setitem

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_default_configuration [as 别名]
    def test_setitem(self):
        '''
        Checks overriding a sampled configuration
        '''
        pcs = ConfigurationSpace()
        pcs.add_hyperparameter(UniformIntegerHyperparameter('x0', 1, 5, default_value=1))
        x1 = pcs.add_hyperparameter(CategoricalHyperparameter('x1', ['ab', 'bc', 'cd', 'de'], default_value='ab'))

        # Condition
        x2 = pcs.add_hyperparameter(CategoricalHyperparameter('x2', [1, 2]))
        pcs.add_condition(EqualsCondition(x2, x1, 'ab'))

        # Forbidden
        x3 = pcs.add_hyperparameter(CategoricalHyperparameter('x3', [1, 2]))
        pcs.add_forbidden_clause(ForbiddenEqualsClause(x3, 2))

        conf = pcs.get_default_configuration()

        # failed because it's a invalid configuration
        with self.assertRaisesRegex(ValueError, "Illegal value '0' for hyperparameter x0"):
            conf['x0'] = 0

        # failed because the variable didn't exists
        with self.assertRaisesRegex(KeyError, "Hyperparameter 'x_0' does not exist in this configuration space."):
            conf['x_0'] = 1

        # failed because forbidden clause is violated
        with self.assertRaisesRegex(ForbiddenValueError, "Given vector violates forbidden clause Forbidden: x3 == 2"):
            conf['x3'] = 2
        self.assertEqual(conf['x3'], 1)

        # successful operation 1
        x0_old = conf['x0']
        if x0_old == 1:
            conf['x0'] = 2
        else:
            conf['x0'] = 1
        x0_new = conf['x0']
        self.assertNotEqual(x0_old, x0_new)
        pcs._check_configuration_rigorous(conf)
        self.assertEqual(conf['x2'], 1)

        # successful operation 2
        x1_old = conf['x1']
        if x1_old == 'ab':
            conf['x1'] = 'cd'
        else:
            conf['x1'] = 'ab'
        x1_new = conf['x1']
        self.assertNotEqual(x1_old, x1_new)
        pcs._check_configuration_rigorous(conf)
        self.assertRaises(KeyError, conf.__getitem__, 'x2')
开发者ID:automl,项目名称:ConfigSpace,代码行数:54,代码来源:test_configuration_space.py

示例2: _test_get_one_exchange_neighbourhood

# 需要导入模块: from ConfigSpace import ConfigurationSpace [as 别名]
# 或者: from ConfigSpace.ConfigurationSpace import get_default_configuration [as 别名]
    def _test_get_one_exchange_neighbourhood(self, hp):
        cs = ConfigurationSpace()
        num_neighbors = 0
        if not isinstance(hp, list):
            hp = [hp]
        for hp_ in hp:
            cs.add_hyperparameter(hp_)
            if np.isinf(hp_.get_num_neighbors()):
                num_neighbors += 4
            else:
                num_neighbors += hp_.get_num_neighbors()

        cs.seed(1)
        config = cs.get_default_configuration()
        all_neighbors = []
        for i in range(100):
            neighborhood = get_one_exchange_neighbourhood(config, i)
            for new_config in neighborhood:
                self.assertNotEqual(config, new_config)
                all_neighbors.append(new_config)

        return all_neighbors
开发者ID:automl,项目名称:ConfigSpace,代码行数:24,代码来源:test_util.py


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