2 #include <itkTimeProbe.h> 5 #include <vnl/algo/vnl_qr.h> 11 itk::TimeProbe tmpTime;
14 OptimizerType::Pointer optTest = OptimizerType::New();
16 unsigned int dimX = 23;
17 unsigned int dimY = 23;
18 OptimizerType::MatrixType testData (dimX,dimY);
19 std::ifstream dataMat(
"dataMatrix.txt");
21 for (
unsigned int i = 0;i < dimX;++i)
23 for (
unsigned int j = 0;j < dimY;++j)
24 dataMat >> testData(i,j);
27 std::cout <<
"Test data " << testData << std::endl;
29 OptimizerType::ParametersType testPoints(dimX);
30 std::ifstream bVector(
"bVector.txt");
32 for (
unsigned int i = 0;i < dimX;++i)
33 bVector >> testPoints[i];
35 std::cout <<
"Test points " << testPoints << std::endl;
37 OptimizerType::ParametersType lowerBounds(dimY);
38 std::ifstream lowBounds(
"lb.txt");
40 for (
unsigned int i = 0;i < dimY;++i)
41 lowBounds >> lowerBounds[i];
43 OptimizerType::ParametersType upperBounds(dimY);
44 std::ifstream upBounds(
"ub.txt");
46 for (
unsigned int i = 0;i < dimY;++i)
47 upBounds >> upperBounds[i];
49 optTest->SetDataMatrix(testData);
50 optTest->SetPoints(testPoints);
52 optTest->SetLowerBounds(lowerBounds);
53 optTest->SetUpperBounds(upperBounds);
55 optTest->StartOptimization();
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;
63 std::cout <<
"LS solution: " << vnl_qr <double> (testData).solve(testPoints) << std::endl;
65 OptimizerType::ParametersType refOutput(dimY);
66 std::ifstream refOutData(
"ref.txt");
68 for (
unsigned int i = 0;i < dimY;++i)
69 refOutData >> refOutput[i];
Bounded variable least squares optimizer. Coming from Stark and Parker paper P.B. Stark and R...