Example #1
0
def test_build_sparse_knn_kernel_to_data():
    G = build_graph(data, decay=None, sparse=True)
    n = G.data.shape[0]
    K = G.build_kernel_to_data(data[:n // 2, :])
    assert(K.shape == (n // 2, n))
    K = G.build_kernel_to_data(G.data)
    assert(np.sum(G.kernel != (K + K.T) / 2) == 0)
    K = G.build_kernel_to_data(G.data_nu)
    assert(np.sum(G.kernel != (K + K.T) / 2) == 0)
Example #2
0
def test_build_sparse_exact_kernel_to_data(**kwargs):
    G = build_graph(data, decay=10, thresh=0, sparse=True)
    n = G.data.shape[0]
    K = G.build_kernel_to_data(data[:n // 2, :])
    assert (K.shape == (n // 2, n))
    K = G.build_kernel_to_data(G.data)
    assert (np.sum(G.kernel != (K + K.T) / 2) == 0)
    K = G.build_kernel_to_data(G.data_nu)
    assert (np.sum(G.kernel != (K + K.T) / 2) == 0)
Example #3
0
def test_inverse_transform_sparse_no_pca():
    G = build_graph(data, sparse=True, n_pca=None)
    assert np.sum(G.data != G.inverse_transform(G.data_nu)) == 0
    with assert_raises_message(
        ValueError,
        "data of shape ({0}, 1) cannot be inverse transformed from graph built on reduced data of shape ({0}, {1})".format(
            G.data.shape[0], G.data.shape[1]
        ),
    ):
        G.inverse_transform(sp.csr_matrix(G.data)[:, 0])
    with assert_raises_message(
        ValueError,
        "data of shape ({0}, 15) cannot be inverse transformed from graph built on reduced data of shape ({0}, {1})".format(
            G.data.shape[0], G.data.shape[1]
        ),
    ):
        G.inverse_transform(sp.csr_matrix(G.data)[:, :15])
Example #4
0
def test_transform_sparse_no_pca():
    G = build_graph(data, sparse=True, n_pca=None)
    assert np.sum(G.data_nu != G.transform(G.data)) == 0
    with assert_raises_message(
        ValueError,
        "data of shape {} cannot be transformed to graph built on data of shape {}".format(
            G.data.tocsr()[:, 0].shape, G.data.shape
        ),
    ):
        G.transform(sp.csr_matrix(G.data)[:, 0])
    with assert_raises_message(
        ValueError,
        "data of shape {} cannot be transformed to graph built on data of shape {}".format(
            G.data.tocsr()[:, :15].shape, G.data.shape
        ),
    ):
        G.transform(sp.csr_matrix(G.data)[:, :15])
Example #5
0
def test_inverse_transform_sparse_no_pca():
    G = build_graph(data, sparse=True, n_pca=None)
    assert np.sum(G.data != G.inverse_transform(G.data_nu)) == 0
    assert_raises(ValueError, G.inverse_transform, sp.csr_matrix(G.data)[:, 0])
    assert_raises(ValueError, G.inverse_transform,
                  sp.csr_matrix(G.data)[:, :15])