vnl_sparse_symmetric_eigensystem.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_sparse_symmetric_eigensystem.h
2 #ifndef vnl_sparse_symmetric_eigensystem_h_
3 #define vnl_sparse_symmetric_eigensystem_h_
4 //:
5 // \file
6 // \brief Find the eigenvalues of a sparse symmetric matrix
7 // \author Rupert W. Curwen, GE CR&D
8 // \date 20 Oct 98
9 //
10 // \verbatim
11 // Modifications
12 // 28 Mar 2001: dac (Manchester) - tidied up documentation
13 // 17 Dec 2010: Michael Bowers - added generalized sparse symmetric eigensystem
14 // solver (see 2nd CalculateNPairs() method)
15 // \endverbatim
16 
17 #include <vector>
18 #include <vnl/vnl_sparse_matrix.h>
19 #ifdef _MSC_VER
20 # include <vcl_msvc_warnings.h>
21 #endif
22 #include <vnl/algo/vnl_algo_export.h>
23 
24 //: Find the eigenvalues of a sparse symmetric matrix
25 // Solve the standard eigenproblem $A x = \lambda x$, or the
26 // generalized eigenproblem of $A x = \lambda B x$, where
27 // $A$ symmetric and sparse and, optionally, B sparse, symmetric,
28 // and positive definite. The block Lanczos algorithm is used to allow the
29 // recovery of a number of eigenvalue/eigenvector pairs from either
30 // end of the spectrum, to a required accuracy.
31 //
32 // Uses the dnlaso routine from the LASO package of netlib for
33 // solving the standard case.
34 // Uses the dsaupd routine from the ARPACK package of netlib for
35 // solving the generalized case.
36 
37 class VNL_ALGO_EXPORT vnl_sparse_symmetric_eigensystem
38 {
39  public:
42 
43  // Find n eigenvalue/eigenvectors of the eigenproblem A * x = lambda * x.
44  // If smallest is true, will calculate the n smallest eigenpairs,
45  // else the n largest.
46  int CalculateNPairs(vnl_sparse_matrix<double>& M, int n,
47  bool smallest = true, long nfigures = 10);
48 
49  // Find n eigenvalue/eigenvectors of the eigenproblem A * x = lambda * B * x.
50  // !smallest and !magnitude - compute the N largest (algebraic) eigenvalues
51  // smallest and !magnitude - compute the N smallest (algebraic) eigenvalues
52  // !smallest and magnitude - compute the N largest (magnitude) eigenvalues
53  // smallest and magnitude - compute the nev smallest (magnitude) eigenvalues
54  // set sigma for shift/invert method
55  int CalculateNPairs(vnl_sparse_matrix<double>& A, vnl_sparse_matrix<double>& B, int nEV,
56  double tolerance = 0, int numberLanczosVecs = 0,
57  bool smallest = false, bool magnitude = true,
58  int maxIterations = 0,
59  double sigma = 0.0);
60 
61  // Recover specified eigenvector after computation. The argument
62  // must be less than the requested number of eigenvectors.
63  vnl_vector<double> get_eigenvector(int i) const;
64  double get_eigenvalue(int i) const;
65 
66  // Used as a callback in solving.
67  int CalculateProduct(int n, int m, const double* p, double* q);
68  int SaveVectors(int n, int m, const double* q, int base);
69  int RestoreVectors(int n, int m, double* q, int base);
70 
71  protected:
72  int nvalues; // this is the size of the next two arrays.
73  vnl_vector<double> * vectors; // eigenvectors
74  double * values; // eigenvalues
75 
76  // Matrix A of A*x = lambda*x (or lambda*B*x)
78  // Matrix B of A*x = lambda*B*x
80 
81  std::vector<double*> temp_store;
82 };
83 
84 #endif // vnl_sparse_symmetric_eigensystem_h_
Find the eigenvalues of a sparse symmetric matrix.
#define m
Definition: vnl_vector.h:43
Simple sparse matrix.