ANIMA  4.0
animaQRTest.cxx
Go to the documentation of this file.
1 #include <animaQRDecomposition.h>
2 #include <iostream>
3 #include <fstream>
4 
5 int main(int argc, char **argv)
6 {
7  unsigned int dimX = 12;
8  unsigned int dimY = 6;
9 
10  vnl_matrix <double> testData (dimX,dimY);
11  vnl_vector <double> bVector(dimX);
12  bVector.fill(1.0);
13 
14  if (argc <= 1)
15  {
16  unsigned int pos = 10;
17  for (unsigned int i = 0;i < dimX;++i)
18  {
19  for (unsigned int j = 0;j < dimY;++j)
20  testData(i,j) = pos++;
21 
22  if (i != 0)
23  testData(i,0) = 10;
24  }
25  }
26  else
27  {
28  std::ifstream inputData(argv[1]);
29  for (unsigned int i = 0;i < dimX;++i)
30  {
31  for (unsigned int j = 0;j < dimY;++j)
32  inputData >> testData(i,j);
33  }
34 
35  inputData.close();
36  }
37 
38  std::cout << "Test data " << testData << std::endl;
39 
40  std::vector <double> betaValues(dimY,0.0);
41  std::vector <unsigned int> pivotVector(dimY);
42  unsigned int rank = 0;
43 
44  anima::QRPivotDecomposition(testData,pivotVector,betaValues,rank);
45 
46  std::cout.precision(20);
47  std::cout << "Matrix rank " << rank << std::endl;
48  std::cout << "Transformed matrix " << testData << std::endl;
49 
50  std::cout << "Pivot vector ";
51  for (unsigned int i = 0;i < pivotVector.size();++i)
52  std::cout << pivotVector[i] << " ";
53  std::cout << std::endl;
54 
55  std::cout << "Beta Values ";
56  for (unsigned int i = 0;i < betaValues.size();++i)
57  std::cout << betaValues[i] << " ";
58  std::cout << std::endl;
59 
60  anima::GetQtBFromQRPivotDecomposition(testData,bVector,betaValues,rank);
61 
62  std::cout << "QtB " << bVector << std::endl;
63 
64  vnl_matrix <double> qMatrix (dimX,dimX);
65  anima::GetQMatrixQRPivotDecomposition(testData,betaValues,qMatrix,rank);
66 
67  std::cout << "Q matrix " << qMatrix << std::endl;
68 
69  return EXIT_SUCCESS;
70 }
void QRPivotDecomposition(vnl_matrix< ScalarType > &aMatrix, std::vector< unsigned int > &pivotVector, std::vector< ScalarType > &houseBetaValues, unsigned int &rank)
void GetQtBFromQRPivotDecomposition(vnl_matrix< ScalarType > &qrMatrix, vnl_vector< ScalarType > &bVector, std::vector< ScalarType > &houseBetaValues, unsigned int rank)
void GetQMatrixQRPivotDecomposition(vnl_matrix< ScalarType > &qrMatrix, std::vector< ScalarType > &houseBetaValues, vnl_matrix< ScalarType > &qMatrix, unsigned int rank)
int main(int argc, char **argv)
Definition: animaQRTest.cxx:5