示例#1
0
def test_spd_inv_sqrt(spd_matrix, epsilon, method, return_rank):
    M = spd_inv_sqrt(spd_matrix,
                     epsilon=epsilon,
                     method=method,
                     return_rank=return_rank)
    if return_rank:
        rank = M[1]
        M = M[0]

        assert_equal(rank, 3)

    assert_array_almost_equal(M @ M.T, spd_inv(spd_matrix))
示例#2
0
def test_spd_inv_1d():
    with assert_raises(ZeroRankError):
        spd_inv(np.array([[1e-18]]), epsilon=1e-10)  # smaller than epsilon

    assert_almost_equal(spd_inv(np.array([[5]])), 1 / 5)
示例#3
0
def test_spd_inv(spd_matrix, epsilon, method):
    W = spd_inv(spd_matrix, epsilon=epsilon, method=method)
    sm, _ = spd_eig(spd_matrix)
    sminv, _ = spd_eig(W)
    assert_array_almost_equal(np.sort(sm), np.sort(1. / sminv))