def test_range_using_modified_gram_schmidt(self): A = np.random.randn(50, 10).dot(np.random.randn(10, 50)) Q = randomized_svd.adaptive_range( A, power_iter_k=0, power_iter_p=0, method='modified_gram_schmidt', k=5, p=10, eps=1e-7) self.assertLess(la.norm(A - Q.dot(Q.T.dot(A)), 2), 1e-7)
def test_adaptive_range_low_rank_5(self): A = np.random.randn(200, 150).dot(np.random.randn(150, 200)) Q = randomized_svd.adaptive_range(A, 1e-9, method='modified_gram_schmidt') self.assertEqual(Q.shape[1], 150)
def test_adaptive_range_nonsquare_horz(self): A = np.random.randn(10, 50) Q = randomized_svd.adaptive_range(A, 1e-9) self.assertEqual(Q.shape, (10, 10))
def test_adaptive_range_low_rank_2(self): A = np.random.randn(50, 30).dot(np.random.randn(30, 50)) Q = randomized_svd.adaptive_range(A, 1e-9) self.assertGreater(Q.shape[1], 20)
def test_adaptive_range_low_rank_4(self): A = np.random.randn(1400, 550).dot(np.random.randn(550, 1400)) Q = randomized_svd.adaptive_range(A, 1e-9) self.assertEqual(Q.shape[1], 550)
def test_adaptive_range_low_rank(self): A = np.random.randn(500, 100).dot(np.random.randn(100, 500)) Q = randomized_svd.adaptive_range(A) self.assertEqual(Q.shape, (500, 100))
def test_adaptive_range_big(self): A = np.random.randn(500, 400) Q = randomized_svd.adaptive_range(A, 1e-9) self.assertEqual(Q.shape, (500, 400))
def test_adaptive_range_small(self): A = np.random.randn(5, 8) Q = randomized_svd.adaptive_range(A, 1e-9) self.assertEqual(Q.shape, (5, 5))
def test_adaptive_range_full_rank(self): A = np.random.randn(50, 50) Q = randomized_svd.adaptive_range(A) self.assertEqual(Q.shape[1], 50)
def test_adaptive_range_small_error(self): A = lowrank(100, 100) Q = randomized_svd.adaptive_range(A, 1e-14, k=2, p=2) err = la.norm((np.eye(100) - Q.dot(Q.T)).dot(A), 2) self.assertLess(err, 1e-13) self.assertGreater(err, 0)