MOAB
4.9.3pre
|
Performs a real Schur decomposition of a square matrix. More...
#include <RealSchur.h>
Public Types | |
enum | { RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime } |
typedef _MatrixType | MatrixType |
typedef MatrixType::Scalar | Scalar |
typedef std::complex< typename NumTraits< Scalar >::Real > | ComplexScalar |
typedef Eigen::Index | Index |
typedef Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > | EigenvalueType |
typedef Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > | ColumnVectorType |
Public Member Functions | |
RealSchur (Index size=RowsAtCompileTime==Dynamic?1:RowsAtCompileTime) | |
Default constructor. | |
template<typename InputType > | |
RealSchur (const EigenBase< InputType > &matrix, bool computeU=true) | |
Constructor; computes real Schur decomposition of given matrix. | |
const MatrixType & | matrixU () const |
Returns the orthogonal matrix in the Schur decomposition. | |
const MatrixType & | matrixT () const |
Returns the quasi-triangular matrix in the Schur decomposition. | |
template<typename InputType > | |
RealSchur & | compute (const EigenBase< InputType > &matrix, bool computeU=true) |
Computes Schur decomposition of given matrix. | |
template<typename HessMatrixType , typename OrthMatrixType > | |
RealSchur & | computeFromHessenberg (const HessMatrixType &matrixH, const OrthMatrixType &matrixQ, bool computeU) |
Computes Schur decomposition of a Hessenberg matrix H = Z T Z^T. | |
ComputationInfo | info () const |
Reports whether previous computation was successful. | |
RealSchur & | setMaxIterations (Index maxIters) |
Sets the maximum number of iterations allowed. | |
Index | getMaxIterations () |
Returns the maximum number of iterations. | |
Static Public Attributes | |
static const int | m_maxIterationsPerRow = 40 |
Maximum number of iterations per row. | |
Private Types | |
typedef Matrix< Scalar, 3, 1 > | Vector3s |
Private Member Functions | |
Scalar | computeNormOfT () |
Index | findSmallSubdiagEntry (Index iu) |
void | splitOffTwoRows (Index iu, bool computeU, const Scalar &exshift) |
void | computeShift (Index iu, Index iter, Scalar &exshift, Vector3s &shiftInfo) |
void | initFrancisQRStep (Index il, Index iu, const Vector3s &shiftInfo, Index &im, Vector3s &firstHouseholderVector) |
void | performFrancisQRStep (Index il, Index im, Index iu, bool computeU, const Vector3s &firstHouseholderVector, Scalar *workspace) |
Private Attributes | |
MatrixType | m_matT |
MatrixType | m_matU |
ColumnVectorType | m_workspaceVector |
HessenbergDecomposition < MatrixType > | m_hess |
ComputationInfo | m_info |
bool | m_isInitialized |
bool | m_matUisUptodate |
Index | m_maxIters |
Performs a real Schur decomposition of a square matrix.
_MatrixType | the type of the matrix of which we are computing the real Schur decomposition; this is expected to be an instantiation of the Matrix class template. |
Given a real square matrix A, this class computes the real Schur decomposition: where U is a real orthogonal matrix and T is a real quasi-triangular matrix. An orthogonal matrix is a matrix whose inverse is equal to its transpose,
. A quasi-triangular matrix is a block-triangular matrix whose diagonal consists of 1-by-1 blocks and 2-by-2 blocks with complex eigenvalues. The eigenvalues of the blocks on the diagonal of T are the same as the eigenvalues of the matrix A, and thus the real Schur decomposition is used in EigenSolver to compute the eigendecomposition of a matrix.
Call the function compute() to compute the real Schur decomposition of a given matrix. Alternatively, you can use the RealSchur(const MatrixType&, bool) constructor which computes the real Schur decomposition at construction time. Once the decomposition is computed, you can use the matrixU() and matrixT() functions to retrieve the matrices U and T in the decomposition.
The documentation of RealSchur(const MatrixType&, bool) contains an example of the typical use of this class.
Definition at line 54 of file RealSchur.h.
typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::RealSchur< _MatrixType >::ColumnVectorType |
Definition at line 70 of file RealSchur.h.
typedef std::complex<typename NumTraits<Scalar>::Real> Eigen::RealSchur< _MatrixType >::ComplexScalar |
Definition at line 66 of file RealSchur.h.
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::RealSchur< _MatrixType >::EigenvalueType |
Definition at line 69 of file RealSchur.h.
typedef Eigen::Index Eigen::RealSchur< _MatrixType >::Index |
Definition at line 67 of file RealSchur.h.
typedef _MatrixType Eigen::RealSchur< _MatrixType >::MatrixType |
Definition at line 57 of file RealSchur.h.
typedef MatrixType::Scalar Eigen::RealSchur< _MatrixType >::Scalar |
Definition at line 65 of file RealSchur.h.
typedef Matrix<Scalar,3,1> Eigen::RealSchur< _MatrixType >::Vector3s [private] |
Definition at line 236 of file RealSchur.h.
anonymous enum |
Definition at line 58 of file RealSchur.h.
{ RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime };
Eigen::RealSchur< _MatrixType >::RealSchur | ( | Index | size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime | ) | [inline, explicit] |
Default constructor.
[in] | size | Positive integer, size of the matrix whose Schur decomposition will be computed. |
The default constructor is useful in cases in which the user intends to perform decompositions via compute(). The size
parameter is only used as a hint. It is not an error to give a wrong size
, but it may impair performance.
Definition at line 83 of file RealSchur.h.
: RowsAtCompileTime) : m_matT(size, size), m_matU(size, size), m_workspaceVector(size), m_hess(size), m_isInitialized(false), m_matUisUptodate(false), m_maxIters(-1) { }
Eigen::RealSchur< _MatrixType >::RealSchur | ( | const EigenBase< InputType > & | matrix, |
bool | computeU = true |
||
) | [inline, explicit] |
Constructor; computes real Schur decomposition of given matrix.
[in] | matrix | Square matrix whose Schur decomposition is to be computed. |
[in] | computeU | If true, both T and U are computed; if false, only T is computed. |
This constructor calls compute() to compute the Schur decomposition.
Example:
Output:
Definition at line 104 of file RealSchur.h.
: m_matT(matrix.rows(),matrix.cols()), m_matU(matrix.rows(),matrix.cols()), m_workspaceVector(matrix.rows()), m_hess(matrix.rows()), m_isInitialized(false), m_matUisUptodate(false), m_maxIters(-1) { compute(matrix.derived(), computeU); }
RealSchur< MatrixType > & Eigen::RealSchur< MatrixType >::compute | ( | const EigenBase< InputType > & | matrix, |
bool | computeU = true |
||
) |
Computes Schur decomposition of given matrix.
[in] | matrix | Square matrix whose Schur decomposition is to be computed. |
[in] | computeU | If true, both T and U are computed; if false, only T is computed. |
*this
The Schur decomposition is computed by first reducing the matrix to Hessenberg form using the class HessenbergDecomposition. The Hessenberg matrix is then reduced to triangular form by performing Francis QR iterations with implicit double shift. The cost of computing the Schur decomposition depends on the number of iterations; as a rough guide, it may be taken to be flops if computeU is true and
flops if computeU is false.
Example:
Output:
Definition at line 249 of file RealSchur.h.
{ eigen_assert(matrix.cols() == matrix.rows()); Index maxIters = m_maxIters; if (maxIters == -1) maxIters = m_maxIterationsPerRow * matrix.rows(); // Step 1. Reduce to Hessenberg form m_hess.compute(matrix.derived()); // Step 2. Reduce to real Schur form computeFromHessenberg(m_hess.matrixH(), m_hess.matrixQ(), computeU); return *this; }
RealSchur< MatrixType > & Eigen::RealSchur< MatrixType >::computeFromHessenberg | ( | const HessMatrixType & | matrixH, |
const OrthMatrixType & | matrixQ, | ||
bool | computeU | ||
) |
Computes Schur decomposition of a Hessenberg matrix H = Z T Z^T.
[in] | matrixH | Matrix in Hessenberg form H |
[in] | matrixQ | orthogonal matrix Q that transform a matrix A to H : A = Q H Q^T |
computeU | Computes the matriX U of the Schur vectors |
*this
This routine assumes that the matrix is already reduced in Hessenberg form matrixH using either the class HessenbergDecomposition or another mean. It computes the upper quasi-triangular matrix T of the Schur decomposition of H When computeU is true, this routine computes the matrix U such that A = U T U^T = (QZ) T (QZ)^T = Q H Q^T where A is the initial matrix
NOTE Q is referenced if computeU is true; so, if the initial orthogonal matrix is not available, the user should give an identity matrix (Q.setIdentity())
Definition at line 266 of file RealSchur.h.
{ m_matT = matrixH; if(computeU) m_matU = matrixQ; Index maxIters = m_maxIters; if (maxIters == -1) maxIters = m_maxIterationsPerRow * matrixH.rows(); m_workspaceVector.resize(m_matT.cols()); Scalar* workspace = &m_workspaceVector.coeffRef(0); // The matrix m_matT is divided in three parts. // Rows 0,...,il-1 are decoupled from the rest because m_matT(il,il-1) is zero. // Rows il,...,iu is the part we are working on (the active window). // Rows iu+1,...,end are already brought in triangular form. Index iu = m_matT.cols() - 1; Index iter = 0; // iteration count for current eigenvalue Index totalIter = 0; // iteration count for whole matrix Scalar exshift(0); // sum of exceptional shifts Scalar norm = computeNormOfT(); if(norm!=0) { while (iu >= 0) { Index il = findSmallSubdiagEntry(iu); // Check for convergence if (il == iu) // One root found { m_matT.coeffRef(iu,iu) = m_matT.coeff(iu,iu) + exshift; if (iu > 0) m_matT.coeffRef(iu, iu-1) = Scalar(0); iu--; iter = 0; } else if (il == iu-1) // Two roots found { splitOffTwoRows(iu, computeU, exshift); iu -= 2; iter = 0; } else // No convergence yet { // The firstHouseholderVector vector has to be initialized to something to get rid of a silly GCC warning (-O1 -Wall -DNDEBUG ) Vector3s firstHouseholderVector(0,0,0), shiftInfo; computeShift(iu, iter, exshift, shiftInfo); iter = iter + 1; totalIter = totalIter + 1; if (totalIter > maxIters) break; Index im; initFrancisQRStep(il, iu, shiftInfo, im, firstHouseholderVector); performFrancisQRStep(il, im, iu, computeU, firstHouseholderVector, workspace); } } } if(totalIter <= maxIters) m_info = Success; else m_info = NoConvergence; m_isInitialized = true; m_matUisUptodate = computeU; return *this; }
MatrixType::Scalar Eigen::RealSchur< MatrixType >::computeNormOfT | ( | ) | [inline, private] |
Computes and returns vector L1 norm of T
Definition at line 335 of file RealSchur.h.
{ const Index size = m_matT.cols(); // FIXME to be efficient the following would requires a triangular reduxion code // Scalar norm = m_matT.upper().cwiseAbs().sum() // + m_matT.bottomLeftCorner(size-1,size-1).diagonal().cwiseAbs().sum(); Scalar norm(0); for (Index j = 0; j < size; ++j) norm += m_matT.col(j).segment(0, (std::min)(size,j+2)).cwiseAbs().sum(); return norm; }
void Eigen::RealSchur< MatrixType >::computeShift | ( | Index | iu, |
Index | iter, | ||
Scalar & | exshift, | ||
Vector3s & | shiftInfo | ||
) | [inline, private] |
Form shift in shiftInfo, and update exshift if an exceptional shift is performed.
Definition at line 400 of file RealSchur.h.
{ using std::sqrt; using std::abs; shiftInfo.coeffRef(0) = m_matT.coeff(iu,iu); shiftInfo.coeffRef(1) = m_matT.coeff(iu-1,iu-1); shiftInfo.coeffRef(2) = m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu); // Wilkinson's original ad hoc shift if (iter == 10) { exshift += shiftInfo.coeff(0); for (Index i = 0; i <= iu; ++i) m_matT.coeffRef(i,i) -= shiftInfo.coeff(0); Scalar s = abs(m_matT.coeff(iu,iu-1)) + abs(m_matT.coeff(iu-1,iu-2)); shiftInfo.coeffRef(0) = Scalar(0.75) * s; shiftInfo.coeffRef(1) = Scalar(0.75) * s; shiftInfo.coeffRef(2) = Scalar(-0.4375) * s * s; } // MATLAB's new ad hoc shift if (iter == 30) { Scalar s = (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0); s = s * s + shiftInfo.coeff(2); if (s > Scalar(0)) { s = sqrt(s); if (shiftInfo.coeff(1) < shiftInfo.coeff(0)) s = -s; s = s + (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0); s = shiftInfo.coeff(0) - shiftInfo.coeff(2) / s; exshift += s; for (Index i = 0; i <= iu; ++i) m_matT.coeffRef(i,i) -= s; shiftInfo.setConstant(Scalar(0.964)); } } }
Index Eigen::RealSchur< MatrixType >::findSmallSubdiagEntry | ( | Index | iu | ) | [inline, private] |
Look for single small sub-diagonal element and returns its index
Definition at line 349 of file RealSchur.h.
Index Eigen::RealSchur< _MatrixType >::getMaxIterations | ( | ) | [inline] |
Returns the maximum number of iterations.
Definition at line 213 of file RealSchur.h.
{ return m_maxIters; }
ComputationInfo Eigen::RealSchur< _MatrixType >::info | ( | ) | const [inline] |
Reports whether previous computation was successful.
Success
if computation was succesful, NoConvergence
otherwise. Definition at line 195 of file RealSchur.h.
{ eigen_assert(m_isInitialized && "RealSchur is not initialized."); return m_info; }
void Eigen::RealSchur< MatrixType >::initFrancisQRStep | ( | Index | il, |
Index | iu, | ||
const Vector3s & | shiftInfo, | ||
Index & | im, | ||
Vector3s & | firstHouseholderVector | ||
) | [inline, private] |
Compute index im at which Francis QR step starts and the first Householder vector.
Definition at line 442 of file RealSchur.h.
{ using std::abs; Vector3s& v = firstHouseholderVector; // alias to save typing for (im = iu-2; im >= il; --im) { const Scalar Tmm = m_matT.coeff(im,im); const Scalar r = shiftInfo.coeff(0) - Tmm; const Scalar s = shiftInfo.coeff(1) - Tmm; v.coeffRef(0) = (r * s - shiftInfo.coeff(2)) / m_matT.coeff(im+1,im) + m_matT.coeff(im,im+1); v.coeffRef(1) = m_matT.coeff(im+1,im+1) - Tmm - r - s; v.coeffRef(2) = m_matT.coeff(im+2,im+1); if (im == il) { break; } const Scalar lhs = m_matT.coeff(im,im-1) * (abs(v.coeff(1)) + abs(v.coeff(2))); const Scalar rhs = v.coeff(0) * (abs(m_matT.coeff(im-1,im-1)) + abs(Tmm) + abs(m_matT.coeff(im+1,im+1))); if (abs(lhs) < NumTraits<Scalar>::epsilon() * rhs) break; } }
const MatrixType& Eigen::RealSchur< _MatrixType >::matrixT | ( | ) | const [inline] |
Returns the quasi-triangular matrix in the Schur decomposition.
Definition at line 144 of file RealSchur.h.
{ eigen_assert(m_isInitialized && "RealSchur is not initialized."); return m_matT; }
const MatrixType& Eigen::RealSchur< _MatrixType >::matrixU | ( | ) | const [inline] |
Returns the orthogonal matrix in the Schur decomposition.
computeU
was set to true (the default value).Definition at line 127 of file RealSchur.h.
{ eigen_assert(m_isInitialized && "RealSchur is not initialized."); eigen_assert(m_matUisUptodate && "The matrix U has not been computed during the RealSchur decomposition."); return m_matU; }
void Eigen::RealSchur< MatrixType >::performFrancisQRStep | ( | Index | il, |
Index | im, | ||
Index | iu, | ||
bool | computeU, | ||
const Vector3s & | firstHouseholderVector, | ||
Scalar * | workspace | ||
) | [inline, private] |
Perform a Francis QR step involving rows il:iu and columns im:iu.
Definition at line 467 of file RealSchur.h.
{ eigen_assert(im >= il); eigen_assert(im <= iu-2); const Index size = m_matT.cols(); for (Index k = im; k <= iu-2; ++k) { bool firstIteration = (k == im); Vector3s v; if (firstIteration) v = firstHouseholderVector; else v = m_matT.template block<3,1>(k,k-1); Scalar tau, beta; Matrix<Scalar, 2, 1> ess; v.makeHouseholder(ess, tau, beta); if (beta != Scalar(0)) // if v is not zero { if (firstIteration && k > il) m_matT.coeffRef(k,k-1) = -m_matT.coeff(k,k-1); else if (!firstIteration) m_matT.coeffRef(k,k-1) = beta; // These Householder transformations form the O(n^3) part of the algorithm m_matT.block(k, k, 3, size-k).applyHouseholderOnTheLeft(ess, tau, workspace); m_matT.block(0, k, (std::min)(iu,k+3) + 1, 3).applyHouseholderOnTheRight(ess, tau, workspace); if (computeU) m_matU.block(0, k, size, 3).applyHouseholderOnTheRight(ess, tau, workspace); } } Matrix<Scalar, 2, 1> v = m_matT.template block<2,1>(iu-1, iu-2); Scalar tau, beta; Matrix<Scalar, 1, 1> ess; v.makeHouseholder(ess, tau, beta); if (beta != Scalar(0)) // if v is not zero { m_matT.coeffRef(iu-1, iu-2) = beta; m_matT.block(iu-1, iu-1, 2, size-iu+1).applyHouseholderOnTheLeft(ess, tau, workspace); m_matT.block(0, iu-1, iu+1, 2).applyHouseholderOnTheRight(ess, tau, workspace); if (computeU) m_matU.block(0, iu-1, size, 2).applyHouseholderOnTheRight(ess, tau, workspace); } // clean up pollution due to round-off errors for (Index i = im+2; i <= iu; ++i) { m_matT.coeffRef(i,i-2) = Scalar(0); if (i > im+2) m_matT.coeffRef(i,i-3) = Scalar(0); } }
RealSchur& Eigen::RealSchur< _MatrixType >::setMaxIterations | ( | Index | maxIters | ) | [inline] |
Sets the maximum number of iterations allowed.
If not specified by the user, the maximum number of iterations is m_maxIterationsPerRow times the size of the matrix.
Definition at line 206 of file RealSchur.h.
{ m_maxIters = maxIters; return *this; }
void Eigen::RealSchur< MatrixType >::splitOffTwoRows | ( | Index | iu, |
bool | computeU, | ||
const Scalar & | exshift | ||
) | [inline, private] |
Update T given that rows iu-1 and iu decouple from the rest.
Definition at line 365 of file RealSchur.h.
{ using std::sqrt; using std::abs; const Index size = m_matT.cols(); // The eigenvalues of the 2x2 matrix [a b; c d] are // trace +/- sqrt(discr/4) where discr = tr^2 - 4*det, tr = a + d, det = ad - bc Scalar p = Scalar(0.5) * (m_matT.coeff(iu-1,iu-1) - m_matT.coeff(iu,iu)); Scalar q = p * p + m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu); // q = tr^2 / 4 - det = discr/4 m_matT.coeffRef(iu,iu) += exshift; m_matT.coeffRef(iu-1,iu-1) += exshift; if (q >= Scalar(0)) // Two real eigenvalues { Scalar z = sqrt(abs(q)); JacobiRotation<Scalar> rot; if (p >= Scalar(0)) rot.makeGivens(p + z, m_matT.coeff(iu, iu-1)); else rot.makeGivens(p - z, m_matT.coeff(iu, iu-1)); m_matT.rightCols(size-iu+1).applyOnTheLeft(iu-1, iu, rot.adjoint()); m_matT.topRows(iu+1).applyOnTheRight(iu-1, iu, rot); m_matT.coeffRef(iu, iu-1) = Scalar(0); if (computeU) m_matU.applyOnTheRight(iu-1, iu, rot); } if (iu > 1) m_matT.coeffRef(iu-1, iu-2) = Scalar(0); }
HessenbergDecomposition<MatrixType> Eigen::RealSchur< _MatrixType >::m_hess [private] |
Definition at line 230 of file RealSchur.h.
ComputationInfo Eigen::RealSchur< _MatrixType >::m_info [private] |
Definition at line 231 of file RealSchur.h.
bool Eigen::RealSchur< _MatrixType >::m_isInitialized [private] |
Definition at line 232 of file RealSchur.h.
MatrixType Eigen::RealSchur< _MatrixType >::m_matT [private] |
Definition at line 227 of file RealSchur.h.
MatrixType Eigen::RealSchur< _MatrixType >::m_matU [private] |
Definition at line 228 of file RealSchur.h.
bool Eigen::RealSchur< _MatrixType >::m_matUisUptodate [private] |
Definition at line 233 of file RealSchur.h.
const int Eigen::RealSchur< _MatrixType >::m_maxIterationsPerRow = 40 [static] |
Maximum number of iterations per row.
If not otherwise specified, the maximum number of iterations is this number times the size of the matrix. It is currently set to 40.
Definition at line 223 of file RealSchur.h.
Index Eigen::RealSchur< _MatrixType >::m_maxIters [private] |
Definition at line 234 of file RealSchur.h.
ColumnVectorType Eigen::RealSchur< _MatrixType >::m_workspaceVector [private] |
Definition at line 229 of file RealSchur.h.