Beispiel #1
0
def test_abstract_multi_continuous_sample():
    h1 = hp.AbstractMultiContinuousHyperParameter('h1',
                                                  0.0,
                                                  1.0,
                                                  sample_count=5)

    with pytest.raises(NotImplementedError):
        sample = h1.sample()
Beispiel #2
0
def test_abstact_multi_continuous_encode_decode():
    h1 = hp.AbstractMultiContinuousHyperParameter('h1',
                                                  0.0,
                                                  1.0,
                                                  sample_count=5)

    encoded = h1.encode([0.5, 0.2, 0.1, 0.3, 0.7])
    assert encoded == [0.5, 0.2, 0.1, 0.3, 0.7]

    decoded = h1.decode(encoded)
    assert decoded == [0.5, 0.2, 0.1, 0.3, 0.7]
Beispiel #3
0
def test_abstract_multi_continuous():
    h1 = hp.AbstractMultiContinuousHyperParameter('h1',
                                                  0.0,
                                                  1.0,
                                                  sample_count=5)

    assert h1.name == 'h1'
    assert h1.num_choices == 0
    assert h1._val1 == 0.0
    assert h1._val2 == 1.0
    assert repr(h1)
    assert h1.sample_count == 5
Beispiel #4
0
def test_abstract_multi_continuous_log_space_encode_decode():
    h1 = hp.AbstractMultiContinuousHyperParameter('h1',
                                                  0.0,
                                                  1.0,
                                                  log_encode=True,
                                                  sample_count=5)

    encoded = h1.encode([0.5, 0.2, 0.1, 0.3, 0.7])
    assert np.allclose(encoded, [
        -0.6931471805599453, -1.6094379124341003, -2.3025850929940455,
        -1.2039728043259361, -0.35667494393873245
    ],
                       atol=1e-2)

    decoded = h1.decode(encoded)
    assert np.allclose(decoded, [0.5, 0.2, 0.1, 0.3, 0.7], atol=1e-3)

    encoded = h1.encode([0.0])
    assert encoded == [-np.inf]

    decoded = h1.decode(encoded)
    assert decoded == [0.0]
Beispiel #5
0
def test_abstract_multi_continuous_no_values():
    with pytest.raises(ValueError):
        hp.AbstractMultiContinuousHyperParameter(None, 0, 1)

    with pytest.raises(ValueError):
        hp.AbstractMultiContinuousHyperParameter('h1', None, None)