I am doing some computations on a sparse matrix of floats in the log domain, so the "empty" entries are actually -Inf (using -FLT_MAX). I'm using a custom sparse matrix class right now but I am eager to swap in an off-the-shelf replacement.
This is in C++. My inclinations were to look at the compressed column matrices in Eigen and Boost uBlas. However it is not clear that either supports a custom value for "zero" (perhaps provided by a template parameter). Does anyone have a suggestion?
Clarification:
What I want is this: for any cell (i,j) that has not been "set" previously, I would like mat[i,j] to return -Inf ... so this is perhaps better described as a "default" value for the "empty" entries of the sparse matrix.
I am using this to perform HMM recursions (Viterbi, sum-product) with probabilities kept in the log domain to avoid underflow.
I am not doing any matrix operations ... I am just filling in a dynamic programming tableau, essentially. I want to use a sparse matrix class because I am only filling in a band of the matrix and I would like efficient memory use. The compressed band matrices would give good performance since I am filling in the matrix "in order."
log(0) = -Infbut I don't understand what you're trying to do - if you add-FLT_MAXfor all zero elements you'll end up with a dense matrix, and at any rate I can't see how doing numerical operations on matrices involving-Infis meaningful. Maybe I've missed the point? - Darren Engwirdax * 0 == 0, butx * -Inf != -Infwhenxis negative (and likewisex + 0 == x, butx + -Inf != x). So when doing a sparse matrix multiplication you can't just ignore the so-called empty values if those values are-Inf, whereas you can jump straight past a bunch of zeroes. - Steve Jessop-Infis used as an approximation tolog(0). So the sparse thing presumably doesn't needn't matrix arithmetic (which is meaningless in the log domain AFAIK), just a sparse 2-dimensional array with a tunable empty value would do. - Steve Jessop