Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly parse optimizer params for base optimizer in gnc #1085

Merged
merged 2 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gtsam/nonlinear/GncOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class GTSAM_EXPORT GncOptimizer {
/// Compute optimal solution using graduated non-convexity.
Values optimize() {
NonlinearFactorGraph graph_initial = this->makeWeightedGraph(weights_);
BaseOptimizer baseOptimizer(graph_initial, state_);
BaseOptimizer baseOptimizer(
graph_initial, state_, params_.baseOptimizerParams);
Values result = baseOptimizer.optimize();
double mu = initializeMu();
double prev_cost = graph_initial.error(result);
Expand Down Expand Up @@ -227,7 +228,8 @@ class GTSAM_EXPORT GncOptimizer {

// variable/values update
NonlinearFactorGraph graph_iter = this->makeWeightedGraph(weights_);
BaseOptimizer baseOptimizer_iter(graph_iter, state_);
BaseOptimizer baseOptimizer_iter(
graph_iter, state_, params_.baseOptimizerParams);
result = baseOptimizer_iter.optimize();

// stopping condition
Expand Down
24 changes: 24 additions & 0 deletions tests/testGncOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ TEST(GncOptimizer, gncConstructor) {
CHECK(gnc.equals(gnc2));
}

/* ************************************************************************* */
TEST(GncOptimizer, solverParameterParsing) {
// has to have Gaussian noise models !
auto fg = example::createReallyNonlinearFactorGraph(); // just a unary factor
// on a 2D point

Point2 p0(3, 3);
Values initial;
initial.insert(X(1), p0);

LevenbergMarquardtParams lmParams;
lmParams.setMaxIterations(0); // forces not to perform optimization
GncParams<LevenbergMarquardtParams> gncParams(lmParams);
auto gnc = GncOptimizer<GncParams<LevenbergMarquardtParams>>(fg, initial,
gncParams);
Values result = gnc.optimize();

// check that LM did not perform optimization and result is the same as the initial guess
DOUBLES_EQUAL(fg.error(initial), fg.error(result), tol);

// also check the params:
DOUBLES_EQUAL(0.0, gncParams.baseOptimizerParams.maxIterations, tol);
}

/* ************************************************************************* */
TEST(GncOptimizer, gncConstructorWithRobustGraphAsInput) {
auto fg = example::sharedNonRobustFactorGraphWithOutliers();
Expand Down