Beispiel #1
0
def test_reverse_log_sampling_random_state():
    f = hp_module.Float('f', 1e-3, 1e3, sampling='reverse_log')
    rand_sample = f.random_sample()
    assert rand_sample >= f.min_value
    assert rand_sample <= f.max_value

    val = 1e-3
    prob = hp_module.value_to_cumulative_prob(val, f)
    assert prob == 0
    new_val = hp_module.cumulative_prob_to_value(prob, f)
    assert np.isclose(val, new_val)

    val = 1
    prob = hp_module.value_to_cumulative_prob(val, f)
    assert prob > 0 and prob < 1
    new_val = hp_module.cumulative_prob_to_value(prob, f)
    assert np.isclose(val, new_val)
def test_log_sampling_random_state():
    f = hp_module.Float("f", 1e-3, 1e3, sampling="log")
    rand_sample = f.random_sample()
    assert rand_sample >= f.min_value
    assert rand_sample <= f.max_value

    val = 1e-3
    prob = hp_module.value_to_cumulative_prob(val, f)
    assert prob == 0
    new_val = hp_module.cumulative_prob_to_value(prob, f)
    assert np.isclose(val, new_val)

    val = 1
    prob = hp_module.value_to_cumulative_prob(val, f)
    assert prob == 0.5
    new_val = hp_module.cumulative_prob_to_value(prob, f)
    assert np.isclose(val, new_val)

    val = 1e3
    prob = hp_module.value_to_cumulative_prob(val, f)
    assert prob == 1
    new_val = hp_module.cumulative_prob_to_value(prob, f)
    assert np.isclose(val, new_val)