예제 #1
0
    def test_read_new_configuration_space_forbidden(self):
        cs_with_forbidden = ConfigurationSpace()
        int_hp = UniformIntegerHyperparameter('int_hp', 0, 50, 30)
        float_hp = UniformFloatHyperparameter('float_hp', 0., 50., 30.)
        cat_hp_str = CategoricalHyperparameter('cat_hp_str', ['a', 'b', 'c'], 'b')
        ord_hp_str = OrdinalHyperparameter('ord_hp_str', ['a', 'b', 'c'], 'b')

        cs_with_forbidden.add_hyperparameters([int_hp, float_hp, cat_hp_str, ord_hp_str])

        int_hp_forbidden = ForbiddenAndConjunction(ForbiddenEqualsClause(int_hp, 1))

        float_hp_forbidden_1 = ForbiddenEqualsClause(float_hp, 1.0)
        float_hp_forbidden_2 = ForbiddenEqualsClause(float_hp, 2.0)
        float_hp_forbidden = ForbiddenAndConjunction(float_hp_forbidden_1, float_hp_forbidden_2)

        cat_hp_str_forbidden = ForbiddenAndConjunction(ForbiddenEqualsClause(cat_hp_str, 'a'))
        ord_hp_float_forbidden = ForbiddenAndConjunction(ForbiddenEqualsClause(ord_hp_str, 'a'))
        cs_with_forbidden.add_forbidden_clauses([int_hp_forbidden, float_hp_forbidden,
                                                 cat_hp_str_forbidden, ord_hp_float_forbidden])

        complex_cs = list()
        complex_cs.append("int_hp integer [0,50] [30]")
        complex_cs.append("float_hp real [0.0, 50.0] [30.0]")
        complex_cs.append("cat_hp_str categorical {a, b, c} [b]")
        complex_cs.append("ord_hp_str ordinal {a, b, c} [b]")
        complex_cs.append("# Forbiddens:")
        complex_cs.append("{int_hp=1}")
        complex_cs.append("{float_hp=1.0, float_hp=2.0}")
        complex_cs.append("{cat_hp_str=a}")
        complex_cs.append("{ord_hp_str=a}")
        cs_new = pcs_new.read(complex_cs)

        self.assertEqual(cs_new, cs_with_forbidden)
예제 #2
0
    def test_write_forbidden(self):
        cs = ConfigurationSpace()

        hp1 = CategoricalHyperparameter("parent", [0, 1])
        hp2 = UniformIntegerHyperparameter("child", 0, 2)
        hp3 = UniformIntegerHyperparameter("child2", 0, 2)
        hp4 = UniformIntegerHyperparameter("child3", 0, 2)
        hp5 = CategoricalHyperparameter("child4", [4, 5, 6, 7])

        cs.add_hyperparameters([hp1, hp2, hp3, hp4, hp5])

        forb2 = ForbiddenEqualsClause(hp1, 1)
        forb3 = ForbiddenInClause(hp2, range(2, 3))
        forb4 = ForbiddenInClause(hp3, range(2, 3))
        forb5 = ForbiddenInClause(hp4, range(2, 3))
        forb6 = ForbiddenInClause(hp5, [6, 7])

        and1 = ForbiddenAndConjunction(forb2, forb3)
        and2 = ForbiddenAndConjunction(forb2, forb4)
        and3 = ForbiddenAndConjunction(forb2, forb5)

        cs.add_forbidden_clauses(
            [forb2, forb3, forb4, forb5, forb6, and1, and2, and3])

        irace.write(cs)  # generates file called forbidden.txt
예제 #3
0
    def test_write_forbidden(self):
        cs = ConfigurationSpace()

        hp1 = CategoricalHyperparameter("parent", [0, 1])
        hp2 = UniformIntegerHyperparameter("child", 0, 2)
        hp3 = UniformIntegerHyperparameter("child2", 0, 2)
        hp4 = UniformIntegerHyperparameter("child3", 0, 2)
        hp5 = CategoricalHyperparameter("child4", [4, 5, 6, 7])

        cs.add_hyperparameters([hp1, hp2, hp3, hp4, hp5])

        forb2 = ForbiddenEqualsClause(hp1, 1)
        forb3 = ForbiddenInClause(hp2, range(2, 3))
        forb4 = ForbiddenInClause(hp3, range(2, 3))
        forb5 = ForbiddenInClause(hp4, range(2, 3))
        forb6 = ForbiddenInClause(hp5, [6, 7])

        and1 = ForbiddenAndConjunction(forb2, forb3)
        and2 = ForbiddenAndConjunction(forb2, forb4)
        and3 = ForbiddenAndConjunction(forb2, forb5)

        cs.add_forbidden_clauses(
            [forb2, forb3, forb4, forb5, forb6, and1, and2, and3])

        irace.write(cs)  # generates file called forbidden.txt