sparse-matrix

Looping over the non-zero elements of a uBlas sparse matrix.

I have the following sparse matrix that contains O(N) elements boost::numeric::ublas::compressed_matrix<int> adjacency (N, N); I could write a brute force double loop to go over all the entries in O(N^2) time like below, but this is going to be too slow. for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) std::cout << adjacency(...

Are there any storage optimized Sparse Matrix implementations in C#?

Are there any storage optimized Sparse Matrix implementations in C#? ...

UMFPACK, using with Microsoft Visual Studio 2008 ( C++ )

Hi I've seen this topic about UMFPack and its usage. http://stackoverflow.com/questions/1242190/c-memory-efficient-solution-for-axb-linear-algebra-system But I couldn't implement it in Visual Studio 2008! I want to use C++ and UMFPACK to solve a triplet mode (Sparse Matrix) and nothing else! I dont wnat any report or something, I just...

converting R code snippet to use the Matrix package?

Hello, I am not sure there are any R users out there, but just in case: I am a novice at R and was kindly "handed down" the following R code snippet: Beta <- exp(as.matrix(read.table('beta.transpose'))) WordFreq <- read.table('freq-matrix') WordProbs <- WordFreq$V1 / sum(WordFreq) infile <- file('freq-matrix') outfile <- file('doc_to...

In SciPy, using ix_() with sparse matrices doesn't seem to work so what else can I use?

In Numpy, ix_() is used to grab rows and columns of a matrix, but it doesn't seem to work with sparse matrices. For instance, this code works because it uses a dense matrix: >>> import numpy as np >>> x = np.mat([[1,0,3],[0,4,5],[7,8,0]]) >>> print x [[1 0 3] [0 4 5] [7 8 0]] >>> print x[np.ix_([0,2],[0,2])] [[1 3] [7 0]] I used ix...

General sparse iterative solver libraries

What are some of the better libraries for large sparse iterative (conjugate gradient, MINRES, GMRES, etc.) linear algebra system solving? I've often coded my own routines, but I'm interested to know which "off-the-shelf" packages people prefer. I've heard of PETSc, TAUCS, IML++, and a few others. I'm wondering how these stack up, and ...

help in displaying the sum of two matrixs (using linked lists)

hey there, Im having problems displaying my results in this program but the program compiles. Any idea as to what is going wrong?. The purpose of the program is to take two, 2 by 2 matrixes and add them to create the matrix called result. but when it comes to displaying the values in each matrix (A,B and result) it hangs. why does at the...

Efficiently solving sparse matrices

For solving spare matrices, in general, how big does the matrix have to be (as a rule of thumb) for methods like congraduate descent to be faster than brute force solvers (that do not take advantage o sparsity)? ...

How to speed up my sparse matrix solver?

I'm writing a sparse matrix solver using the Gauss-Seidel method. By profiling, I've determined that about half of my program's time is spent inside the solver. The performance-critical part is as follows: size_t ic = d_ny + 1, iw = d_ny, ie = d_ny + 2, is = 1, in = 2 * d_ny + 1; for (size_t y = 1; y < d_ny - 1; ++y) { for (size_t x...

Why does the speed of this SOR solver depend on the input?

Related to my other question, I have now modified the sparse matrix solver to use the SOR (Successive Over-Relaxation) method. The code is now as follows: void SORSolver::step() { float const omega = 1.0f; float const *b = &d_b(1, 1), *w = &d_w(1, 1), *e = &d_e(1, 1), *s = &d_s(1, 1), *n = &d_n(1, 1), *xw...

In R, when using named rows, can a sparse matrix column be added to another sparse matrix?

I have two sparse matrices, m1 and m2: > m1 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("b","d"),NULL)) > m2 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("a","b"),NULL)) > m1["b",1]<- 4 > m2["a",1]<- 5 > m1 2 x 1 sparse Matrix of class "dgCMatrix" b 4 d . > m2 2 x 1 sparse Matrix of class "dgCMatrix" ...

Scipy sparse... arrays?

Hey, folks. So, I'm doing some Kmeans classification using numpy arrays that are quite sparse-- lots and lots of zeroes. I figured that I'd use scipy's 'sparse' package to reduce the storage overhead, but I'm a little confused about how to create arrays, not matrices. I've gone through this tutorial on how to create sparse matrices: h...

Representing Sparse Data in PostgreSQL

What's the best way to represent a sparse data matrix in PostgreSQL? The two obvious methods I see are: Store data in a single a table with a separate column for every conceivable feature (potentially millions), but with a default value of NULL for unused features. This is conceptually very simple, but I know that with most RDMS implem...

best way to get a vector from sparse matrix

Hi, I have a m x n matrix where each row consists of zeros and same values for each row. an example would be: M = [-0.6 1.8 -2.3 0 0 0; 0 0 0 3.4 -3.8 -4.3; -0.6 0 0 3.4 0 0] In this example the first column consists of 0s and -0.6, second 0 and 1.8, third -2.3 and so on. In such case I would like to reduce m to 1 (get a vector fro...

Adding a numpy array to a scipy.sparse.dok_matrix

Hi together, I have a scipy.sparse.dok_matrix (dimensions m x n), wanting to add a flat numpy-array with length m. for col in xrange(n): dense_array = ... dok_matrix[:,col] = dense_array However, this code raises an Exception in dok_matrix.__setitem__ when it tries to delete a non existing key (del self[(i,j)]). So, for now ...

MATLAB: Convert two array to a sparse matrix

I'm looking for an a command or trick to convert two arrays to a sparse matrix. The two arrays contain x-values and y-values, which gives a coordinate in the cartesian coordinate system. I want to group the coordinates, which if the value is between some value on the x-axes and the y-axes. % MATLAB x_i = find(x > 0.1 & x < 0.9); y_i = f...

What is the best algorithm for solving a band-diagonal matrix?

I'm trying to figure out the best way to solve a pentadiagonal matrix. Is there something faster than gaussian elimination? ...

Java - Using Abstract classes properly (problem with COLT)

I'm using colt for some algebraic operations with sparse matrices. Actually i want to calculate a sparse matrix inverse, everything looks pretty easy but i'm not able to get it done. There is a method in "Algebra" called inverse that get a DoubleMatrix2D [abstract], and SparseMatrix2D is a direct subclass of DoubleMatrix2D. A couble of...

how to implement a sparse_vector class

I am implementing a templated sparse_vector class. It's like a vector, but it only stores elements that are different from their default constructed value. So, sparse_vector would store the lazily-sorted index-value pairs for all indices whose value is not T(). I am basing my implementation on existing sparse vectors in numeric librar...

k-means clustering in R on very large, sparse matrix?

Hello, I am trying to do some k-means clustering on a very large matrix. The matrix is approximately 500000 rows x 4000 cols yet very sparse (only a couple of "1" values per row). The whole thing does not fit into memory, so I converted it into a sparse ARFF file. But R obviously can't read the sparse ARFF file format. I also have th...