39 using namespace gtsam;
169 paramsChol.
linearSolverType = LevenbergMarquardtParams::MULTIFRONTAL_CHOLESKY;
192 graph.
addPrior(
X(1),
Pose2(0.,0.,0.), noiseModel::Isotropic::Sigma(3, 1
e-10));
196 ordering.push_back(
X(1));
197 ordering.push_back(
X(2));
200 LevenbergMarquardtParams::SetLegacyDefaults(¶ms);
216 fg.
push_back(NonlinearFactorGraph::sharedFactor());
251 fg.
addPrior(0,
Pose2(0, 0, 0), noiseModel::Isotropic::Sigma(3, 1));
253 noiseModel::Isotropic::Sigma(3, 1));
255 noiseModel::Isotropic::Sigma(3, 1));
303 for (
auto& [
key,
value] : sqrtHessianDiagonal) {
354 fg.
addPrior(0,
Pose2(0,0,0), noiseModel::Isotropic::Sigma(3,1));
356 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(2.0),
357 noiseModel::Isotropic::Sigma(3,1)));
359 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(3.0),
360 noiseModel::Isotropic::Sigma(3,1)));
363 init.insert(0,
Pose2(0,0,0));
364 init.insert(1,
Pose2(0.961187, 0.99965, 1.1781));
368 expected.
insert(1,
Pose2(0.961187, 0.99965, 1.1781));
385 fg.
addPrior(0,
Point2(0,0), noiseModel::Isotropic::Sigma(2,0.01));
387 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(1.0),
388 noiseModel::Isotropic::Sigma(2,1)));
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)));
397 init.insert(0,
Point2(1,1));
398 init.insert(1,
Point2(1,0));
419 fg.
addPrior(0,
Pose2(0,0, 0), noiseModel::Isotropic::Sigma(3,0.1));
421 noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(0.2),
422 noiseModel::Isotropic::Sigma(3,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)));
434 init.insert(0,
Pose2(0, 0, 0));
461 auto huber = noiseModel::Robust::Create(noiseModel::mEstimator::Huber::Create(20),
462 noiseModel::Isotropic::Sigma(1, 1));
464 vector<double> pts{-10,-3,-1,1,3,10,1000};
470 expected.
insert(0, 3.33333333);
497 graph.
addPrior(
X(1),
Pose2(0.,0.,0.), noiseModel::Isotropic::Sigma(3,1));
499 graph.
addPrior(
X(3),
Pose2(3.,0.,0.), noiseModel::Isotropic::Sigma(3,1));
517 LevenbergMarquardtParams::LegacyDefaults())
520 initial_(initialValues) {}
543 graph.
addPrior(
X(1),
Pose2(0., 0., 0.), noiseModel::Isotropic::Sigma(3, 1));
545 noiseModel::Isotropic::Sigma(3, 1));
546 graph.
addPrior(
X(3),
Pose2(3., 0., 0.), noiseModel::Isotropic::Sigma(3, 1));
564 static const string filename(
"testNonlinearOptimizer.log");
590 size_t lastIterCalled = 0;
591 lmParams.
iterationHook = [&](
size_t iteration,
double oldError,
double newError)
594 lastIterCalled = iteration;
595 EXPECT(newError<oldError);
615 size_t lastIterCalled = 0;
616 cgParams.
iterationHook = [&](
size_t iteration,
double oldError,
double newError)
619 lastIterCalled = iteration;
620 EXPECT(newError<oldError);
641 return (a - b).array().abs().maxCoeff() <
tol;
652 fg.
addPrior(0,
MyType(0, 0, 0), noiseModel::Isotropic::Sigma(3, 1));
const gtsam::Symbol key('X', 0)
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
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
#define DOUBLES_EQUAL(expected, actual, threshold)
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
const Values & optimize() override
NonlinearFactorGraph createReallyNonlinearFactorGraph()
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
TEST_UNSAFE(NonlinearOptimizer, MoreOptimization)
IterativeLM(const NonlinearFactorGraph &graph, const Values &initialValues, const ConjugateGradientParameters &p, const LevenbergMarquardtParams ¶ms=LevenbergMarquardtParams::LegacyDefaults())
Constructor.
Iterative methods, implementation.
iterator insert(const std::pair< Key, Vector > &key_value)
static const Point3 pt(1.0, 2.0, 3.0)
const Values & values() const
return values in current optimizer state
NonlinearFactorGraph graph
static enum @1107 ordering
static const SmartProjectionParams params
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Vector conjugateGradientDescent(const System &Ab, const Vector &x, const ConjugateGradientParameters ¶meters)
static int GetDimension(const MyType &)
TEST(NonlinearOptimizer, paramsEquals)
VectorValues zeroVectors() const
std::string logFile
an optional CSV log file, with [iteration, time, error, lambda]
void setVerbosity(const std::string &src)
#define EXPECT(condition)
LevenbergMarquardtParams lmParams
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Linear Factor Graph where all factors are Gaussians.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
double error(const Values &values) const
virtual VectorValues hessianDiagonal() const
void setRelativeErrorTol(double value)
static MyType Retract(const MyType &a, const Vector3 &b)
GaussianFactorGraph::shared_ptr iterate() override
bool diagonalDamping
if true, use diagonal of Hessian
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
void insert(Key j, const Value &val)
GaussianFactorGraph buildDampedSystem(const GaussianFactorGraph &linear, const VectorValues &sqrtHessianDiagonal) const
bool equals(const NonlinearOptimizerParams &other, double tol=1e-9) const
std::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty) ...
VectorValues solve(const GaussianFactorGraph &gfg, const NonlinearOptimizerParams ¶ms) const override
Solve that uses conjugate gradient.
virtual GaussianFactorGraph::shared_ptr linearize() const
Simple non-linear optimizer that solves using non-preconditioned CG.
virtual VectorValues gradientAtZero() const
ConjugateGradientParameters cgParams_
Solver specific parameters.
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
double lambdaInitial
The initial Levenberg-Marquardt damping term (default: 1e-5)