RBGen  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RBGen_StSVD_RTR.h
1 #ifndef RBGEN_STSVD_RTR_H
2 #define RBGEN_STSVD_RTR_H
3 
4 #include "RBGen_PODMethod.hpp"
5 #include "RBGen_Method.hpp"
6 #include "AnasaziOrthoManager.hpp"
7 #include "AnasaziEpetraAdapter.hpp"
8 #include "Epetra_MultiVector.h"
9 #include "Epetra_SerialDenseMatrix.h"
11 #include "Teuchos_Time.hpp"
12 #include "Teuchos_LAPACK.hpp"
13 #include "AnasaziSolverUtils.hpp"
14 
15 
16 //
17 // This class encapsulates a dominant SVD computation via Riemannian Trust-Region manifold
18 // optimization.
19 //
20 // We are given a snapshot matrix A of dimension m by n. We wish to find the rank-k
21 // dominant SVD.
22 //
23 // The manifold is M = St(k,m) x St(k,n), where St(k,p) is the manifold of rank-k orthonormal
24 // bases of R^p (the orthogonal Stiefel manifold).
25 //
26 // The objective function is
27 // f : M --> R
28 // : (U,V) --> trace(U^T A V N),
29 // where N is a diagonal matrix with distinct, ascending (or descending) strictly positive elements.
30 // For example, N = diag(5,4,3,2,1)
31 // N serves to order the singular vectors in U and V
32 // In the case where the dominant singular values are distinct, this function has a unique global maximizer,
33 // which is a strict global maximizer. Otherwise, there is a unique region where the global maximum is reached,
34 // which corresponds to rotations of the singular vectors corresponding to the non-distinct singular values.
35 //
36 // This solver applies the Riemannian Trust-Region method (Absil, Baker and Gallivan) to maximize f
37 // over M.
38 //
39 
40 namespace RBGen {
41 
43  class StSVDRTR : public virtual Method<Epetra_MultiVector,Epetra_Operator>, public virtual PODMethod<double> {
44 
45  public:
47 
48 
50  StSVDRTR();
51 
53  virtual ~StSVDRTR() {};
55 
57 
58 
60  void computeBasis();
61 
63  void updateBasis( const Teuchos::RCP< Epetra_MultiVector >& update_ss );
64 
66 
68 
69 
72 
75 
77  std::vector<double> getSingularValues() const;
78 
80  double getCompTime() const { return timerComp_.totalElapsedTime(); }
81 
83  std::vector<double> getResNorms();
84 
86 
88 
89 
93  const Teuchos::RCP< RBGen::FileIOHandler< Epetra_Operator > >& fileio = Teuchos::null );
94 
95  void Reset( const Teuchos::RCP<Epetra_MultiVector>& new_ss );
96 
98 
100 
101 
102  bool isInitialized() { return isInitialized_; }
103 
105 
106  protected:
107 
108  typedef Anasazi::SolverUtils<double,Epetra_MultiVector,Epetra_Operator> Utils;
109  // debugging checklist
110  struct CheckList {
111  // outer checks
112  // U,V are ortho
113  bool checkUV;
114  // R is residual
115  bool checkRes;
116  // UAVNsym, VAUNsym
117  bool checkSyms;
118  // check sigma
119  bool checkSigma;
120  // check f(U,V)
121  bool checkF;
122 
123  // inner checks
124  // tangency
125  bool checkE, checkHE, checkD, checkHD, checkR;
126  // length
127  bool checkElen, checkRlen;
128  // conjugacy
129  bool checkEHR, checkDHR;
130 
131  CheckList() : checkUV(false), checkRes(false), checkSyms(false),
132  checkSigma(false), checkF(false),
133  checkE(false), checkHE(false), checkD(false), checkHD(false), checkR(false),
134  checkElen(false), checkRlen(false),
135  checkEHR(false), checkDHR(false) {};
136  };
137  // subproblem return codes
138  enum trRetType {
139  UNINITIALIZED = 0,
140  MAXIMUM_ITERATIONS,
141  NEGATIVE_CURVATURE,
142  EXCEEDED_TR,
143  KAPPA_CONVERGENCE,
144  THETA_CONVERGENCE,
145  NOTHING
146  };
147  // these correspond to above
148  std::vector<std::string> stopReasons_;
149  typedef Teuchos::ScalarTraits<double> SCT;
150 
151  // private members
152  // Riemannian metric
153  // g(eta,eta)
154  double innerProduct( const Epetra_MultiVector &etaU,
155  const Epetra_MultiVector &etaV ) const;
156  // g(eta,zeta)
157  double innerProduct( const Epetra_MultiVector &etaU,
158  const Epetra_MultiVector &etaV,
159  const Epetra_MultiVector &zetaU,
160  const Epetra_MultiVector &zetaV ) const;
161  // Retraction, in situ
162  void retract( const Epetra_MultiVector &xU,
163  const Epetra_MultiVector &xV,
164  Epetra_MultiVector &etaU,
165  Epetra_MultiVector &etaV ) const;
166  // Apply Hessian
167  void Hess( const Epetra_MultiVector &xU,
168  const Epetra_MultiVector &xV,
169  const Epetra_MultiVector &etaU,
170  const Epetra_MultiVector &etaV,
171  Epetra_MultiVector &HetaU,
172  Epetra_MultiVector &HetaV ) const;
173  // Project back to tangent plane
174  void Proj( const Epetra_MultiVector &xU,
175  const Epetra_MultiVector &xV,
176  Epetra_MultiVector &etaU,
177  Epetra_MultiVector &etaV ) const;
178  // solve the trust-region subproblem
179  void solveTRSubproblem();
180  // private initialize routine
181  void initialize();
182  // compute sym(S) = 0.5*(S+S')
183  void Sym(Epetra_MultiVector &S) const;
184  // compute f(x) and other stuff
185  void updateF();
186  // compute residuals and their norms
187  void updateResiduals();
188  // debugging checks
189  void Debug(const CheckList &chk, std::string where) const;
190  // print status
191  void printStatus() const;
192 
193 
194  // Is this object initialized?
195  bool isInitialized_;
196 
197  // Vector holding N
198  std::vector<double> N_;
199 
200  // Pointer to the snapshots
202  // state multivecs
203  Teuchos::RCP<Epetra_MultiVector> U_, V_, // current iterate
204  AU_, AV_, // A*V and A'*U
205  RU_, RV_, // residual, gradient and residual of model minimization
206  etaU_, etaV_, // subproblem solution
207  HeU_, HeV_, // eta under Hessian
208  deltaU_, deltaV_, // search directions
209  HdU_, HdV_; // search directions under Hessian
210 
211  // Vector holding singular values.
212  std::vector<double> sigma_;
213 
214  // Convergence tolerance
215  double tol_;
216 
217  // ortho manager: need this for qf()
219 
220  // cummulative timer
221  Teuchos::Time timerComp_;
222 
223  // debug flag
224  bool debug_;
225 
226  // verb level
227  int verbLevel_;
228 
229  // residual norms: individual and combined
230  std::vector<double> resNorms_;
231  std::vector<double> resUNorms_, resVNorms_;
232  double maxScaledNorm_;
233 
234  // trust-region state
235  // initial and current trust-region radius
236  double Delta0_, Delta_, Delta_bar_;
237  // |eta|
238  double etaLen_;
239  // acceptance parameter
240  double rhoPrime_;
241  // norm of the initial gradient
242  double normGrad0_;
243  // number of outer iterations
244  int iter_;
245  // maximum number of outer iterations
246  int maxOuterIters_;
247  // maximum number of inner iterations
248  int maxInnerIters_;
249  // convergence parameters
250  double conv_kappa_, conv_theta_;
251  // most recent rho
252  double rho_, rhonum_, rhoden_;
253  bool tiny_rhonum_, zero_rhoden_, neg_rho_;
254  // current objective function
255  double fx_;
256  // last inner stop
257  trRetType innerStop_;
258  // previous update was accepted or not
259  bool accepted_;
260  // num inner iterations
261  int numInner_;
262  // trust region adjustment
263  std::string tradjust_;
264  // dimensions of problem
265  int m_, n_, rank_;
266  // is V local or distributed
267  bool localV_;
268  // init with elementary vectors or random
269  bool initElem_;
270 
271  // UAVNsym, VAUNsym
272  // we need sym(U'*A*V*N) and sym(V'*A'*U*N)
273  // for the Hessian
274  Teuchos::RCP<Epetra_MultiVector> UAVNsym_, VAUNsym_;
275 
276  // DGESVD workspace
279  std::vector<double> dgesvd_work_;
280  };
281 
282 } // end of RBGen namespace
283 
284 #endif // RBGEN_STSVD_RTR_H
std::vector< double > getSingularValues() const
Return the singular values.
void updateBasis(const Teuchos::RCP< Epetra_MultiVector > &update_ss)
Update the current basis using a new set of snapshots.
std::vector< double > getResNorms()
Return the scaled residual norms.
virtual ~StSVDRTR()
Destructor.
void Reset(const Teuchos::RCP< Epetra_MultiVector > &new_ss)
Reset the snapshot set used to compute the reduced basis.
StSVDRTR()
Default constructor.
Abstract base class for reduced basis methods.
Abstract base class for reduced basis POD methods.
void computeBasis()
Computes bases for the left and (optionally) right singular subspaces, along with singular vaues...
double getCompTime() const
Return the cummulative wall-clock time.
Class for producing a POD basis using a trust-region optimization on the Stiefel manifold.
double totalElapsedTime(bool readCurrentTime=false) const
Teuchos::RCP< const Epetra_MultiVector > getRightBasis() const
Return a basis for the right singular subspace.
Teuchos::RCP< const Epetra_MultiVector > getBasis() const
Return a basis for the left singular subspace.
void Initialize(const Teuchos::RCP< Teuchos::ParameterList > &params, const Teuchos::RCP< const Epetra_MultiVector > &init, const Teuchos::RCP< RBGen::FileIOHandler< Epetra_Operator > > &fileio=Teuchos::null)
Initialize the method with the given parameter list and snapshot set.