示例#1
0
 def test_pgs_solver_2(self):
     n = 7
     A = np.diag(np.arange(7) + 1).astype(float)
     print(A)
     b = np.array([-1, 4, 4, 2, -3, 7, -5]).astype(float) # Seems less stable with zeros in b
     real_z = np.array([1, 0, 0, 0, 0.6, 0, 5 / 7])
     real_w = np.array([0, 4, 4, 2, 0, 7, 0])
     z = solve_LCP_with_pgs(A, b)
     print(z)
     print(z - real_z[:, None])
     w = np.dot(A, z) + b[:, None]
     assert np.dot(w.T, z) < 0.00001
     assert np.allclose(real_z[:, None], z)
     assert np.allclose(real_w[:, None], w)
示例#2
0
 def test_pgs_solver_1(self):
     n = 5
     e = np.ones(n)
     A = np.diag(-e[:-1], 1) + np.diag(-e[:-1], -1) + np.diag(2. * e, 0)
     b = np.array([1, -3, 0, 4, -2]).astype(float)
     real_z = np.array([0.75, 2.5, 1.25, 0, 1])
     real_w = np.array([0, 0, 0, 1.75, 0])
     z = solve_LCP_with_pgs(A, b)
     print(z - real_z[:, None])
     w = np.dot(A, z) + b[:, None]
     assert np.dot(w.T, z) < 0.00001
     assert np.allclose(real_z[:, None], z)
     # Maybe set our own tolerance?
     assert np.allclose(real_w[:, None], w)
示例#3
0
 def test_pgs_solver_1(self):
     n = 5
     e = np.ones(n)
     A = np.diag(-e[:-1], 1) + np.diag(-e[:-1], -1) + np.diag(2. * e, 0)
     b = np.array([1, -3, 0, 4, -2]).astype(float)
     real_z = np.array([0.75, 2.5, 1.25, 0, 1])
     real_w = np.array([0, 0, 0, 1.75, 0])
     z = solve_LCP_with_pgs(A, b)
     print(z - real_z[:, None])
     w = np.dot(A, z) + b[:, None]
     assert np.dot(w.T, z) < 0.00001
     assert np.allclose(real_z[:, None], z)
     # Maybe set our own tolerance?
     assert np.allclose(real_w[:, None], w)
示例#4
0
 def test_pgs_solver_2(self):
     n = 7
     A = np.diag(np.arange(7) + 1).astype(float)
     print(A)
     b = np.array([-1, 4, 4, 2, -3, 7,
                   -5]).astype(float)  # Seems less stable with zeros in b
     real_z = np.array([1, 0, 0, 0, 0.6, 0, 5 / 7])
     real_w = np.array([0, 4, 4, 2, 0, 7, 0])
     z = solve_LCP_with_pgs(A, b)
     print(z)
     print(z - real_z[:, None])
     w = np.dot(A, z) + b[:, None]
     assert np.dot(w.T, z) < 0.00001
     assert np.allclose(real_z[:, None], z)
     assert np.allclose(real_w[:, None], w)