def test_log_space_conversion(self): lower, upper = 1e-5, 1e5 hyper = UniformFloatHyperparameter('test', lower=lower, upper=upper, log=True) self.assertTrue(hyper.is_legal(hyper._transform(1.))) lower, upper = 1e-10, 1e10 hyper = UniformFloatHyperparameter('test', lower=lower, upper=upper, log=True) self.assertTrue(hyper.is_legal(hyper._transform(1.)))
def test_log_space_conversion(self): lower, upper = 1e-5, 1e5 hyper = UniformFloatHyperparameter('test', lower=lower, upper=upper, log=True) self.assertTrue(hyper.is_legal(hyper._transform(1.))) lower, upper = 1e-10, 1e10 hyper = UniformFloatHyperparameter('test', lower=lower, upper=upper, log=True) self.assertTrue(hyper.is_legal(hyper._transform(1.)))
def test_quantization_UniformFloatHyperparameter_decimal_numbers_negative(self): hp = UniformFloatHyperparameter("ufhp", -1.2, 1.2, q=0.2) rs = np.random.RandomState() sample_one = hp._sample(rs=rs, size=1) self.assertIsInstance(obj=sample_one, cls=np.ndarray) self.assertEqual(1, sample_one.size) try: self.assertAlmostEqual(float(hp._transform(sample_one) + 1.2) % 0.2, 0.0) except: self.assertAlmostEqual(float(hp._transform(sample_one) + 1.2) % 0.2, 0.2) self.assertGreaterEqual(hp._transform(sample_one), -1.2) self.assertLessEqual(hp._transform(sample_one), 1.2)
def test_quantization_UniformFloatHyperparameter(self): hp = UniformFloatHyperparameter("ufhp", 1, 100, q=3) rs = np.random.RandomState(1) sample_one = hp._sample(rs=rs, size=1) self.assertIsInstance(obj=sample_one, cls=np.ndarray) self.assertEqual(1, sample_one.size) self.assertTrue(hp._transform(sample_one) % 3 == 0) sample_hundred = hp._sample(rs=rs, size=100) self.assertIsInstance(obj=sample_hundred, cls=np.ndarray) self.assertEqual(100, sample_hundred.size) self.assertTrue( np.all(hp._transform(val) % 3 == 0 for val in sample_hundred))
def test_quantization_UniformFloatHyperparameter(self): hp = UniformFloatHyperparameter("ufhp", 1, 100, q=3) rs = np.random.RandomState() sample_one = hp._sample(rs=rs, size=1) self.assertIsInstance(obj=sample_one, cls=np.ndarray) self.assertEqual(1, sample_one.size) self.assertEqual((hp._transform(sample_one) - 1) % 3, 0) self.assertGreaterEqual(hp._transform(sample_one), 1) self.assertLessEqual(hp._transform(sample_one), 100) sample_hundred = hp._sample(rs=rs, size=100) self.assertIsInstance(obj=sample_hundred, cls=np.ndarray) self.assertEqual(100, sample_hundred.size) np.testing.assert_array_equal( [(hp._transform(val) - 1) % 3 for val in sample_hundred], np.zeros((100,), dtype=int), ) samples_in_original_space = hp._transform(sample_hundred) for i in range(100): self.assertGreaterEqual(samples_in_original_space[i], 1) self.assertLessEqual(samples_in_original_space[i], 100)