This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Eigenvectors of sparse matrices

Tags: None
(comma "," separated)
sweeneychris
Registered Member
Posts
8
Karma
0

Eigenvectors of sparse matrices

Thu Oct 01, 2015 12:39 am
I need to get the eigenvectors of a sparse matrix. This is leading me to two issues/questions:

1) Is there a way to do eigen-decomposition for sparse matrices? Or do you always have to use dense matrices? It would be AWESOME to have a Lanczos method available.
2) Do DiagonalMatrix and SparseMatrix play nicely? I am getting errors when trying to add/subtract the two

More details: I have a sparse matrix which is formed from three matrices, two of which are Eigen::DiagonalMatrix and one which is Eigen::SparseMatrix as such:
Code: Select all
const Eigen::SparseMatrix<double> sparse_mat2 = diag1 * (diag2 - sparse_mat1) * diag1

That line is giving me fits saying that you cannot add/subtract diag2 and sparse_mat, which seems surprising to me.

My ultimate goal is to obtain k eigenvectors of sparse_mat2 corresponding to the k smallest eigenvalues. Is the only way to do this to convert all matrices to the dense form?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Check this project: https://github.com/yixuan/spectra

For sparse and diagonal interaction, such operations are not allowed because they are inherently inefficient unless we create a temporary, whereas in most cases the user can avoid this temporary by doing, e.g. (with 3.3-alpha1):

Code: Select all
#include <Eigen/Sparse>
using namespace Eigen;
int main() {
  DiagonalMatrix<double,Dynamic> diag1, diag2;
  SparseMatrix<double> sparse_mat1;
  sparse_mat1 -= diag2;
  const Eigen::SparseMatrix<double> sparse_mat2 = diag1 * (-sparse_mat1) * diag1;
}
sweeneychris
Registered Member
Posts
8
Karma
0

Re: Eigenvectors of sparse matrices

Thu Oct 01, 2015 7:55 pm
Wow thanks so much for your response. These were exactly the two things that I needed!!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar