moved logging at the end of the iteration

release/4.3a0
Luca 2014-04-22 11:55:16 -04:00
parent e98c4c2ac2
commit 67cfe5ea66
1 changed files with 11 additions and 14 deletions

View File

@ -214,20 +214,6 @@ void LevenbergMarquardtOptimizer::iterate() {
// Build damped system for this lambda (adds prior factors that make it like gradient descent) // Build damped system for this lambda (adds prior factors that make it like gradient descent)
GaussianFactorGraph dampedSystem = buildDampedSystem(*linear); GaussianFactorGraph dampedSystem = buildDampedSystem(*linear);
// Log current error/lambda to file
if (!params_.logFile.empty()) {
ofstream os(params_.logFile.c_str(), ios::app);
boost::posix_time::ptime currentTime =
boost::posix_time::microsec_clock::universal_time();
os << state_.totalNumberInnerIterations << ","
<< 1e-6 * (currentTime - state_.startTime).total_microseconds() << ","
<< state_.error << "," << state_.lambda << endl;
}
++state_.totalNumberInnerIterations;
// Try solving // Try solving
double modelFidelity = 0.0; double modelFidelity = 0.0;
bool step_is_successful = false; bool step_is_successful = false;
@ -300,6 +286,17 @@ void LevenbergMarquardtOptimizer::iterate() {
} }
} }
// Log current error/lambda to file
if (!params_.logFile.empty()) {
ofstream os(params_.logFile.c_str(), ios::app);
boost::posix_time::ptime currentTime = boost::posix_time::microsec_clock::universal_time();
os << /*inner iterations*/ state_.totalNumberInnerIterations << ","
<< 1e-6 * (currentTime - state_.startTime).total_microseconds() << ","
<< /*current error*/ state_.error << "," << state_.lambda << ","
<< /*outer iterations*/ state_.iterations << endl;
}
++state_.totalNumberInnerIterations;
if (step_is_successful) { // we have successfully decreased the cost and we have good modelFidelity if (step_is_successful) { // we have successfully decreased the cost and we have good modelFidelity
state_.values.swap(newValues); state_.values.swap(newValues);
state_.error = newError; state_.error = newError;