Beispiel #1
0
def test_continuous_multi_uniform_sample():
    h1 = hp.MultiUniformContinuousHyperParameter('h1',
                                                 0.0,
                                                 1.0,
                                                 sample_count=5)
    samples = h1.sample()
    assert all([0.0 <= sample and sample < 1.0 for sample in samples])
Beispiel #2
0
def test_multi_uniform_serialization_deserialization():
    h1 = hp.MultiUniformContinuousHyperParameter('h1',
                                                 0.0,
                                                 1.0,
                                                 log_encode=True,
                                                 sample_count=5)

    config = h1.get_config()
    assert 'name' in config
    assert 'min_value' in config
    assert 'max_value' in config
    assert 'log_encode' in config
    assert 'sample_count' in config

    min, max = config['min_value'], config['max_value']
    assert min == 0.0
    assert max == 1.0
    assert config['sample_count'] == 5

    h2 = hp.MultiUniformContinuousHyperParameter.load_from_config(config)
    config = h2.get_config()

    assert 'name' in config
    assert 'min_value' in config
    assert 'max_value' in config
    assert 'log_encode' in config
    assert 'sample_count' in config

    min, max = config['min_value'], config['max_value']
    assert min == 0.0
    assert max == 1.0
    assert config['sample_count'] == 5
Beispiel #3
0
def test_continuous_multi_uniform_encode_decode():
    h1 = hp.MultiUniformContinuousHyperParameter('h1',
                                                 0.0,
                                                 1.0,
                                                 sample_count=5)
    sample = h1.sample()

    encoded = h1.encode(sample)
    assert encoded == sample

    decoded = h1.decode(encoded)
    assert decoded == sample
Beispiel #4
0
def test_continuous_multi_uniform():
    h1 = hp.MultiUniformContinuousHyperParameter('h1',
                                                 0.0,
                                                 1.0,
                                                 sample_count=5)

    assert h1.name == 'h1'
    assert h1.num_choices == 0
    assert h1.min_value == 0.0
    assert h1.max_value == 1.0
    assert repr(h1)
    assert h1.sample_count == 5
def test_continuous_uniform_encode_decode_log_space():
    h1 = hp.MultiUniformContinuousHyperParameter('h1',
                                                 0.0,
                                                 1.0,
                                                 log_encode=True,
                                                 sample_count=3)
    sample = h1.sample()

    encoded = h1.encode(sample)
    assert encoded == [
        -0.5999965965916227, -0.3352079232808751, -0.5062305704264942
    ]

    decoded = h1.decode(encoded)
    assert decoded == sample
Beispiel #6
0
def test_continuous_multi_uniform_no_values():
    with pytest.raises(ValueError):
        hp.MultiUniformContinuousHyperParameter(None, 0, 1)

    with pytest.raises(ValueError):
        hp.MultiUniformContinuousHyperParameter('h1', None, None)
Beispiel #7
0
def get_multi_parameter_list():
    h1 = hp.MultiDiscreteHyperParameter('h1', [0, 1, 2], sample_count=2)
    h2 = hp.MultiDiscreteHyperParameter('h2', [3, 4, 5, 6], sample_count=3)
    h3 = hp.MultiUniformContinuousHyperParameter('h3', 7, 10, sample_count=5)
    h4 = hp.MultiDiscreteHyperParameter('h4', ['v1', 'v2'], sample_count=4)
    return [h1, h2, h3, h4]