ConicBundle
lanczpol.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CH_MATRIX_CLASSES__LANCZPOL_HXX
4 #define CH_MATRIX_CLASSES__LANCZPOL_HXX
5 
15 #ifndef CH_MATRIX_CLASSES__LANCZOS_HXX
16 #include "lanczos.hxx"
17 #endif
18 #include "clock.hxx"
19 
20 namespace CH_Matrix_Classes {
21 
22 
26 
27 
35 class Lanczpol:public Lanczos,protected Memarrayuser
36 {
37 private:
38  int ierr;
49 
50  //--- global variables to allow reastarting
55 
62 
72 
74 
75  int stop_above;
77 
80 
82 
88 
90  std::ostream* myout;
91 
93  void error(const char *s){
94  if (myout)
95  (*myout)<<"Lanczos Error: "<<s<<std::endl;
96  }
97 
99  int guess_extremes(Integer nproposed);
100 
102  int dhua(Integer nreig,Integer nproposed, Integer maxmult);
103 
105  int bklanc(Integer neigfound,Integer blocksz,Integer s,
106  const Matrix &d,Matrix &C,Matrix &X,
107  Matrix &e,Matrix &u,Matrix &v);
108 
110  int bkqrlanc(Integer neigfound,Integer blocksz,Integer s,
111  const Matrix &d,Matrix &C,Matrix &X,
112  Matrix &e,Matrix &u,Matrix &v);
113 
115  int bklanccheb(Integer neigfound,Integer blocksz,Integer s,
116  Matrix &C,Matrix &X,Matrix &e,Matrix &v);
117 
119  int bkqrlanccheb(Integer neigfound,Integer blocksz,Integer s,
120  Matrix &C,Matrix &X,Matrix &e,Matrix &v);
121 
123  int err(Integer neigfound,Integer blocksz,const Matrix& X,Matrix &e);
124 
126  int cnvtst(Integer neigfound,Integer blocksz,Real& errc,Real eps,
127  const Matrix& d,const Matrix &e,Integer &nconv);
128 
130  int eigen(Integer neigfound,Integer blocksz,Integer sbsz,Matrix& C,
131  Matrix& d,Matrix& u,Matrix& v,Real& af);
132 
134  int sectn(Matrix& X,Integer neigfound,Integer blocksz,
135  Matrix& C,Matrix& d,Matrix& u,Matrix& v,
136  Real& af);
137 
139  int rotate_extremes(Integer neigfound,Integer sbs,Matrix& d,
140  const Matrix& C,Matrix &X,Matrix& v);
141 
143  int rotate(Integer neigfound,Integer sbs,Integer l,
144  const Matrix& C,Matrix &X,Matrix& v);
145 
147  int random(Matrix& X,Integer j);
148 
150  Integer orthog(Integer offset,Integer blocksz,Matrix &X,Matrix& B);
151 
153  int blockcheby(Integer col_offset,const Matrix& X,Matrix& v);
154 
156  Real scalarcheby(Real xval);
157 
159  int tred2(Integer n,const Matrix& C,Matrix& u,Matrix& v,Matrix& Z);
160 
162  int tql2(Integer n,Matrix &u,Matrix &v, Matrix& Z);
163 
164 public:
166  Lanczpol();
168  ~Lanczpol();
169 
170 
177 
179  void set_mineig(Real ie){minval=ie;}
181  void set_maxmult(Integer mop){maxop=mop;}
183  void set_maxiter(Integer mi){maxiter=mi;}
185  void set_relprec(Real relprec){eps=relprec;}
187  void set_nchebit(Integer cheb){choicencheb=cheb;}
189  void set_nblockmult(Integer nb){choicenbmult=nb;}
190 
192  void enable_stop_above(Real ub){stop_above=1; upper_bound=ub;}
194  void disable_stop_above(){stop_above=0;}
195 
197  void set_retlanvecs(Integer nl){retlanvecs=nl;}
198 
200  int get_lanczosvecs(Matrix& val,Matrix& vecs) const;
201 
203  Real get_relprec(void){return eps;} //relative precision
204 
206  int get_err() const{return ierr;}
208  Integer get_iter() const{return iter;}
210  Integer get_nmult() const{return nmult;}
211 
213 
215  int compute(const Lanczosmatrix* bigmat,
216  Matrix& eigval,
217  Matrix& eigvec,
218  Integer nreig,
219  Integer in_blocksz=0,
220  Integer maxcol=0
221  );
222 
223 
224 
229 
231  void set_out(std::ostream* o=0,int pril=1)
232  {myout=o; print_level=pril;}
233 
234 
236  std::ostream& save(std::ostream& out) const;
237 
239  std::istream& restore(std::istream& in);
241 };
242 
244 
245 }
246 
247 #endif
248 
std::istream & restore(std::istream &in)
restore the data from in where it was stored by save()
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
Integer nlanczvecs
number of columns of storage matrix X carrying "meaningful" Ritz vectors
Definition: lanczpol.hxx:47
Integer iter
iteration counter for Lanczos restarts (interval guess+computation)
Definition: lanczpol.hxx:53
Integer nmult
number of single vector multiplications with matrix
Definition: lanczpol.hxx:54
Lanczpol()
intialize all to default values
int rotate(Integer neigfound, Integer sbs, Integer l, const Matrix &C, Matrix &X, Matrix &v)
rotate the lanzos vectors to Ritz vectors
int get_lanczosvecs(Matrix &val, Matrix &vecs) const
returns the Lanczos vectors of the last call with their Ritz values
Matrix u
temporary matrix
Definition: lanczpol.hxx:68
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
Real errc
error accumulation
Definition: lanczpol.hxx:56
int print_level
level of iteration information that should be displayed
Definition: lanczpol.hxx:89
Integer neigfound
number of eigenvalues known, these are in the first neigfound columns of X
Definition: lanczpol.hxx:51
int err(Integer neigfound, Integer blocksz, const Matrix &X, Matrix &e)
compute norms of deviations of the Ritz vectors from being eigenvectors
CH_Tools::GB_rand randgen
local random number generator
Definition: lanczpol.hxx:81
Matrix w
temporary matrix
Definition: lanczpol.hxx:70
void set_maxmult(Integer mop)
set an upper bound on the number of matrix vector multiplications
Definition: lanczpol.hxx:181
const Lanczosmatrix * bigmatrix
pointer giving the (virtual) input matrix
Definition: lanczpol.hxx:73
int bkqrlanccheb(Integer neigfound, Integer blocksz, Integer s, Matrix &C, Matrix &X, Matrix &e, Matrix &v)
block lanzos multiplication with complete QR orthogonalization and Chebycheff spectral transformation...
void enable_stop_above(Real ub)
allow the algorithm to stop as soon as the maximum Ritz value exceeds the value ub ...
Definition: lanczpol.hxx:192
CH_Tools::Microseconds time_mult_sum
sum over time_mult for all restarts
Definition: lanczpol.hxx:85
int sectn(Matrix &X, Integer neigfound, Integer blocksz, Matrix &C, Matrix &d, Matrix &u, Matrix &v, Real &af)
compute matrix for eigenvalue computation into C
std::ostream * myout
everything is output to *myout, default: myout=&cout (may be 0 for no output)
Definition: lanczpol.hxx:90
void set_relprec(Real relprec)
set relative precision requirement for termination
Definition: lanczpol.hxx:185
Integer maxguessiter
upper bound on number of restarts to guess spectral interval
Definition: lanczpol.hxx:41
Abstract base class for supplying the input matrix for Lanzcosmethods.
Definition: lanczos.hxx:33
Integer choicencheb
user&#39;s choice for number of block Chebychev iterations (<0 -> automatic determination) ...
Definition: lanczpol.hxx:43
int blockcheby(Integer col_offset, const Matrix &X, Matrix &v)
apply spectral transformation by using a Chebycheff polynomial on the block multiplications ...
allows measuring time difference to its initialization time in Microseconds
Definition: clock.hxx:282
Real scalarcheby(Real xval)
compute the same polynomial as in blockcheby but for the scalar value xval
void set_nchebit(Integer cheb)
set the degree of the Chebycheff polynomial for the spectral transformation
Definition: lanczpol.hxx:187
int dhua(Integer nreig, Integer nproposed, Integer maxmult)
main routine performing the Lancozs iterations
extra long integer number for expressing and computing time measurements in microseconds.
Definition: clock.hxx:46
device independent random number generator based on long int with seed
Definition: gb_rand.hxx:28
int eigen(Integer neigfound, Integer blocksz, Integer sbsz, Matrix &C, Matrix &d, Matrix &u, Matrix &v, Real &af)
compute eigenvalues of current (block) tridiagonalization
int rotate_extremes(Integer neigfound, Integer sbs, Matrix &d, const Matrix &C, Matrix &X, Matrix &v)
rotate the eigenvectors of the largest and smallest eigenvalues of the tridiagonal matrix...
Real maxval
current approximation of largest eigenvalue
Definition: lanczpol.hxx:59
Integer get_iter() const
returns the number of restarts of the last call
Definition: lanczpol.hxx:208
Integer ncalls
counts number of calls to Lanczpol
Definition: lanczpol.hxx:78
Abstract interface to Lanzcos methods for computing a few extremal eigenvalues given via a Lanczosmat...
Definition: lanczos.hxx:53
Integer choicenbmult
user&#39;s choice for number of block multiplications (<0 -> automatic determination, min 6) ...
Definition: lanczpol.hxx:45
Integer maxiter
upper bound on number of restarts
Definition: lanczpol.hxx:40
void set_retlanvecs(Integer nl)
set an upper bound on the number of vectors returned in get_lanczosvecs()
Definition: lanczpol.hxx:197
int random(Matrix &X, Integer j)
assign a random vector to column j of X
int get_err() const
returns the error code of the last call
Definition: lanczpol.hxx:206
int stop_above
1 if algorithm is to stop after upper bound is exceeded
Definition: lanczpol.hxx:75
Integer guessmult
number of matrix vector multiplications to guess interval
Definition: lanczpol.hxx:42
Matrix C
X^tAX, intermediate eigenvalue computations, orthogonalizations, etc.
Definition: lanczpol.hxx:64
Integer maxop
upper bound on matrix vector multiplications
Definition: lanczpol.hxx:39
int ierr
error return code
Definition: lanczpol.hxx:38
CH_Tools::Clock myclock
for time measurements
Definition: lanczpol.hxx:83
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
int cnvtst(Integer neigfound, Integer blocksz, Real &errc, Real eps, const Matrix &d, const Matrix &e, Integer &nconv)
check convergence of maximum Ritz value/vector
Real polval
the Chebychef polynomial will have this value at maxval
Definition: lanczpol.hxx:61
void error(const char *s)
output of error messages
Definition: lanczpol.hxx:93
Real eps
relative precision
Definition: lanczpol.hxx:57
Real upper_bound
stop if current maximum Ritz value exceeds this value
Definition: lanczpol.hxx:76
Header declaring the abstract classes CH_Matrix_Classes::Lanczosmatrix and CH_Matrix_Classes::Lanczos...
Real get_relprec(void)
returns current relative precision requirement
Definition: lanczpol.hxx:203
int bklanc(Integer neigfound, Integer blocksz, Integer s, const Matrix &d, Matrix &C, Matrix &X, Matrix &e, Matrix &u, Matrix &v)
block lanzos multiplication without Chebycheff spectral transformation
Matrix class for real values of type Real
Definition: matrix.hxx:74
int bkqrlanc(Integer neigfound, Integer blocksz, Integer s, const Matrix &d, Matrix &C, Matrix &X, Matrix &e, Matrix &u, Matrix &v)
block lanzos multiplication, with complete QR orthogonalization, without Chebycheff spectral transfor...
Integer blocksz
working block of lanczos vectors X(:,neigfound:neigfound+blocksz-1)
Definition: lanczpol.hxx:52
Integer get_nmult() const
returns the number of matrix-vector multiplications of the last call
Definition: lanczpol.hxx:210
Integer mymaxj
maximum amount of storage (columns) provided in X and C
Definition: lanczpol.hxx:79
CH_Tools::Microseconds time_sum
time spent in this call to compute()
Definition: lanczpol.hxx:87
void set_nblockmult(Integer nb)
set maximum number of block multiplications within one restart
Definition: lanczpol.hxx:189
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
void disable_stop_above()
do not allow premature termination as in enable_stop_above()
Definition: lanczpol.hxx:194
A Lanczos method allowing spectral transformation by Chebycheff polynomials and premature termination...
Definition: lanczpol.hxx:35
Real minval
current approximation of smallest eigenvalue
Definition: lanczpol.hxx:60
void set_maxiter(Integer mi)
set an upper bpound on the number of restarts
Definition: lanczpol.hxx:183
Matrix v
temporary matrix
Definition: lanczpol.hxx:69
int compute(const Lanczosmatrix *bigmat, Matrix &eigval, Matrix &eigvec, Integer nreig, Integer in_blocksz=0, Integer maxcol=0)
the main routine: compute the nreig maximum eigenvalues of the matrix specified by bigmat ...
CH_Tools::Microseconds time_iter
time spent in last lanczos iteration
Definition: lanczpol.hxx:86
Integer nblockmult
number of blockmultiplications in one restart
Definition: lanczpol.hxx:46
Integer nchebit
number of block Chebychev iterations within one iteration
Definition: lanczpol.hxx:44
Header declaring and (inline) implementing the classes CH_Tools::Microseconds and CH_Tools::Clock as ...
int bklanccheb(Integer neigfound, Integer blocksz, Integer s, Matrix &C, Matrix &X, Matrix &e, Matrix &v)
block lanzos multiplication with Chebycheff spectral transformation
Integer retlanvecs
user&#39;s choice for number of returend Ritz vectors (<0 -> nlanczvecs)
Definition: lanczpol.hxx:48
Matrix d
diagonals (Ritz values)
Definition: lanczpol.hxx:65
void set_out(std::ostream *o=0, int pril=1)
set output stream and level of detail of log output (for debugging)
Definition: lanczpol.hxx:231
Matrix Xqr
for complete orthogonalization with Householder QR
Definition: lanczpol.hxx:67
~Lanczpol()
destructor, nothing particular
int guess_extremes(Integer nproposed)
compute a guess for minimum and maximum eigenvalue
std::ostream & save(std::ostream &out) const
save all data in out so that the current state can be recovered completely by restore() ...
Real mcheps
machine precision (computed in constructor)
Definition: lanczpol.hxx:58
Matrix minvec
temporary matrix for guessing minimal eigenvalue
Definition: lanczpol.hxx:71
int tred2(Integer n, const Matrix &C, Matrix &u, Matrix &v, Matrix &Z)
tridiagonalize a symmetric blockdiagonal matrix
Matrix e
error bounds
Definition: lanczpol.hxx:66
void set_mineig(Real ie)
set a guess on the value of the smallest
Definition: lanczpol.hxx:179
Matrix X
provides storage for the Lanczos vectors during computation
Definition: lanczpol.hxx:63
CH_Tools::Microseconds time_mult
for each restart, the time spent in lanczosmult
Definition: lanczpol.hxx:84
int tql2(Integer n, Matrix &u, Matrix &v, Matrix &Z)
compute the eigenvalues of a tridiagonal matrix
Integer orthog(Integer offset, Integer blocksz, Matrix &X, Matrix &B)
orthonormalize columns X(:,offset:offset+l_blocksz-1) to all previous columns