def test_set_bounds():
    pbounds = {
        'p1': (0, 1),
        'p3': (0, 3),
        'p2': (0, 2),
        'p4': (0, 4),
    }
    space = TargetSpace(target_func, pbounds)

    # Ignore unknown keys
    space.set_bounds({"other": (7, 8)})
    assert all(space.bounds[:, 0] == np.array([0, 0, 0, 0]))
    assert all(space.bounds[:, 1] == np.array([1, 2, 3, 4]))

    # Update bounds accordingly
    space.set_bounds({"p2": (1, 8)})
    assert all(space.bounds[:, 0] == np.array([0, 1, 0, 0]))
    assert all(space.bounds[:, 1] == np.array([1, 8, 3, 4]))
Beispiel #2
0
def test_set_bounds():
    pbounds = {'p1': (0, 1), 'p3': (0, 3), 'p2': (0, 2), 'p4': (0, 4)}
    ptypes = {'p1': int, 'p2': float, 'p3': int, 'p4': float}
    space = TargetSpace(target_func, pbounds, ptypes)

    # Ignore unknown keys
    space.set_bounds({"other": (7, 8)})
    assert all(space.bounds[:, 0] == np.array([0, 0, 0, 0]))
    assert all(space.bounds[:, 1] == np.array([1, 2, 3, 4]))

    # Update bounds accordingly
    space.set_bounds({"p3": (1.1, 8.7)})
    print(space.bounds)
    assert all(space.bounds[:, 0] == np.array([0, 0, 1, 0]))
    assert all(space.bounds[:, 1] == np.array([1, 2, 9, 4]))

    ptypes = None
    space = TargetSpace(target_func, pbounds, ptypes)
    space.set_bounds({"p3": (1.1, 8.7)})
    print(space.bounds)
    assert all(space.bounds[:, 0] == np.array([0, 0, 1.1, 0]))
    assert all(space.bounds[:, 1] == np.array([1, 2, 8.7, 4]))