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)
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)