Ejemplo n.º 1
0
def test_hammersly():
    h = Hammersly()
    x = h.generate([
        (0., 1.),
    ] * 2, 4)
    y = np.array([[0, 0], [1 / 2, 0.25], [1 / 4, 0.5], [3 / 4, 0.75]])
    assert_almost_equal(x, y)

    samples = h.generate([
        (0., 1.),
    ] * 2, 200)
    assert len(samples) == 200
    assert len(samples[0]) == 2
Ejemplo n.º 2
0
def test_skopt():
    space = Space([(0.0, 1.0)])
    for i in range(TESTS):
        prime_idx = randint(0, MAX_BASE)
        hammer = Hammersley(prime_idx)
        skhammer = SkoptHammersley(0, 0, [PRIME_VECTOR[prime_idx]])
        h1 = hammer.get_array(SIZE)
        h2 = np.squeeze(skhammer.generate(space.dimensions, SIZE))
        assert np.allclose(h1, h2)
Ejemplo n.º 3
0
def test_hammersly():
    h = Hammersly()
    x = h.generate([
        (0., 1.),
    ] * 2, 3)
    y = np.array([[0.75, 0.125, 0.625], [0.25, 0.5, 0.75]]).T
    assert_almost_equal(x, y)
    x = h.generate([
        (0., 1.),
    ] * 2, 4)
    y = np.array([[0.75, 0.125, 0.625, 0.375], [0.2, 0.4, 0.6, 0.8]]).T
    assert_almost_equal(x, y)

    samples = h.generate([
        (0., 1.),
    ] * 2, 200)
    assert len(samples) == 200
    assert len(samples[0]) == 2
#############################################################################
# Halton sampling
# ---------------

halton = Halton()
x = halton.generate(space.dimensions, n_samples)
plot_searchspace(x, 'Halton')
pdist_data.append(pdist(x).flatten())
x_label.append("halton")

#############################################################################
# Hammersly sampling
# ------------------

hammersly = Hammersly()
x = hammersly.generate(space.dimensions, n_samples)
plot_searchspace(x, 'Hammersly')
pdist_data.append(pdist(x).flatten())
x_label.append("hammersly")

#############################################################################
# Grid sampling
# -------------

grid = Grid(border="include", use_full_layout=False)
x = grid.generate(space.dimensions, n_samples)
plot_searchspace(x, 'Grid')
pdist_data.append(pdist(x).flatten())
x_label.append("grid")

#############################################################################