def test_not_equals_condition(self): hp1 = CategoricalHyperparameter("parent", [0, 1]) hp2 = UniformIntegerHyperparameter("child", 0, 10) cond = NotEqualsCondition(hp2, hp1, 0) cond_ = NotEqualsCondition(hp2, hp1, 0) self.assertEqual(cond, cond_) # Test vector value: self.assertEqual(cond.vector_value, hp1._inverse_transform(0)) self.assertEqual(cond.vector_value, cond_.vector_value) cond_reverse = NotEqualsCondition(hp1, hp2, 0) self.assertNotEqual(cond, cond_reverse) self.assertNotEqual(cond, dict()) self.assertEqual("child | parent != 0", str(cond))
def test_in_condition(self): hp1 = CategoricalHyperparameter("parent", list(range(0, 11))) hp2 = UniformIntegerHyperparameter("child", 0, 10) cond = InCondition(hp2, hp1, [0, 1, 2, 3, 4, 5]) cond_ = InCondition(hp2, hp1, [0, 1, 2, 3, 4, 5]) self.assertEqual(cond, cond_) # Test vector value: self.assertEqual( cond.vector_values, [hp1._inverse_transform(i) for i in [0, 1, 2, 3, 4, 5]]) self.assertEqual(cond.vector_values, cond_.vector_values) cond_reverse = InCondition(hp1, hp2, [0, 1, 2, 3, 4, 5]) self.assertNotEqual(cond, cond_reverse) self.assertNotEqual(cond, dict()) self.assertEqual("child | parent in {0, 1, 2, 3, 4, 5}", str(cond))
def test_equals_condition(self): hp1 = CategoricalHyperparameter("parent", [0, 1]) hp2 = UniformIntegerHyperparameter("child", 0, 10) cond = EqualsCondition(hp2, hp1, 0) cond_ = EqualsCondition(hp2, hp1, 0) # Test vector value: self.assertEqual(cond.vector_value, hp1._inverse_transform(0)) self.assertEqual(cond.vector_value, cond_.vector_value) # Test invalid conditions: self.assertRaises(TypeError, EqualsCondition, hp2, "parent", 0) self.assertRaises(TypeError, EqualsCondition, "child", hp1, 0) self.assertRaises(ValueError, EqualsCondition, hp1, hp1, 0) self.assertEqual(cond, cond_) cond_reverse = EqualsCondition(hp1, hp2, 0) self.assertNotEqual(cond, cond_reverse) self.assertNotEqual(cond, dict()) self.assertEqual("child | parent == 0", str(cond))