npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
trlanEigensystem.hh
Go to the documentation of this file.
1 #ifndef EMSUNFOLD_TRLANEIGENSYSTEM_HH_
2 #define EMSUNFOLD_TRLANEIGENSYSTEM_HH_
3 
4 /*!
5 // \file trlanEigensystem.hh
6 //
7 // \brief Determination of eigenvalues/vectors of covariance matrices with TRLAN
8 //
9 // Author: I. Volobouev
10 //
11 // July 2014
12 */
13 
14 #include <vector>
15 
17 
18 namespace emsunfold {
19  /**
20  // TRLAN diagnostic information, in a slightly more convenient form than
21  // that provided by the Fortran 77 interface "trlan77".
22  */
24  {
25  public:
26  /**
27  // Default constructor creates a dummy object which is supposed
28  // to be overwritten later.
29  */
31 
32  /**
33  // The arguments of this constructor are as follows:
34  //
35  // tailFraction -- The fraction of eigenvalues not found. This is
36  // (trace - (sum of eigenvalues found))/trace.
37  //
38  // ipar -- input/output parameters of the trlan77 routine.
39  */
40  TrlanDiagnostics(double tailFraction, const int ipar[32]);
41 
42  /**
43  // ((matrix trace) - (sum of eigenvalues found))/(matrix trace).
44  // For the diagnostics object created by the default constructor,
45  // this method returns -1.0.
46  */
47  inline double finalTailFraction() const {return tailFraction_;}
48 
49  /**
50  // Error code returned by TRLAN. 0 means no error.
51  // For the list of error codes, consult the TRLAN user guide.
52  */
53  inline int status() const {return ipar_[0];}
54 
55  /**
56  // Number of eigenpairs actually determined. Note that it could be
57  // less than the number requested.
58  */
59  inline int nConverged() const {return ipar_[3];}
60 
61  /** Number of Ritz pairs locked (with small residual norms) */
62  inline int nLocked() const {return ipar_[23];}
63 
64  /** Actual number of matrix-vector multiplications performed */
65  inline int nMatVec() const {return ipar_[24];}
66 
67  /** Number of restarting loops */
68  inline int nRestart() const {return ipar_[25];}
69 
70  /**
71  // Number of times the Gram-Schmidt orthogonalization has been applied
72  */
73  inline int nOrth() const {return ipar_[26];}
74 
75  /** Number of times initial random vectors were generated */
76  inline int nRand() const {return ipar_[27];}
77 
78  /** Total TRLAN run time, in milliseconds */
79  inline int tTotal() const {return ipar_[28];}
80 
81  /** Time spent multiplying matrix by vectors, in ms */
82  inline int tMatVec() const {return ipar_[29];}
83 
84  /** Time spent re-orthogonalizing, in ms */
85  inline int tOrth() const {return ipar_[30];}
86 
87  /** Time spent in restarting and Rayleigh-Ritz projections, in ms */
88  inline int tRestart() const {return ipar_[31];}
89 
90  private:
91  double tailFraction_;
92  int ipar_[32];
93  };
94 
95  /**
96  // Determine eigenvalues and eigenvectors of the argument covariance
97  // matrix using TRLAN, steered by the parameters given. This function
98  // returns the TRLAN error code (status). 0 means everything is OK.
99  // Consult the TRLAN user guide for the meaning of other error codes.
100  // Note that, even when 0 is returned, the number of eigenpairs actually
101  // found could be less than the number of eigenpairs requested and/or
102  // tail fraction stopping condition might not be satisfied.
103  //
104  // The eigenvalues will be returned in the increasing order. Check
105  // diagnostics->nConverged() to see how many of them are returned.
106  // Note that the vector of eigenvalues can actually have more elements,
107  // but only "diagnostics->nConverged()" of them are valid. Eigenvectors
108  // will be placed into "eigenvectors" vector one after another. If the
109  // matrix "covmat" has "nrows" rows then &eigenvectors[0] will point to
110  // the first eigenvector, &eigenvectors[0] + nrows to the second, etc.
111  // The order of eigenvectors corresponds to the order of eigenvalues.
112  */
113  template <class Matrix>
114  int trlanEigensystem(const Matrix& covmat, const EigenParameters& params,
115  std::vector<double>* eigenvalues,
116  std::vector<double>* eigenvectors,
117  TrlanDiagnostics* diagnostics);
118 }
119 
120 std::ostream& operator<<(std::ostream& os, const emsunfold::TrlanDiagnostics& d);
121 
122 #include "npstat/emsunfold/trlanEigensystem.icc"
123 
124 #endif // EMSUNFOLD_TRLANEIGENSYSTEM_HH_
Parameters specifying how to search for eigenvalues/eigenvectors of covariance matrices using TRLAN.
Definition: EigenParameters.hh:20
Definition: trlanEigensystem.hh:24
int nOrth() const
Definition: trlanEigensystem.hh:73
int nMatVec() const
Definition: trlanEigensystem.hh:65
int nRand() const
Definition: trlanEigensystem.hh:76
int tRestart() const
Definition: trlanEigensystem.hh:88
int nLocked() const
Definition: trlanEigensystem.hh:62
int tTotal() const
Definition: trlanEigensystem.hh:79
int status() const
Definition: trlanEigensystem.hh:53
int nConverged() const
Definition: trlanEigensystem.hh:59
TrlanDiagnostics(double tailFraction, const int ipar[32])
double finalTailFraction() const
Definition: trlanEigensystem.hh:47
int tMatVec() const
Definition: trlanEigensystem.hh:82
int nRestart() const
Definition: trlanEigensystem.hh:68
int tOrth() const
Definition: trlanEigensystem.hh:85
Definition: AbsSparseUnfoldingFilterND.hh:25
int trlanEigensystem(const Matrix &covmat, const EigenParameters &params, std::vector< double > *eigenvalues, std::vector< double > *eigenvectors, TrlanDiagnostics *diagnostics)