34 #include <boost/range/adaptor/map.hpp> 35 #include <boost/shared_ptr.hpp> 36 #include <boost/assign/std/list.hpp> 38 using boost::adaptors::map_values;
44 using namespace gtsam;
174 paramsChol.
linearSolverType = LevenbergMarquardtParams::MULTIFRONTAL_CHOLESKY;
197 graph.
addPrior(
X(1),
Pose2(0.,0.,0.), noiseModel::Isotropic::Sigma(3, 1
e-10));
201 ordering.push_back(
X(1));
202 ordering.push_back(
X(2));
205 LevenbergMarquardtParams::SetLegacyDefaults(¶ms);
221 fg.
push_back(NonlinearFactorGraph::sharedFactor());
256 fg.
addPrior(0,
Pose2(0, 0, 0), noiseModel::Isotropic::Sigma(3, 1));
258 noiseModel::Isotropic::Sigma(3, 1));
260 noiseModel::Isotropic::Sigma(3, 1));
308 for (
Vector&
v : sqrtHessianDiagonal | map_values)
v =
v.cwiseSqrt();
357 fg.
addPrior(0,
Pose2(0,0,0), noiseModel::Isotropic::Sigma(3,1));
359 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(2.0),
360 noiseModel::Isotropic::Sigma(3,1)));
362 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(3.0),
363 noiseModel::Isotropic::Sigma(3,1)));
366 init.insert(0,
Pose2(0,0,0));
367 init.insert(1,
Pose2(0.961187, 0.99965, 1.1781));
371 expected.
insert(1,
Pose2(0.961187, 0.99965, 1.1781));
388 fg.
addPrior(0,
Point2(0,0), noiseModel::Isotropic::Sigma(2,0.01));
390 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(1.0),
391 noiseModel::Isotropic::Sigma(2,1)));
393 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(1.0),
394 noiseModel::Isotropic::Sigma(2,1)));
396 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(1.0),
397 noiseModel::Isotropic::Sigma(2,1)));
400 init.insert(0,
Point2(1,1));
401 init.insert(1,
Point2(1,0));
422 fg.
addPrior(0,
Pose2(0,0, 0), noiseModel::Isotropic::Sigma(3,0.1));
424 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(0.2),
425 noiseModel::Isotropic::Sigma(3,1)));
427 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(0.2),
428 noiseModel::Isotropic::Sigma(3,1)));
430 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(0.2),
431 noiseModel::Isotropic::Sigma(3,1)));
433 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(0.2),
434 noiseModel::Isotropic::Sigma(3,1)));
437 init.insert(0,
Pose2(0, 0, 0));
464 auto huber = noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(20),
465 noiseModel::Isotropic::Sigma(1, 1));
467 vector<double> pts{-10,-3,-1,1,3,10,1000};
473 expected.
insert(0, 3.33333333);
500 graph.
addPrior(
X(1),
Pose2(0.,0.,0.), noiseModel::Isotropic::Sigma(3,1));
502 graph.
addPrior(
X(3),
Pose2(3.,0.,0.), noiseModel::Isotropic::Sigma(3,1));
520 LevenbergMarquardtParams::LegacyDefaults())
523 initial_(initialValues) {}
546 graph.
addPrior(
X(1),
Pose2(0., 0., 0.), noiseModel::Isotropic::Sigma(3, 1));
548 noiseModel::Isotropic::Sigma(3, 1));
549 graph.
addPrior(
X(3),
Pose2(3., 0., 0.), noiseModel::Isotropic::Sigma(3, 1));
567 static const string filename(
"testNonlinearOptimizer.log");
593 size_t lastIterCalled = 0;
594 lmParams.
iterationHook = [&](
size_t iteration,
double oldError,
double newError)
597 lastIterCalled = iteration;
598 EXPECT(newError<oldError);
618 size_t lastIterCalled = 0;
619 cgParams.
iterationHook = [&](
size_t iteration,
double oldError,
double newError)
622 lastIterCalled = iteration;
623 EXPECT(newError<oldError);
644 return (a - b).array().abs().maxCoeff() <
tol;
655 fg.
addPrior(0,
MyType(0, 0, 0), noiseModel::Isotropic::Sigma(3, 1));
LevenbergMarquardtParams lm_params
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
virtual const Values & optimize()
static Vector3 Local(const MyType &a, const MyType &b)
static bool Equals(const MyType &a, const MyType &b, double tol)
IterationHook iterationHook
static int runAllTests(TestResult &result)
A non-templated config holding any types of Manifold-group elements.
VectorValues zeroVectors() const
Factor Graph consisting of non-linear factors.
void insert(Key j, const Value &val)
static enum @843 ordering
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
#define DOUBLES_EQUAL(expected, actual, threshold)
const Values & optimize() override
NonlinearFactorGraph createReallyNonlinearFactorGraph()
TEST_UNSAFE(NonlinearOptimizer, MoreOptimization)
IterativeLM(const NonlinearFactorGraph &graph, const Values &initialValues, const ConjugateGradientParameters &p, const LevenbergMarquardtParams ¶ms=LevenbergMarquardtParams::LegacyDefaults())
Constructor.
Iterative methods, implementation.
static const Point3 pt(1.0, 2.0, 3.0)
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
NonlinearFactorGraph graph
bool equals(const NonlinearOptimizerParams &other, double tol=1e-9) const
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
static int GetDimension(const MyType &)
TEST(NonlinearOptimizer, paramsEquals)
std::string logFile
an optional CSV log file, with [iteration, time, error, lambda]
void setVerbosity(const std::string &src)
const Values & values() const
return values in current optimizer state
#define EXPECT(condition)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
boost::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty) ...
Linear Factor Graph where all factors are Gaussians.
static SmartStereoProjectionParams params
GaussianFactorGraph buildDampedSystem(const GaussianFactorGraph &linear, const VectorValues &sqrtHessianDiagonal) const
void setRelativeErrorTol(double value)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Vector conjugateGradientDescent(const System &Ab, const Vector &x, const ConjugateGradientParameters ¶meters)
static MyType Retract(const MyType &a, const Vector3 &b)
GaussianFactorGraph::shared_ptr iterate() override
bool diagonalDamping
if true, use diagonal of Hessian
virtual GaussianFactorGraph::shared_ptr linearize() const
LevenbergMarquardtParams lmParams
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
static void Print(const MyType &, const string &)
Create small example with two poses and one landmark.
GaussianFactorGraph::shared_ptr iterate() override
double error(const Values &values) const
VectorValues solve(const GaussianFactorGraph &gfg, const NonlinearOptimizerParams ¶ms) const override
Solve that uses conjugate gradient.
Simple non-linear optimizer that solves using non-preconditioned CG.
iterator insert(const std::pair< Key, Vector > &key_value)
ConjugateGradientParameters cgParams_
Solver specific parameters.
virtual VectorValues hessianDiagonal() const
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
virtual VectorValues gradientAtZero() const
double lambdaInitial
The initial Levenberg-Marquardt damping term (default: 1e-5)