0

I would like to compute the inverse of some large block diagonal sparse matrix. The number of rows and columns is somewhat over 50,000. The blocks are 12 by 12 and are sparse (27 non zero elements).

I tried to compute the inverse of the entire matrix (using solve). This was not possible, the entire matrix is too big.

After that, i use a for-loop. Within each iteration, i take out one block, compute its inverse and place it back.

That method works, but i takes about 5 minutes. I wonder if there is some faster way.

Many thanks in advance.

  • 2
    I think you might consider asking in [scicomp.SE](http://scicomp.stackexchange.com/), but they'll likely just tell you not to invert any big matrix. Why do you need the inverse? The reason it's so slow, BTW, is that removing the blocks and putting them back in is slow. The math is doable very fast. – Emmet Apr 04 '14 at 18:07
  • are you already using a sparse matrix and the methods in the `Matrix` package? it's not clear from your question. – Ben Bolker Apr 10 '14 at 00:30
  • yes that is true; a dgCMatrix – user3499209 Apr 11 '14 at 06:17

2 Answers2

0

How do you end up with a 50k x 50k matrix?

Inverting a 12 x 12 is simple and quick. Is it the inverting that's causing the slowness or the accessing of the matrix object?

What are you going to do with your large inversion?

user3472874
  • 151
  • 5
  • accessing the matrix object causes the slowless...selecting a block of that matrix many times – user3499209 Apr 06 '14 at 18:23
  • the reason why i want to do this is not so easy to explain....I want to use a quadratic optimization. I have at my disposal a very fast module for problems of the form (min (x* - x)'(x*-x) ), partly programmed in C+. My problem is somewhat more difficult. It is of the more general form min x'A'x + cx. I use the matrix inverse to transform my problem in the easier problem min (x* - x)'(x*-x) ). I know there is some R module Quadprog for solving more general quadratic programs, but it is not so good as my software for the easier problem. – user3499209 Apr 06 '14 at 18:28
0

I made by code much faster, by:

1) storing the inverse of the block diagonal matrices in a list, rather than 'placing them back in the large matrix. At the end I built the entire matrix from the list by using the bdiag() command. 2) by considering the block diagonal matrices not one by one, but in groups of about 10 So, I repeatedly calculate the inverse of a submatrix consisting of 10 block diagonal matrices.

In the original question i did not tell that i do not only take the inverse of each block, but that i also applied some transformation on each block. Now the transformation is done in advance for the entire block diagonal matrix, which also saves time.