简体   繁体   中英

Fastest way to compute a subset of columns of the pseudoinverse of a scipy.sparse matrix

I am looking for the best way to compute a subset of the columns of the pseudoinverse of a sparse matrix A . Here are some relevant facts:

  1. A is a sparse NxN matrix that has a single zero eigenvalue with known eigenvector

  2. I only need M < N/2 columns of the pseudoinverse

  3. The pseudoinverse is a dense matrix

I am currently using scipy.linalg.lstsq(A,Id) (where Id is an NxM submatrix of the NxN identity matrix), but I suspect there is a better way to do this.

Any suggestions will be appreciated.

Update: Since there is only one zero eigenvalue, it turns out to be faster to create an invertible augmented (N+1)x(N+1) matrix and use scipy.linalg.solve . However, this is still not taking advantage of the sparsity of A .

You are looking for scipy.sparse.linalg.svds which will “Compute the largest k singular values/vectors for a sparse matrix” (though that's a bit misleading since it'll do that for dense matrixes too!).

It uses the Arnoldi iteration as implemented in the popular Fortran77 package, ARPACK, which in turn has wrappers in most math systems (Matlab, R, etc.).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM