sparse-matrix

Best C++ Matrix Library for sparse unitary matrices

隐身守侯 提交于 2019-11-27 20:52:04
I am looking for a good (in the best case actively maintained) C++ matrix library. Thereby it should be templated, because I want to use a complex of rationals as numerical type. The matrices what I am dealing with are mainly sparse and unitary. Can you please suggest libraries and also give a small explaination why to use them, because I know how to find them, but I cannot really decide what is suitable for me because I am missing the experience with them. EDIT: The main operations I am dealing with are matrix multiplication , scalar multiplication with a vector and kronecker product . The

Slicing Sparse Matrices in Scipy — Which Types Work Best?

ⅰ亾dé卋堺 提交于 2019-11-27 19:22:36
The SciPy Sparse Matrix tutorial is very good -- but it actually leaves the section on slicing un(der)developed (still in outline form -- see section: "Handling Sparse Matrices"). I will try and update the tutorial, once this question is answered. I have a large sparse matrix -- currently in dok_matrix format. import numpy as np from scipy import sparse M = sparse.dok_matrix((10**6, 10**6)) For various methods I want to be able to slice columns and for others I want to slice rows. Ideally I would use advanced-indexing (i.e. a boolean vector, bool_vect ) with which to slice a sparse matrix M --

Is there an efficient way of concatenating scipy.sparse matrices?

不羁岁月 提交于 2019-11-27 18:44:40
I'm working with some rather large sparse matrices (from 5000x5000 to 20000x20000) and need to find an efficient way to concatenate matrices in a flexible way in order to construct a stochastic matrix from separate parts. Right now I'm using the following way to concatenate four matrices, but it's horribly inefficient. Is there any better way to do this that doesn't involve converting to a dense matrix? rmat[0:m1.shape[0],0:m1.shape[1]] = m1 rmat[m1.shape[0]:rmat.shape[0],m1.shape[1]:rmat.shape[1]] = m2 rmat[0:m1.shape[0],m1.shape[1]:rmat.shape[1]] = bridge rmat[m1.shape[0]:rmat.shape[0],0:m1

Concatenate sparse matrices in Python using SciPy/Numpy

你。 提交于 2019-11-27 18:32:46
What would be the most efficient way to concatenate sparse matrices in Python using SciPy/Numpy? Here I used the following: >>> np.hstack((X, X2)) array([ <49998x70000 sparse matrix of type '<class 'numpy.float64'>' with 1135520 stored elements in Compressed Sparse Row format>, <49998x70000 sparse matrix of type '<class 'numpy.int64'>' with 1135520 stored elements in Compressed Sparse Row format>], dtype=object) I would like to use both predictors in a regression, but the current format is obviously not what I'm looking for. Would it be possible to get the following: <49998x1400000 sparse

R - data frame - convert to sparse matrix

让人想犯罪 __ 提交于 2019-11-27 18:21:17
问题 I have a data frame which is mostly zeros (sparse data frame?) something similar to name,factor_1,factor_2,factor_3 ABC,1,0,0 DEF,0,1,0 GHI,0,0,1 The actual data is about 90,000 rows with 10,000 features. Can I convert this to a sparse matrix? I am expecting to gain time and space efficiencies by utilizing a sparse matrix instead of a data frame. Any help would be appreciated Update #1: Here is some code to generate the data frame. Thanks Richard for providing this x <- structure(list(name =

Access value, column index, and row_ptr data from scipy CSR sparse matrix

蹲街弑〆低调 提交于 2019-11-27 17:42:36
问题 I have a large matrix that I would like to convert to sparse CSR format. When I do: import scipy as sp Ks = sp.sparse.csr_matrix(A) print Ks Where A is dense, I get (0, 0) -2116689024.0 (0, 1) 394620032.0 (0, 2) -588142656.0 (0, 12) 1567432448.0 (0, 14) -36273164.0 (0, 24) 233332608.0 (0, 25) 23677192.0 (0, 26) -315783392.0 (0, 45) 157961968.0 (0, 46) 173632816.0 etc... I can get vectors of row index, column index, and value using: Knz = Ks.nonzero() sparserows = Knz[0] sparsecols = Knz[1]

Apply PCA on very large sparse matrix

心已入冬 提交于 2019-11-27 17:30:26
问题 I am doing a text classification task with R, and I obtain a document-term matrix with size 22490 by 120,000 (only 4 million non-zero entries, less than 1% entries). Now I want to reduce the dimensionality by utilizing PCA (Principal Component Analysis). Unfortunately, R cannot handle this huge matrix, so I store this sparse matrix in a file in the "Matrix Market Format", hoping to use some other techniques to do PCA. So could anyone give me some hints for useful libraries (whatever the

How to transform numpy.matrix or array to scipy sparse matrix

早过忘川 提交于 2019-11-27 17:06:19
For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy matrix or array. What are the functions to do the inverse? I searched, but got no idea what keywords should be the right hit. You can pass a numpy array or matrix as an argument when initializing a sparse matrix. For a CSR matrix, for example, you can do the following. >>> import numpy as np >>> from scipy import sparse >>> A = np.array([[1,2,0],[0,0,3],[1,0,4]]) >>> B = np.matrix([[1,2,0],[0,0,3],[1,0,4]]) >>> A array([[1, 2, 0], [0, 0, 3], [1, 0, 4]]) >>> sA = sparse.csr_matrix(A) # Here's the initialization of

How to parallelize this Python for loop when using Numba

自闭症网瘾萝莉.ら 提交于 2019-11-27 16:00:28
问题 I'm using the Anaconda distribution of Python, together with Numba, and I've written the following Python function that multiplies a sparse matrix A (stored in a CSR format) by a dense vector x : @jit def csrMult( x, Adata, Aindices, Aindptr, Ashape ): numRowsA = Ashape[0] Ax = numpy.zeros( numRowsA ) for i in range( numRowsA ): Ax_i = 0.0 for dataIdx in range( Aindptr[i], Aindptr[i+1] ): j = Aindices[dataIdx] Ax_i += Adata[dataIdx] * x[j] Ax[i] = Ax_i return Ax Here A is a large scipy sparse

Fast sparse matrix multiplication

≯℡__Kan透↙ 提交于 2019-11-27 15:52:58
问题 for class I have to write my own linear equation solver for sparse matrices. I am free to use any type of data structure for sparse matrices and I have to implement several solves, including conjuguate gradient. I was wondering if there is a famous way to store sparse matrices such that multiplication with a vector is relatively fast. Right now my sparse matrices are basically implemented a wrapped std::map< std::pair<int, int>, double> which stores the data, if any. This transforms the