示例#1
0
def test_continuous_normal_sample():
    h1 = hp.NormalContinuousHyperParameter('h1', 0.0, 1.0)
    sample = [h1.sample() for _ in range(10000)]
    mean = np.mean(sample)
    std = np.std(sample)
    assert np.allclose(mean, 0.0, atol=0.025)
    assert np.allclose(std, 1.0, atol=0.025)
示例#2
0
def test_continuous_normal():
    h1 = hp.NormalContinuousHyperParameter('h1', 0.0, 1.0)

    assert h1.name == 'h1'
    assert h1.num_choices == 0
    assert h1.mean == 0.0
    assert h1.std == 1.0
    assert repr(h1)
示例#3
0
def test_continuous_normal_encode_decode():
    h1 = hp.NormalContinuousHyperParameter('h1', 0.0, 1.0)
    sample = h1.sample()

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

    decoded = h1.decode(encoded)
    assert decoded == sample
示例#4
0
def test_normal_serialization_deserialization():
    h1 = hp.NormalContinuousHyperParameter('h1', 0.0, 1.0)

    config = h1.get_config()
    assert 'name' in config
    assert 'mean' in config
    assert 'std' in config

    mean, std = config['mean'], config['std']
    assert mean == 0.0
    assert std == 1.0

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

    assert 'name' in config
    assert 'mean' in config
    assert 'std' in config

    mean, std = config['mean'], config['std']
    assert mean == 0.0
    assert std == 1.0
示例#5
0
def test_continuous_normal_no_values():
    with pytest.raises(ValueError):
        hp.NormalContinuousHyperParameter(None, 0, 1)

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