コード例 #1
0
ファイル: test_subproblem.py プロジェクト: jvanhoefer/fides
def test_convex_subproblem(subproblem):
    delta = 1.151
    s, case = solve_nd_trust_region_subproblem(subproblem['B'],
                                               subproblem['g'], delta)
    assert np.all(np.real(linalg.eig(subproblem['B'])[0]) > 0)
    assert norm(s) < delta
    assert case == 'posdef'
    assert is_local_quad_min(s, subproblem['B'], subproblem['g'])
コード例 #2
0
def test_convex_subproblem(subproblem):
    delta = 1.151
    s, case = solve_nd_trust_region_subproblem(subproblem['B'],
                                               subproblem['g'], delta)
    assert np.all(np.real(linalg.eig(subproblem['B'])[0]) > 0)
    assert norm(s) < delta
    assert case == 'posdef'
    assert is_local_quad_min(s, subproblem['B'], subproblem['g'])

    for alpha in [0, 0.5, -0.5]:
        sc = solve_1d_trust_region_subproblem(subproblem['B'], subproblem['g'],
                                              s, delta, alpha * s)[0]
        assert sc + alpha == 1
コード例 #3
0
def test_nonconvex_subproblem_eigvals(subproblem, minev):
    subproblem['B'][0, 0] = -minev
    delta = 1.0
    s, case = solve_nd_trust_region_subproblem(subproblem['B'],
                                               subproblem['g'], delta)
    assert np.any(np.real(linalg.eig(subproblem['B'])[0]) < 0)
    assert np.isclose(norm(s), delta, atol=1e-6, rtol=0)
    assert is_bound_quad_min(s, subproblem['B'], subproblem['g'])
    assert not is_bound_quad_min(-s, subproblem['B'], subproblem['g'])

    for alpha in [0, 0.5, -0.5]:
        sc = solve_1d_trust_region_subproblem(subproblem['B'], subproblem['g'],
                                              s, delta, alpha * s)[0]
        assert np.isclose(sc + alpha, 1)
コード例 #4
0
def test_nonconvex_subproblem_eigvals(subproblem, minev):
    subproblem['B'][0, 0] = -minev
    delta = 1.0
    s, case = solve_nd_trust_region_subproblem(subproblem['B'],
                                               subproblem['g'], delta)
    assert np.any(np.real(linalg.eig(subproblem['B'])[0]) < 0)
    assert np.isclose(norm(s), delta, atol=1e-6, rtol=0)
    assert is_bound_quad_min(s, subproblem['B'], subproblem['g'])

    snorm = s.copy()
    normalize(snorm)
    for alpha in [0, 0.5, -0.5]:
        assert np.isclose(solve_1d_trust_region_subproblem(
            subproblem['B'], subproblem['g'], snorm, delta, alpha * s
        )[0], (1 - alpha)*delta)
コード例 #5
0
def test_hard_hard_subproblem(subproblem):
    subproblem['B'][0, 0] = -1.0
    subproblem['g'][0] = 0.0
    delta = 0.5
    s, case = solve_nd_trust_region_subproblem(subproblem['B'],
                                               subproblem['g'], delta)
    assert np.any(np.real(linalg.eig(subproblem['B'])[0]) < 0)
    assert np.isclose(norm(s), delta, atol=1e-6, rtol=0)
    assert case == 'hard'
    assert is_bound_quad_min(s, subproblem['B'], subproblem['g'])

    snorm = s.copy()
    normalize(snorm)
    for alpha in [0, 0.5, -0.5]:
        assert np.isclose(solve_1d_trust_region_subproblem(
            subproblem['B'], subproblem['g'], snorm, delta, alpha * s
        )[0], (1 - alpha)*delta)