def test_Range(): rg = hp_module.Range( 'rg', min_value=5, max_value=9, step=1, default=6) rg = hp_module.Range.from_config(rg.get_config()) assert rg.default == 6 assert 5 <= rg.random_sample() < 9 assert isinstance(rg.random_sample(), int) assert rg.random_sample(123) == rg.random_sample(123) # No default rg = hp_module.Range( 'rg', min_value=5, max_value=9, step=1) assert rg.default == 5
def test_bayesian_oracle_with_zero_y(tmp_dir): hp_list = [hp_module.Choice('a', [1, 2], default=1), hp_module.Range('b', 3, 10, default=3), hp_module.Linear('c', 0, 1, 0.1, default=0), hp_module.Fixed('d', 7), hp_module.Choice('e', [9, 0], default=9)] oracle = bo_module.BayesianOptimizationOracle() for i in range(100): oracle.populate_space(str(i), hp_list) oracle.result(str(i), 0)
def test_save_before_result(tmp_dir): hp_list = [ hp_module.Choice('a', [1, 2], default=1), hp_module.Range('b', 3, 10, default=3), hp_module.Linear('c', 0, 1, 0.1, default=0), hp_module.Fixed('d', 7), hp_module.Choice('e', [9, 0], default=9) ] oracle = bo_module.BayesianOptimizationOracle() oracle.populate_space(str(1), hp_list) oracle.save(os.path.join(tmp_dir, 'temp_oracle')) oracle.result(str(1), 0)
def test_bayesian_dynamic_space(tmp_dir): hp_list = [hp_module.Choice('a', [1, 2], default=1)] oracle = bo_module.BayesianOptimizationOracle() for i in range(10): oracle.populate_space(str(i), hp_list) oracle.result(str(i), i) hp_list.append(hp_module.Range('b', 3, 10, default=3)) assert 'b' in oracle.populate_space('1_0', hp_list)['values'] hp_list.append(hp_module.Linear('c', 0, 1, 0.1, default=0)) assert 'c' in oracle.populate_space('1_1', hp_list)['values'] hp_list.append(hp_module.Fixed('d', 7)) assert 'd' in oracle.populate_space('1_2', hp_list)['values'] hp_list.append(hp_module.Choice('e', [9, 0], default=9)) assert 'e' in oracle.populate_space('1_3', hp_list)['values']