Module: Linear Algebra Group: Decomposition classes
Does not inherit
#include <rw/lapack/sv.h> #include <rw/lapack/svddccalc.h> RWGenMat<double> A; . . . RWSVDecomp<double,RWSVDDivConqCalc<double> >sv(A);
A singular value decomposition is a representation of a matrix A of the form:
where U and V are orthogonal, and E is diagonal. The entries along the diagonal of E are the singular values; the columns of U are the left singular vectors, and the columns of V are the right singular vectors.
The class RWSVDecomp<T> is used to construct and work with singular value decompositions. The singular values are always ordered smallest to largest with this class. You may need more control over the computation of the decomposition than is provided by this class. For example, if you don't need all the singular vectors, you can use the SV decomposition server class, RWSVDecompServer<T>, to do the construction.
The template parameter <SVDCalc> determines the algorithm used by the RWSVDecomp<T> class to compute the singular value decomposition and must implement the following method:
NOTE -- For greater flexibility, the user can implement this method, or the Linear Algebra Module provides two classes to perform this function - RWSVDCalc<T> and RWSVDDivConqCalc<T>. Please see their descriptions in this reference guide for more information.
bool computeSVD(const RWGenMat<T>& A,
RWGenMat<T>& U,
RWGenMat<T>& VT,
RWMathVec<norm_type>& sigma,
norm_type tolerance,
int numLeftVecs = -1
int numRightVecs = -1);
where norm_type is a typedef for rw_numeric_traits<T>::norm_type.
Parameters:
A - The input matrix for which the singular value decomposition is being computed.
U - The output matrix of left singular victors (the columns of U are the left singular vectors).
VT - The output matrix of right singular victors (the rows of VT are the right singular victors).
sigma - The output vector of singular values in descending order.
tolerance - The input singular values with magnitude less than tolerance will be set to zero.
numLeftVectors - The input number of left vectors to compute. If the number is less than zero, the default number of vectors will be computed (it is up to the developer to determine what the default is).
numRightVectors - The input number of right vectors to compute. If the number is less than zero, the default number of vectors will be computed (it is up to the developer to determine what the default is).
The return value is True if the decomposition was successfully computed.
#include <rw/iostream> #include <rw/lapack/sv.h> #include <rw/lapack/svddccalc.h> int main() { RWGenMat<double> A; std::cin >> A; RWSVDecomp<double, RWSVDDivConqCalc<double> > sv(A); std::cout << "Input matrix: " << A << std::endl; std::cout << "singular values: " << sv.singularValues() << std::endl; std::cout << "left vectors: " << sv.leftVectors() << std::endl; std::cout << "right vectors: " << sv.rightVectors() << std::endl; return 0; }
RWSVDecomp();
Default constructor. Builds a decomposition of size 0 x 0.
RWSVDecomp(const RWSVDecomp<T,SVDCalc>& A);
Copy constructor. References the data in the original decomposition for efficiency.
RWSVDecomp(const RWGenMat<float>, float tol=0); RWSVDecomp(const RWGenMat<double>, double tol=0); RWSVDecomp(const RWGenMat<DComplex>, double tol=0);
Builds a singular value decomposition of A. The parameter tol specifies the accuracy to which the singular values are required. By default, they are computed to within machine precision. To construct a singular value decomposition with non-default options, you can use the singular value decomposition server classes RWSVDecompServer<T>.
unsigned cols();
Returns the number of columns in the matrix that the decomposition represents.
void RWSVDecomp<float,SVDCalc>::factor(const
RWGenMat<float>&, float tol=0); void RWSVDecomp<double,SVDCalc>::factor(const
RWGenMat<double>&, double tol=0); void RWSVDecomp<DComplex,SVDCalc>::factor(const
RWGenMat<DComplex>&, double tol=0);
Builds a singular value decomposition of A. The parameter tol specifies the accuracy to which the singular values are required. By default, they are computed to within machine precision. To construct a singular value decomposition with non-default options, you can use the singular value decomposition server class RWSVDecompServer<T>.
unsigned fail(); unsigned good();
Returns an indication of whether all singular values are successfully computed.
RWMathVec<T> leftVector(int i);
Returns the ith left singular vector. Throws an exception if the ith vector is not computed.
RWGenMat<T> leftVectors();
Returns a matrix whose columns are the left singular vectors.
unsigned numLeftVectors(); unsigned numRightVectors();
Returns the number of left or right singular vectors computed.
unsigned rank();
Returns the rank of the matrix. The rank is indicated by the number of nonzero singular values.
RWMathVec<T> rightVector(int i);
Returns the ith right singular vector. Throws an exception if the ith vector is not computed.
RWGenMat<T> rightVectors();
Returns a matrix whose columns are the right singular vectors.
unsigned rows();
Returns the number of rows in the matrix that the decomposition represents.
T singularValue(int i);
Returns the ith singular value.
RWMathVec<T> singularValues();
Returns the vector of singular values.
void RWSVDecomp<float,SVDCalc>::truncate(float tol=0); void RWSVDecomp<double,SVDCalc>::truncate(double tol=0); void RWSVDecomp<DComplex,SVDCalc>::truncate(double tol=0);
Truncates all singular values with magnitude less than tol by setting them to 0. If tol is a measure of the expected error in entries of the matrix, this truncation provides a more meaningful decomposition. The rank of the decomposition is a measure of the numerical rank of the matrix.
void operator=(const RWSVDecomp<T,SVDCalc>&);
Assigns the passed value to this decomposition . The current contents of the decomposition are lost.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.