25 #ifndef INCLUDED_ParamFindingRoutine_h_GUID_C2088279_D54B_4D8B_562E_5748C748DAD0 26 #define INCLUDED_ParamFindingRoutine_h_GUID_C2088279_D54B_4D8B_562E_5748C748DAD0 46 template <
typename TrackingReferenceType,
typename ParamSet>
50 std::cout <<
"Max runs: " << maxRuns << std::endl;
55 ParamVec x = ParamSet::getInitialVec(commonData);
57 std::cout <<
"Optimizing, respectively: " 58 << ParamSet::getVecElementNames() <<
"\n";
59 std::cout <<
"Initial vector:\n" 61 auto functor = [&](ParamVec
const ¶mVec) ->
double {
65 ParamSet::updateParamsFromVec(params, paramVec);
67 auto optim = OptimData::make(params, commonData);
70 TrackingReferenceType ref;
71 std::size_t samples = 0;
75 for (
auto const &rowPtr : data) {
76 mainAlgo(optim, *rowPtr);
78 if (ref.havePose() && mainAlgo.havePose()) {
88 auto avgCost = (accum /
static_cast<double>(samples));
89 auto numResets = mainAlgo.getNumResets(optim);
93 avgCost * (numResets + 1) * (numResets + 1) / samples;
94 if (std::isnan(effectiveCost)) {
95 effectiveCost = getReallyBigCost();
98 <<
" effective cost (average cost of " << std::setw(9)
99 << avgCost <<
" over " << std::setw(4) << samples
100 <<
" eligible frames with " << std::setw(2)
101 << numResets <<
" resets)\n";
102 return effectiveCost;
104 std::cout <<
"No samples with pose for both algorithms?" 106 return getReallyBigCost();
110 auto cost = functor(x);
112 <<
"The computed cost of these initial parameter values is " 113 << cost << std::endl;
117 static_cast<long>(maxRuns), functor);
118 std::cout <<
"Optimizer returned " << ret
119 <<
" and these parameter values:" << std::endl;
121 std::cout <<
"for parameters described as, respectively,\n" 122 << ParamSet::getVecElementNames() << std::endl;
124 using ParamOptimizerFunc = std::function<void(
125 MeasurementsRows
const &,
bool,
OptimCommonData const &, std::size_t)>;
128 #endif // INCLUDED_ParamFindingRoutine_h_GUID_C2088279_D54B_4D8B_562E_5748C748DAD0 Eigen::IOFormat const & getFullFormat()
Use for output of parameters.
Definition: UtilityFunctions.h:61
Algorithm functor to be called in a loop that processes measurements rows: feeds in LEDs (stage 2) an...
Definition: OptimizationBase.h:115
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
double ei_newuoa_wrapped(long npt, Eigen::MatrixBase< Derived > &x, std::pair< double, double > rho, long maxfun, Function &&f)
Friendlier wrapper around newuoa: takes a vector for x, and the function takes a reference to const v...
Definition: newuoa.h:1943
void runOptimizer(MeasurementsRows const &data, bool costOnly, OptimCommonData const &commonData, std::size_t maxRuns)
The main optimization routine, in which we run the tracker repeatedly with different parameters and c...
Definition: ParamFindingRoutine.h:47
std::string to_string(Eigen::Quaterniond const &quat)
Helper to convert to string for messages.
Definition: EigenTestHelpers.h:46
General configuration parameters.
Definition: ConfigParams.h:82
Input from main to the optimization routine (wrapper)
Definition: OptimizationBase.h:47
double costMeasurement(Eigen::Isometry3d const &refPose, Eigen::Isometry3d const &expPose)
Definition: UtilityFunctions.h:137
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127