def modify_data(self, X):
     sentinel = sparse_rand(X.shape[0],
                            1,
                            density=self.sentinel_density,
                            format='csr',
                            random_state=self.random_state)
     X = hstack([X, sentinel], format='csr')
     return X
Esempio n. 2
0
def test_sparse_input():
    X = sparse_rand(100, 3, density=0.1, format='csr')

    # Should not error
    for eigen_solver in eigen_solvers:
        for path_method in path_methods:
            clf = manifold.Isomap(n_components=2,
                                  eigen_solver=eigen_solver,
                                  path_method=path_method)
            clf.fit(X)
Esempio n. 3
0
def test_sparse_modified_ldl(m, n):
    A = sparse_rand(m, n, density=0.025).toarray()
    A = np.dot(A, A.T)
    # Perform decompositions
    np_chlsky = cholesky(A)
    D, L = modified_ldl(A)
    py_chlsky = L*np.sqrt(D)

    L = tril(csr_matrix(L), format='csr')
    # Check L is actually sparse!
    assert len(L.data) < np.product(A.shape)
    assert issparse(L)

    spD, spL = sparse_ldl.modified_ldl(A, L.indptr, L.indices)
    # Check implementation of Cholesky above is the same as numpy
    np.testing.assert_allclose(spD, D)
    np.testing.assert_allclose(spL, L.data, atol=1e-7)
Esempio n. 4
0
def A(m, n):
    """A random positive definite matrix"""
    A = sparse_rand(m, n, density=0.1).toarray()
    return np.dot(A, A.T) + np.eye(m)*m