def test_categorical_is_legal(self):
        f1 = CategoricalHyperparameter("param", ["a", "b"])
        self.assertTrue(f1.is_legal("a"))
        self.assertTrue(f1.is_legal(u"a"))
        self.assertFalse(f1.is_legal("c"))
        self.assertFalse(f1.is_legal(3))

        # Test is legal vector
        self.assertTrue(f1.is_legal_vector(1.0))
        self.assertTrue(f1.is_legal_vector(0.0))
        self.assertTrue(f1.is_legal_vector(0))
        self.assertFalse(f1.is_legal_vector(0.3))
        self.assertFalse(f1.is_legal_vector(-0.1))
        self.assertRaises(TypeError, f1.is_legal_vector, "Hahaha")
Ejemplo n.º 2
0
    def test_categorical_is_legal(self):
        f1 = CategoricalHyperparameter("param", ["a", "b"])
        self.assertTrue(f1.is_legal("a"))
        self.assertTrue(f1.is_legal(u"a"))
        self.assertFalse(f1.is_legal("c"))
        self.assertFalse(f1.is_legal(3))

        # Test is legal vector
        self.assertTrue(f1.is_legal_vector(1.0))
        self.assertTrue(f1.is_legal_vector(0.0))
        self.assertTrue(f1.is_legal_vector(0))
        self.assertFalse(f1.is_legal_vector(0.3))
        self.assertFalse(f1.is_legal_vector(-0.1))
        self.assertRaises(TypeError, f1.is_legal_vector, "Hahaha")
Ejemplo n.º 3
0
    def test_categorical_callable(self):
        def fn_1():
            return 1

        def fn_2():
            return 2

        f1 = CategoricalHyperparameter("param", [fn_1, fn_2])
        f1_ = CategoricalHyperparameter("param", [fn_1, fn_2])
        self.assertEqual(f1, f1_)
        self.assertEqual(
            "param, Type: Categorical, Choices: {{{}, {}}}, Default: {}".
            format(fn_1, fn_2, fn_1), str(f1))

        f2 = CategoricalHyperparameter("param", [fn_2, fn_1])
        self.assertNotEqual(f1, f2)

        def fn_3():
            return 3

        self.assertTrue(f1.is_legal(fn_1))
        self.assertTrue(f1.is_legal(fn_2))
        self.assertFalse(f1.is_legal(fn_3))
        self.assertFalse(f1.is_legal(fn_1()))
Ejemplo n.º 4
0
 def test_categorical_is_legal(self):
     f1 = CategoricalHyperparameter("param", ["a", "b"])
     self.assertTrue(f1.is_legal("a"))
     self.assertTrue(f1.is_legal(u"a"))
     self.assertFalse(f1.is_legal("c"))
     self.assertFalse(f1.is_legal(3))