예제 #1
0
    def testMakeLowRankMatrix(self):
        X = make_low_rank_matrix(n_samples=50, n_features=25, effective_rank=5,
                                 tail_strength=0.01, random_state=0)

        self.assertEqual(X.shape, (50, 25), "X shape mismatch")

        _, s, _ = svd(X)
        self.assertLess((s.sum() - 5).execute(n_parallel=1), 0.1, "X rank is not approximately 5")
예제 #2
0
def test_svd_execution(setup):
    rs = np.random.RandomState()
    data = rs.randn(18, 6) + 1j * rs.randn(18, 6)

    a = tensor(data, chunk_size=(9, 6))
    U, s, V = svd(a)
    t = U.dot(diag(s).dot(V))

    res = t.execute().fetch()
    np.testing.assert_array_almost_equal(res, data)

    a = tensor(data, chunk_size=(18, 6))
    U, s, V = svd(a)
    t = U.dot(diag(s).dot(V))

    res = t.execute().fetch()
    np.testing.assert_array_almost_equal(res, data)

    a = tensor(data, chunk_size=(2, 6))
    U, s, V = svd(a)
    t = U.dot(diag(s).dot(V))

    res = t.execute().fetch()
    np.testing.assert_array_almost_equal(res, data)

    data = rs.randn(6, 18) + 1j * rs.randn(6, 18)

    a = tensor(data)
    U, s, V = svd(a)
    t = U.dot(diag(s).dot(V))

    res = t.execute().fetch()
    np.testing.assert_array_almost_equal(res, data)

    # test for matrix of ones
    data = np.ones((20, 10))

    a = tensor(data, chunk_size=10)
    s = svd(a)[1]
    res = s.execute().fetch()
    expected = np.linalg.svd(a)[1]
    np.testing.assert_array_almost_equal(res, expected)
예제 #3
0
def test_make_low_rank_matrix(setup):
    X = make_low_rank_matrix(n_samples=50,
                             n_features=25,
                             effective_rank=5,
                             tail_strength=0.01,
                             random_state=0)

    assert X.shape == (50, 25)

    _, s, _ = svd(X)
    assert (s.sum() - 5).to_numpy() < 0.1
예제 #4
0
    def testSVDExecution(self):
        data = np.random.randn(18, 6) + 1j * np.random.randn(18, 6)

        a = tensor(data, chunk_size=(9, 6))
        U, s, V = svd(a)
        t = U.dot(diag(s).dot(V))

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, data))

        a = tensor(data, chunk_size=(18, 6))
        U, s, V = svd(a)
        t = U.dot(diag(s).dot(V))

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, data))

        a = tensor(data, chunk_size=(2, 6))
        U, s, V = svd(a)
        t = U.dot(diag(s).dot(V))

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, data))

        data = np.random.randn(6, 18) + 1j * np.random.randn(6, 18)

        a = tensor(data)
        U, s, V = svd(a)
        t = U.dot(diag(s).dot(V))

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, data))

        # test for matrix of ones
        data = np.ones((20, 10))

        a = tensor(data, chunk_size=10)
        s = svd(a)[1]
        res = self.executor.execute_tensor(s, concat=True)[0]
        expected = np.linalg.svd(a)[1]
        np.testing.assert_array_almost_equal(res, expected)