Ejemplo n.º 1
0
def test_Linear():
    linear = hp_module.Linear(
        'linear', min_value=0.5, max_value=9.5, resolution=0.1, default=9.)
    linear = hp_module.Linear.from_config(linear.get_config())
    assert linear.default == 9.
    assert 0.5 <= linear.random_sample() < 9.5
    assert isinstance(linear.random_sample(), float)
    assert linear.random_sample(123) == linear.random_sample(123)
    # No default
    linear = hp_module.Linear(
        'linear', min_value=0.5, max_value=9.5, resolution=0.1)
    assert linear.default == 0.5
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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']