45 #include <Base/Math/SparseMatrix.hh>
46 #include <MathAlgo/SVD.hh>
47 #include <Base/Math/Random.hh>
49 #ifdef BIAS_HAVE_UMFPACK
61 cout <<
"-- Testing umfpack - conversion and usage -- " << endl;
63 cout <<
"does this get me anywhere " << endl << flush;
83 cout <<
"sparse matrix S " << S << endl;
96 cout <<
"solved with sparse matrix (should be [1 2 3 4 5]) : " << x << endl << flush;
100 cout <<
"ST " << ST << endl;
104 cout <<
"testing invert for larger matrix " << m <<
"x" << m << endl << flush;
105 cout <<
"haaae? "<< endl;
109 for(
int i=0; i < m; i++){
110 for(
int j=0; j < m; j++){
114 cout <<
"setting non-zero element " << endl;
123 cout <<
"new matrix is " << MLarge << endl << flush;
125 cout <<
"building sparse matrix now... " << endl << flush;
128 SparseMatrix SLargeInv(SLarge.GetRowsNum(), SLarge.GetColsNum());
130 cout <<
"maxCols " << SLarge.
GetCols() <<
" actualCols " << SLarge.GetColsNum()
131 <<
" maxRows " << SLarge.GetRows() <<
" actual rows " << SLarge.GetRowsNum() << endl << flush;
133 SLarge.Invert(SLargeInv);
139 SLarge.Invert(MLargeInv);
142 cout <<
"Done with inverting, checking for id now... " << endl;
144 SparseMatrix IdSparse(SLarge.GetRowsNum(), SLargeInv.GetColsNum());
146 SLarge.
Multiply(SLargeInv, IdSparse);
147 IdSparse.GetAsDense(IdSparseAsDense);
149 cout <<
"Done getting sparse id as dense... " << endl;
152 MLarge.
Mult(MLargeInv, IdDense);
155 double epsilon = 1e-8;
156 bool res1 = IdSparseAsDense.IsIdentity(epsilon);
158 cout <<
"testing for identity - sparse : " << res1 << endl;
159 cout <<
"testing for identity - dense : " << res2 << endl;
162 cout <<
"checking norm sparse case " <<
Matrix<double>(IdSparseAsDense - ID).NormFrobenius() << endl;
163 cout <<
"checking norm dense case " <<
Matrix<double>(IdDense - ID).NormFrobenius() << endl;
169 MLarge.
Mult(MLargeInvSvd, idMLarge);
170 cout <<
"checking norm in svd case svd res " <<
Matrix<double>(ID - idMLarge).NormFrobenius() << endl;
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Implementation of sparse matrix operations.
unsigned int GetCols() const
Returns the maximum number of columns (max non-zero entry).
void Mult(const Matrix< T > &arg, Matrix< T > &result) const
matrix multiplication, result is not allocated
void Multiply(const T &scalar, Matrix< T > &dest) const
multiplication function, storing data destination matrix
bool IsIdentity(double eps=0.0) const
Checks if the matrix a an identity.
class for producing random numbers from different distributions
void Transpose(SparseMatrix &result)
Returns transposed matrix in result (as sparse matrix).