ANIMA  4.0
animaBVLSOptimizerTest.cxx
Go to the documentation of this file.
1 #include <animaBVLSOptimizer.h>
2 #include <itkTimeProbe.h>
3 #include <iostream>
4 #include <fstream>
5 #include <vnl/algo/vnl_qr.h>
6 
7 int main()
8 {
9  typedef anima::BVLSOptimizer OptimizerType;
10 
11  itk::TimeProbe tmpTime;
12  tmpTime.Start();
13 
14  OptimizerType::Pointer optTest = OptimizerType::New();
15 
16  unsigned int dimX = 23;
17  unsigned int dimY = 23;
18  OptimizerType::MatrixType testData (dimX,dimY);
19  std::ifstream dataMat("dataMatrix.txt");
20 
21  for (unsigned int i = 0;i < dimX;++i)
22  {
23  for (unsigned int j = 0;j < dimY;++j)
24  dataMat >> testData(i,j);
25  }
26 
27  std::cout << "Test data " << testData << std::endl;
28 
29  OptimizerType::ParametersType testPoints(dimX);
30  std::ifstream bVector("bVector.txt");
31 
32  for (unsigned int i = 0;i < dimX;++i)
33  bVector >> testPoints[i];
34 
35  std::cout << "Test points " << testPoints << std::endl;
36 
37  OptimizerType::ParametersType lowerBounds(dimY);
38  std::ifstream lowBounds("lb.txt");
39 
40  for (unsigned int i = 0;i < dimY;++i)
41  lowBounds >> lowerBounds[i];
42 
43  OptimizerType::ParametersType upperBounds(dimY);
44  std::ifstream upBounds("ub.txt");
45 
46  for (unsigned int i = 0;i < dimY;++i)
47  upBounds >> upperBounds[i];
48 
49  optTest->SetDataMatrix(testData);
50  optTest->SetPoints(testPoints);
51 
52  optTest->SetLowerBounds(lowerBounds);
53  optTest->SetUpperBounds(upperBounds);
54 
55  optTest->StartOptimization();
56 
57  tmpTime.Stop();
58 
59  std::cout << "Computation time: " << tmpTime.GetTotal() << std::endl;
60  std::cout << "BVLS solution: " << optTest->GetCurrentPosition() << std::endl;
61  std::cout << "BVLS residual: " << optTest->GetCurrentResidual() << std::endl;
62 
63  std::cout << "LS solution: " << vnl_qr <double> (testData).solve(testPoints) << std::endl;
64 
65  OptimizerType::ParametersType refOutput(dimY);
66  std::ifstream refOutData("ref.txt");
67 
68  for (unsigned int i = 0;i < dimY;++i)
69  refOutData >> refOutput[i];
70 
71 // std::cout << "Scipy solution: " << refOutput << std::endl;
72 // std::cout << "Diff: " << refOutput - optTest->GetCurrentPosition() << std::endl;
73 
74  return EXIT_SUCCESS;
75 }
Bounded variable least squares optimizer. Coming from Stark and Parker paper P.B. Stark and R...
int main()