class SparseRowMatrixTestCase(unittest.TestCase): def setUp(self): self.matrix_A = SparseRowMatrix(sparse_matrix_rdd, 'test_data', 1000, 100) self.matrix_A2 = SparseRowMatrix(sparse_matrix_rdd2, 'test_data', 100, 1000) def test_size(self): c = self.matrix_A.rdd.count() self.assertEqual(c, 1000) def test_size2(self): c = self.matrix_A2.rdd.count() self.assertEqual(c, 100) def test_gaussian_projection(self): p = self.matrix_A.gaussian_projection(20) self.assertEqual(p.shape, (20, 100)) #def test_mat_ltimes(self): # mat = np.random.rand(10,1000) # p = self.matrix_A.ltimes(mat) # p_true = np.dot( mat,A ) # self.assertTrue( np.linalg.norm(p-p_true)/np.linalg.norm(p_true) < 1e-5 ) def test_atamat(self): mat = np.random.rand(100, 20) p = self.matrix_A.atamat(mat) p_true = np.dot(A.T, np.dot(A, mat)) self.assertTrue( np.linalg.norm(p - p_true) / np.linalg.norm(p_true) < 1e-5) def test_gaussian_projection2(self): p = self.matrix_A2.gaussian_projection(20) self.assertEqual(p.shape, (20, 1000)) def test_atamat2(self): mat = np.random.rand(1000, 20) p = self.matrix_A2.atamat(mat) p_true = np.dot(A2.T, np.dot(A2, mat)) self.assertTrue( np.linalg.norm(p - p_true) / np.linalg.norm(p_true) < 1e-5)
class SparseRowMatrixTestCase(unittest.TestCase): def setUp(self): self.matrix_A = SparseRowMatrix(sparse_matrix_rdd,'test_data',1000,100) self.matrix_A2 = SparseRowMatrix(sparse_matrix_rdd2,'test_data',100,1000) def test_size(self): c = self.matrix_A.rdd.count() self.assertEqual(c, 1000) def test_size2(self): c = self.matrix_A2.rdd.count() self.assertEqual(c, 100) def test_gaussian_projection(self): p = self.matrix_A.gaussian_projection(20) self.assertEqual(p.shape, (20,100)) #def test_mat_ltimes(self): # mat = np.random.rand(10,1000) # p = self.matrix_A.ltimes(mat) # p_true = np.dot( mat,A ) # self.assertTrue( np.linalg.norm(p-p_true)/np.linalg.norm(p_true) < 1e-5 ) def test_atamat(self): mat = np.random.rand(100,20) p = self.matrix_A.atamat(mat) p_true = np.dot( A.T, np.dot(A, mat) ) self.assertTrue( np.linalg.norm(p-p_true)/np.linalg.norm(p_true) < 1e-5 ) def test_gaussian_projection2(self): p = self.matrix_A2.gaussian_projection(20) self.assertEqual(p.shape, (20,1000)) def test_atamat2(self): mat = np.random.rand(1000,20) p = self.matrix_A2.atamat(mat) p_true = np.dot( A2.T, np.dot(A2, mat) ) self.assertTrue( np.linalg.norm(p-p_true)/np.linalg.norm(p_true) < 1e-5 )