예제 #1
0
파일: test_alg.py 프로젝트: suiy02/sigpy
    def test_ConjugateGradient(self):
        n = 5
        lamda = 0.1
        A, x_numpy, y = self.Ax_y_setup(n, lamda)
        x = np.zeros([n])
        alg_method = alg.ConjugateGradient(
            lambda x: A.T @ A @ x + lamda * x,
            A.T @ y, x, max_iter=1000)
        while(not alg_method.done()):
            alg_method.update()

        npt.assert_allclose(x, x_numpy)
예제 #2
0
파일: alg_test.py 프로젝트: jtamir/sigpy
    def test_ConjugateGradient(self):
        n = 5
        A = np.random.random([n, n])
        x_orig = np.random.random([n])
        y = np.matmul(A, x_orig)
        x_truth = np.linalg.solve(np.matmul(A.T, A), np.matmul(A.T, y))

        x = np.zeros([n])
        alg_method = alg.ConjugateGradient(
            lambda x: np.matmul(A.T, np.matmul(A, x)), np.matmul(A.T, y), x)
        while (not alg_method.done()):
            alg_method.update()

        npt.assert_allclose(x, x_truth, atol=1, rtol=1e-3)