2012-02-27 09:18:36 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
|
* All Rights Reserved
|
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file GaussNewtonOptimizer.cpp
|
|
|
|
|
* @brief
|
|
|
|
|
* @author Richard Roberts
|
|
|
|
|
* @created Feb 26, 2012
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gtsam/nonlinear/GaussNewtonOptimizer.h>
|
|
|
|
|
#include <gtsam/linear/GaussianMultifrontalSolver.h>
|
|
|
|
|
#include <gtsam/linear/GaussianSequentialSolver.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace gtsam {
|
|
|
|
|
|
2012-04-05 07:20:42 +08:00
|
|
|
/* ************************************************************************* */
|
2012-05-15 03:10:02 +08:00
|
|
|
void GaussNewtonOptimizer::iterate() {
|
2012-04-05 10:45:47 +08:00
|
|
|
|
2012-05-15 00:51:33 +08:00
|
|
|
const NonlinearOptimizerState& current = state_;
|
2012-02-27 09:18:36 +08:00
|
|
|
|
|
|
|
|
// Linearize graph
|
2012-05-15 00:51:33 +08:00
|
|
|
GaussianFactorGraph::shared_ptr linear = graph_.linearize(current.values, *params_.ordering);
|
2012-02-27 09:18:36 +08:00
|
|
|
|
|
|
|
|
// Check whether to use QR
|
2012-02-28 13:30:53 +08:00
|
|
|
bool useQR;
|
2012-05-15 00:51:33 +08:00
|
|
|
if(params_.factorization == GaussNewtonParams::LDL)
|
2012-02-27 09:18:36 +08:00
|
|
|
useQR = false;
|
2012-05-15 00:51:33 +08:00
|
|
|
else if(params_.factorization == GaussNewtonParams::QR)
|
2012-02-27 09:18:36 +08:00
|
|
|
useQR = true;
|
|
|
|
|
else
|
|
|
|
|
throw runtime_error("Optimization parameter is invalid: GaussNewtonParams::factorization");
|
|
|
|
|
|
|
|
|
|
// Optimize
|
|
|
|
|
VectorValues::shared_ptr delta;
|
2012-05-15 00:51:33 +08:00
|
|
|
if(params_.elimination == GaussNewtonParams::MULTIFRONTAL)
|
2012-02-27 09:18:36 +08:00
|
|
|
delta = GaussianMultifrontalSolver(*linear, useQR).optimize();
|
2012-05-15 00:51:33 +08:00
|
|
|
else if(params_.elimination == GaussNewtonParams::SEQUENTIAL)
|
2012-02-27 09:18:36 +08:00
|
|
|
delta = GaussianSequentialSolver(*linear, useQR).optimize();
|
|
|
|
|
else
|
|
|
|
|
throw runtime_error("Optimization parameter is invalid: GaussNewtonParams::elimination");
|
|
|
|
|
|
|
|
|
|
// Maybe show output
|
2012-05-15 00:51:33 +08:00
|
|
|
if(params_.verbosity >= NonlinearOptimizerParams::DELTA) delta->print("delta");
|
2012-02-27 09:18:36 +08:00
|
|
|
|
2012-04-05 10:45:47 +08:00
|
|
|
// Create new state with new values and new error
|
2012-05-15 00:51:33 +08:00
|
|
|
state_.values = current.values.retract(*delta, *params_.ordering);
|
|
|
|
|
state_.error = graph_.error(state_.values);
|
|
|
|
|
++ state_.iterations;
|
2012-04-05 07:20:42 +08:00
|
|
|
}
|
|
|
|
|
|
2012-02-27 09:18:36 +08:00
|
|
|
} /* namespace gtsam */
|