>
>#include <rw/dsv.h> // DoubleSVDecomp #include <rw/fsv.h> // FloatSVDecomp #include <rw/csv.h> // DComplexSVDecomp DoubleSVDecomp sv(A); // A is an RWGenMat<double>
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 classes {TYPE}SVDecomp are used to construct and work with singular value decompositions. The singular values are always ordered smallest to largest with these classes.
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 classes, {TYPE}SVDecompServer, to do the construction.
>#include <rw/iostream.h> #include <rw/dsv.h> main() { RWGenMat<double> A; cin >> A; DoubleSVDecomp sv(A); cout << "Input matrix: " << A << endl; cout << "singular values: " << sv.singularValues() << endl; cout << "left vectors: " << sv.leftVectors() << endl; cout << "right vectors: " << sv.rightVectors() << endl; }>
DoubleSVDecomp(); FloatSVDecomp(); DComplexSVDecomp();
Default constructor. Builds a decomposition of size 0 x 0.
DoubleSVDecomp(const DoubleSVDecomp& A); FloatSVDecomp(const FloatSVDecomp& A); DComplexSVDecomp(const DComplexSVDecomp& A);
Copy constructor. References the data in the original decomposition for efficiency.
DoubleSVDecomp(const RWGenMat<double>& A); FloatSVDecomp(const RWGenMat<float>& A); DComplexSVDecomp(const RWGenMat<DComplex>& A); DoubleSVDecomp(const RWGenMat<double>& A, double tol); FloatSVDecomp(const RWGenMat<float>& A, float tol); DComplexSVDecomp(const RWGenMat<DComplex>& A, double tol);
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 {TYPE}SVDecompServer.
unsigned FloatSVDecomp::cols(); unsigned DoubleSVDecomp::cols(); unsigned DComplexSVDecomp::cols();
Returns the number of columns in the matrix that the decomposition represents.
void DoubleSVDecomp::factor(const RWGenMat<double>& A); void FloatSVDecomp::factor(const RWGenMat<float>& A); void DComplexSVDecomp::factor(const RWGenMat<DComplex>& A); void DoubleSVDecomp::factor(const RWGenMat<double>& A, double tol); void FloatSVDecomp::factor(const RWGenMat<float>& A, float tol); void DComplexSVDecomp::factor(const RWGenMat<DComplex>& A, double tol);
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 {TYPE}SVDecompServer.
unsigned FloatSVDecomp::fail(); unsigned DoubleSVDecomp::fail(); unsigned DComplexSVDecomp::fail(); unsigned FloatSVDecomp::good(); unsigned DoubleSVDecomp::good(); unsigned DComplexSVDecomp::good();
Returns an indication of whether all singular values are successfully computed.
RWMathVec<float> FloatSVDecomp::leftVector(int i); RWMathVec<double> DoubleSVDecomp::leftVector(int i); RWMathVec<DComplex> DComplexSVDecomp::leftVector(int i);
Returns the ith left singular vector. Throws an exception if the ith vector is not computed.
RWGenMat<float> FloatSVDecomp::leftVectors(); RWGenMat<double> DoubleSVDecomp::leftVectors(); RWGenMat<DComplex> DComplexSVDecomp::leftVectors();
Returns a matrix whose columns are the left singular vectors.
unsigned FloatSVDecomp::numLeftVectors(); unsigned DoubleSVDecomp::numLeftVectors(); unsigned DComplexSVDecomp::numLeftVectors(); unsigned FloatSVDecomp::numRightVectors(); unsigned DoubleSVDecomp::numRightVectors(); unsigned DComplexSVDecomp::numRightVectors();
Returns the number of left or right singular vectors computed.
unsigned FloatSVDecomp::rank(); unsigned DoubleSVDecomp::rank(); unsigned DComplexSVDecomp::rank();
Returns the rank of the matrix. The rank is indicated by the number of nonzero singular values.
RWMathVec<float> FloatSVDecomp::rightVector(int i); RWMathVec<double> DoubleSVDecomp::rightVector(int i); RWMathVec<DComplex> DComplexSVDecomp::rightVector(int i);
Returns the ith right singular vector. Throws an exception if the ith vector is not computed.
RWGenMat<float> FloatSVDecomp::rightVectors(); RWGenMat<double> DoubleSVDecomp::rightVectors(); RWGenMat<DComplex> DComplexSVDecomp::rightVectors();
Returns a matrix whose columns are the right singular vectors.
unsigned FloatSVDecomp::rows(); unsigned DoubleSVDecomp::rows(); unsigned DComplexSVDecomp::rows();
Returns the number of rows in the matrix that the decomposition represents.
float FloatSVDecomp::singularValue(int i); double DoubleSVDecomp::singularValue(int i); double DComplexSVDecomp::singularValue(int i);
Returns the ith singular value.
RWMathVec<float> FloatSVDecomp::singularValues(); RWMathVec<double> DoubleSVDecomp::singularValues(); RWMathVec<double> DComplexSVDecomp::singularValues();
Returns the vector of singular values.
void FloatSVDecomp::truncate(float tol); void DoubleSVDecomp::truncate(double tol); void DComplexSVDecomp::truncate(double tol);
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 FloatSVDecomp::operator=(const FloatSVDecomp&); void DoubleSVDecomp::operator=(const DoubleSVDecomp&); void DComplexSVDecomp::operator=(const DComplexSVDecomp&);
Assigns the passed value to this decomposition . The current contents of the decomposition are lost.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.