예제 #1
0
def test_get_bounds_numpy_error(array_params):
    with pytest.raises(InvalidBoundsError):
        get_bounds(
            array_params,
            # lower bounds larger than upper bounds
            lower_bounds=np.ones_like(array_params),
            upper_bounds=np.zeros_like(array_params),
        )
예제 #2
0
def test_get_bounds_numpy(array_params):
    got_lower, got_upper = get_bounds(array_params)

    expected = np.array([np.inf, np.inf])

    assert_array_equal(got_lower, -expected)
    assert_array_equal(got_upper, expected)
예제 #3
0
def test_get_bounds_no_arguments(pytree_params):
    got_lower, got_upper = get_bounds(pytree_params)

    expected_lower = np.array([-np.inf] + 3 * [0] + 4 * [-np.inf])
    expected_upper = np.full(8, np.inf)

    assert_array_equal(got_lower, expected_lower)
    assert_array_equal(got_upper, expected_upper)
예제 #4
0
def test_get_bounds_with_lower_bounds(pytree_params):
    lower_bounds = {"delta": 0.1}

    got_lower, got_upper = get_bounds(pytree_params, lower_bounds=lower_bounds)

    expected_lower = np.array([0.1] + 3 * [0] + 4 * [-np.inf])
    expected_upper = np.full(8, np.inf)

    assert_array_equal(got_lower, expected_lower)
    assert_array_equal(got_upper, expected_upper)
예제 #5
0
def test_get_bounds_with_upper_bounds(pytree_params):
    upper_bounds = {
        "utility":
        pd.DataFrame([[1]] * 3, index=["a", "b", "c"], columns=["value"]),
    }
    got_lower, got_upper = get_bounds(pytree_params, upper_bounds=upper_bounds)

    expected_lower = np.array([-np.inf] + 3 * [0] + 4 * [-np.inf])
    expected_upper = np.array([np.inf] + 3 * [1] + 4 * [np.inf])

    assert_array_equal(got_lower, expected_lower)
    assert_array_equal(got_upper, expected_upper)
예제 #6
0
def test_get_bounds_subdataframe(pytree_params):
    upper_bounds = {
        "utility": pd.DataFrame([[2]] * 2, index=["b", "c"],
                                columns=["value"]),
    }
    lower_bounds = {
        "delta": 0,
        "utility": pd.DataFrame([[1]] * 2, index=["a", "b"],
                                columns=["value"]),
    }
    lb, ub = get_bounds(pytree_params,
                        lower_bounds=lower_bounds,
                        upper_bounds=upper_bounds)

    assert np.all(lb[1:3] == np.ones(2))
    assert np.all(ub[2:4] == 2 * np.ones(2))
예제 #7
0
def test_get_bounds_error(pytree_params, lower_bounds, upper_bounds):
    with pytest.raises(InvalidBoundsError):
        get_bounds(pytree_params,
                   lower_bounds=lower_bounds,
                   upper_bounds=upper_bounds)