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
|
2012-10-02 22:40:07 +08:00
|
|
|
* @date Feb 26, 2012
|
2012-02-27 09:18:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gtsam/nonlinear/GaussNewtonOptimizer.h>
|
2013-08-02 05:57:33 +08:00
|
|
|
#include <gtsam/linear/GaussianFactorGraph.h>
|
|
|
|
|
#include <gtsam/linear/VectorValues.h>
|
2012-02-27 09:18:36 +08:00
|
|
|
|
|
|
|
|
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
|
2013-08-02 05:57:33 +08:00
|
|
|
GaussianFactorGraph::shared_ptr linear = graph_.linearize(current.values);
|
2012-02-27 09:18:36 +08:00
|
|
|
|
2012-07-25 05:06:33 +08:00
|
|
|
// Solve Factor Graph
|
2013-10-26 02:27:43 +08:00
|
|
|
const VectorValues delta = solve(*linear, current.values, params_);
|
2012-02-27 09:18:36 +08:00
|
|
|
|
|
|
|
|
// Maybe show output
|
2012-05-15 13:08:57 +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
|
2013-08-02 05:57:33 +08:00
|
|
|
state_.values = current.values.retract(delta);
|
2012-05-15 00:51:33 +08:00
|
|
|
state_.error = graph_.error(state_.values);
|
|
|
|
|
++ state_.iterations;
|
2012-04-05 07:20:42 +08:00
|
|
|
}
|
|
|
|
|
|
2013-08-02 05:57:33 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
GaussNewtonParams GaussNewtonOptimizer::ensureHasOrdering(
|
|
|
|
|
GaussNewtonParams params, const NonlinearFactorGraph& graph) const
|
|
|
|
|
{
|
|
|
|
|
if(!params.ordering)
|
2014-11-18 05:16:52 +08:00
|
|
|
params.ordering = Ordering::colamd(graph);
|
2013-08-02 05:57:33 +08:00
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 09:18:36 +08:00
|
|
|
} /* namespace gtsam */
|