29 #include "bias_config.h"
31 #include <Base/Debug/Error.hh>
32 #include <Base/Debug/Debug.hh>
34 #include <Base/Math/Matrix.hh>
35 #include <Base/Math/Vector.hh>
47 #define DEFAULT_DOUBLE_ZERO_THRESHOLD 1E-8
49 #define SVDSOLVE 0x00000001
50 #define D_SVD_RANK 0x00000002
51 #define D_SVD_SOLVE 0x00000004
107 double ZeroThreshold = DEFAULT_DOUBLE_ZERO_THRESHOLD,
108 bool AbsoluteZeroThreshold =
true);
117 inline SVD(
bool AbsoluteZeroThreshold =
true) {
119 ZeroThreshold_ = DEFAULT_DOUBLE_ZERO_THRESHOLD;
120 AbsoluteZeroThreshold_ = AbsoluteZeroThreshold;
129 double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD);
133 double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD)
134 {
return Compute(M, ZeroThreshold); };
136 #ifdef BIAS_HAVE_OPENCV
144 double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD);
156 int General_Eigenproblem_GeneralMatrix_Lapack(
const Matrix<double> &M);
161 {
return ZeroThreshold_; }
173 inline const double GetSingularValue(
int index )
const;
193 if (U_.num_cols()>VT_.num_cols())
194 return U_.num_cols();
196 return VT_.num_cols();
210 if (AbsoluteZeroThreshold_)
return AbsNullspaceDim();
211 else return RelNullspaceDim();
217 if (AbsoluteZeroThreshold_)
return AbsRightNullspaceDim();
218 else return RelRightNullspaceDim();
224 if (AbsoluteZeroThreshold_)
return AbsLeftNullspaceDim();
225 else return RelLeftNullspaceDim();
235 const int AbsNullspaceDim()
const;
240 const int AbsRightNullspaceDim()
const;
245 const int AbsLeftNullspaceDim()
const;
252 const int RelNullspaceDim()
const;
253 const int RelRightNullspaceDim()
const;
254 const int RelLeftNullspaceDim()
const;
274 const int last_offset = 0 );
284 inline bool GetLeftNullvector(
Vector<double>&nv,
const int last_offset=0);
287 inline Vector<double> GetLeftNullvector(
const int last_offset = 0 );
293 {
return Solve(y); };
308 #ifdef BIAS_HAVE_OPENCV
388 BIASASSERT( index >=0 );
389 BIASASSERT( index <
size() );
414 const int last_offset )
438 BIASERR(
"No left nullvector for "<<last_offset);
444 const int last_offset) {
448 BIASERR(
"for last_offset=" <<last_offset
450 <<
" can no left nullvector be retrieved. aborting. ");
Vector< double > GetNullvector(const int last_offset=0)
return one of the nullvectors.
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Subscript num_cols() const
Matrix< T > Transpose() const
transpose function, storing data destination matrix
const int NullspaceDim() const
return the dim of the nullspace.
bool GetLeftNullvector(Vector< double > &nv, const int last_offset=0)
Return one of the left nullvectors.
Vector< double > S_
contains the singular values of A_ corresponding to the i'th column in descending order...
Vector< double > solve(const Vector< double > &y) const
use our naming convention
SVD(bool AbsoluteZeroThreshold=true)
creates an empty svd without automatically decomposing any matrix
int size() const
return the length of the singular value vector inline const int size() const
double GetZeroThreshold() const
return zerothresh currently used
Vector< T > & newsize(Subscript N)
const double GetSingularValue(int index) const
return one singular value (which may be zero).
const int RightNullspaceDim() const
returns the dim of the matrix's right nullspace
Matrix< double > GetV() const
return V
const Matrix< double > & GetVT() const
return VT (=transposed(V))
bool Decomposed_
flag for holding decomposed matrix
const Vector< double > & GetS() const
return S which is a vector of the singular values of A in descending order.
const int LeftNullspaceDim() const
returns the dim of the matrix's left nullspace
Matrix< double > A_
data members: original matrix (to be decomposed)
Matrix< double > VT_
contains the right singular vectors of A- in rows [because VT is transpose(V) ]
double ZeroThreshold_
values below this threshold are treated as zero
const Matrix< double > & GetU() const
return U U is a m x m orthogonal matrix
Subscript num_rows() const
bool AbsoluteZeroThreshold_
determines whether we compare singular-values directly (absolute) to the zero threshold or whether we...
Matrix< double > U_
contains columnwise the left singular vectors of A_ corresponding to the i'th singular value ...
int compute(const Matrix< double > &M, double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD)
use our naming convention