OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
QRSolver.h
Go to the documentation of this file.
1 #ifndef OPAL_QRSolver_HH
2 #define OPAL_QRSolver_HH 1
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: QRSolver.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: QRSolver
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2000/03/27 09:33:35 $
17 // $Author: Andreas Adelmann $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Algebra/Matrix.h"
22 #include "Algebra/Vector.h"
23 #include <cstddef>
24 
25 
26 // Class QRSolver
27 // ------------------------------------------------------------------------
29 // Given an m by n matrix A, an n by n diagonal matrix D,
30 // and an m-vector B, two problem can be solved:
31 // [ol][li]
32 // Solve the the system $A*X = B$ in the least squares sense.
33 // The first step to solve this problem is:
34 // [pre]
35 // QRSolver solver(A, pivot);
36 // [/pre]
37 // The second step is then
38 // [pre]
39 // solver.solveR(X);
40 // [/pre]
41 // [li]
42 // Solve the the two systems $A*X = B, D*X = 0$ in the least squares sense.
43 // The first step to solve this problem is
44 // [pre]
45 // QRSolver solver(A, pivot);
46 // [/pre]
47 // The second step is
48 // [pre]
49 // solver.solveS(D, X);
50 // [/pre]
51 // The second step can be repeated as many times as required for different
52 // diagonal matrices $D$.
53 // [/ol]
54 // In both cases, the method
55 // [pre]
56 // solver.getColNorm(C);
57 // [/pre]
58 // can be called to return the original column norms of $A$.
59 
60 class QRSolver {
61 
62 public:
63 
65  // Determine the QR-factorisation $A = Q*R$ of the matrix $A$
66  // and transform the right-hand side $B$. If [b]pivot[/b] is
67  // true, then pivot search is done.
68  // [p]
69  // This method uses Householder transformations with optional column
70  // pivoting to compute a QR-factorization of the m-by-n matrix $A$.
71  // It determines an orthogonal matrix $Q$, a permutation matrix $P$,
72  // and an upper trapezoidal matrix $R$ with diagonal elements of
73  // nonincreasing magnitude, such that $A*P = Q*R$. The Householder
74  // transformation for column $k$ is of the form $I - (1/U(k))*U*U^T$,
75  // where $U$ has zeros in the first $k-1$ positions.
76  // The form of this transformation and the method of pivoting first
77  // appeared in the corresponding LINPACK subroutine.
78  QRSolver(const Matrix<double> &A, const Vector<double> &B, bool pivot);
79 
80  ~QRSolver();
81 
83  void solveR(Vector<double> &X) const;
84 
86  void solveS(const Array1D<double> &D, double p, Vector<double> &X);
87 
89  void solveRT(Vector<double> &V) const;
90 
92  // Requires prior execution of solveS.
93  void solveST(Vector<double> &V) const;
94 
96  void getColNorm(Array1D<double> &) const;
97 
98 private:
99 
100  // Transform R to S, given the diagonal matrix D.
101  void R_to_S(const Matrix<double> &R,
102  const Array1D<double> &D,
103  Matrix<double> &S,
104  Vector<double> &Z);
105 
106  // Solution of R*X = QtB.
107  void solve(const Matrix<double> &R,
108  const Vector<double> &QtB,
109  Vector<double> &X) const;
110 
111  // Solution of R.transpose()**(-1) * V
112  void solveT(const Matrix<double> &R, Vector<double> &V) const;
113 
114  // The dimensions of the problem.
115  int n; // number of columns.
116  int m; // number of rows.
117 
118  // The lower trapezoidal part of the matrix Q contains the n vectors
119  // defining a factored form of the orthogonal matrix Q.
121 
122  // The upper-trapezoidal matrix R contains the matrix R.
124 
125  // The transformed r.h.s. Q.transpose() * B.
127 
128  // The upper-trapezoidal matrix S contains the matrix S.
130 
131  // The vector column_norm contains the original column norms of M.
133 
134  // The vector piv_col defines the permutation matrix P.
135  // Column j of P is column piv_col(j) of the identity matrix.
137 };
138 
139 #endif // OPAL_QRSolver_HH
int n
Definition: QRSolver.h:115
void R_to_S(const Matrix< double > &R, const Array1D< double > &D, Matrix< double > &S, Vector< double > &Z)
Definition: QRSolver.cpp:179
int m
Definition: QRSolver.h:116
Array1D< double > column_norm
Definition: QRSolver.h:132
void solveRT(Vector< double > &V) const
Pre-multiply the vector $V$ by $R.transpose()^{-1}$.
Definition: QRSolver.cpp:164
Definition: rbendmap.h:8
Array1D< int > piv_col
Definition: QRSolver.h:136
void getColNorm(Array1D< double > &) const
Return the original column norms of the matrix $A$.
Definition: QRSolver.cpp:174
void solveST(Vector< double > &V) const
Pre-multiply the vector $V$ by $S.transpose()^{-1}$.
Definition: QRSolver.cpp:169
Matrix< double > R
Definition: QRSolver.h:123
Array2D< double > Q
Definition: QRSolver.h:120
Least-square solution of systems of linear equations.
Definition: QRSolver.h:60
void solveR(Vector< double > &X) const
Solution of $A*X = B$ in the least-squares sense.
Definition: QRSolver.cpp:148
QRSolver(const Matrix< double > &A, const Vector< double > &B, bool pivot)
Constructor.
Definition: QRSolver.cpp:64
void solve(const Matrix< double > &R, const Vector< double > &QtB, Vector< double > &X) const
Definition: QRSolver.cpp:228
void solveT(const Matrix< double > &R, Vector< double > &V) const
Definition: QRSolver.cpp:257
Vector< double > QtB
Definition: QRSolver.h:126
Matrix< double > S
Definition: QRSolver.h:129
void solveS(const Array1D< double > &D, double p, Vector< double > &X)
Solution of $A*X = B, D*X = 0$ in the least-squares sense.
Definition: QRSolver.cpp:153