2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 6 See LICENSE for the license information 8 Unit tests for IMU testing scenarios. 9 Author: Frank Dellaert & Duy Nguyen Ta (Python) 13 from __future__
import print_function
18 from gtsam
import (DoglegOptimizer, DoglegParams,
19 DummyPreconditionerParameters, GaussNewtonOptimizer,
20 GaussNewtonParams, LevenbergMarquardtOptimizer,
21 LevenbergMarquardtParams, NonlinearFactorGraph, Ordering,
22 PCGSolverParameters, Point2, PriorFactorPoint2, Values)
31 """Do trivial test with three optimizer variants.""" 32 fg = NonlinearFactorGraph()
38 optimal_values = Values()
39 optimal_values.insert(KEY1, xstar)
40 self.assertEqual(0.0, fg.error(optimal_values), 0.0)
44 initial_values = Values()
45 initial_values.insert(KEY1, x0)
46 self.assertEqual(9.0, fg.error(initial_values), 1e-3)
50 ordering.push_back(KEY1)
53 gnParams = GaussNewtonParams()
54 gnParams.setOrdering(ordering)
55 actual1 = GaussNewtonOptimizer(fg, initial_values, gnParams).
optimize()
56 self.assertAlmostEqual(0, fg.error(actual1))
59 lmParams = LevenbergMarquardtParams.CeresDefaults()
60 lmParams.setOrdering(ordering)
61 actual2 = LevenbergMarquardtOptimizer(
62 fg, initial_values, lmParams).
optimize()
63 self.assertAlmostEqual(0, fg.error(actual2))
66 lmParams = LevenbergMarquardtParams.CeresDefaults()
67 lmParams.setLinearSolverType(
"ITERATIVE")
68 cgParams = PCGSolverParameters()
69 cgParams.setPreconditionerParams(DummyPreconditionerParameters())
70 lmParams.setIterativeParams(cgParams)
71 actual2 = LevenbergMarquardtOptimizer(
72 fg, initial_values, lmParams).
optimize()
73 self.assertAlmostEqual(0, fg.error(actual2))
76 dlParams = DoglegParams()
77 dlParams.setOrdering(ordering)
78 actual3 = DoglegOptimizer(fg, initial_values, dlParams).
optimize()
79 self.assertAlmostEqual(0, fg.error(actual3))
82 if __name__ ==
"__main__":
static shared_ptr Create(size_t dim)
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)