28 #include <boost/shared_ptr.hpp> 53 double currentFactor,
unsigned int iterations = 0,
54 unsigned int totalNumberInnerIterations = 0)
57 currentFactor(currentFactor),
58 totalNumberInnerIterations(totalNumberInnerIterations) {}
62 unsigned int iterations = 0,
unsigned int totalNumberInnerIterations = 0)
65 currentFactor(currentFactor),
66 totalNumberInnerIterations(totalNumberInnerIterations) {}
72 totalNumberInnerIterations += 1;
82 Values&& newValues,
double newError)
const {
88 newLambda *=
std::max(1.0 / 3.0, 1.0 -
pow(2.0 * stepQuality - 1.0, 3));
92 return std::unique_ptr<This>(
new This(std::move(newValues), newError, newLambda, newFactor,
93 iterations + 1, totalNumberInnerIterations + 1));
101 :
A(
Matrix::Identity(dim, dim)),
103 model(noiseModel::Isotropic::Sigma(dim, sigma)) {}
107 model(noiseModel::Isotropic::Sigma(dim, sigma)) {}
116 if (dim >= noiseModelCache.size())
117 noiseModelCache.resize(dim+1);
126 noiseModelCache.
resize(0);
129 for (
const auto key_value :
values) {
130 const Key key = key_value.key;
131 const size_t dim = key_value.value.
dim();
133 damped += boost::make_shared<JacobianFactor>(
key, item->
A, item->
b, item->
model);
141 noiseModelCache.
resize(0);
143 for (
const auto& key_vector : sqrtHessianDiagonal) {
145 const Key key = key_vector.first;
146 const size_t dim = key_vector.second.size();
148 item->
A.diagonal() = sqrtHessianDiagonal.at(key);
149 damped += boost::make_shared<JacobianFactor>(
key, item->
A, item->
b, item->
model);
150 }
catch (
const std::out_of_range&) {
LevenbergMarquardtState(Values &&initialValues, double error, double lambda, double currentFactor, unsigned int iterations=0, unsigned int totalNumberInnerIterations=0)
CachedModel * getCachedModel(size_t dim) const
A non-templated config holding any types of Manifold-group elements.
GaussianFactorGraph buildDampedSystem(GaussianFactorGraph damped) const
Build a damped system for a specific lambda, vanilla version.
LevenbergMarquardtState This
static const double sigma
void diagonal(const MatrixType &m)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Namespace containing all symbols from the Eigen library.
CachedModel(int dim, double sigma)
GaussianFactorGraph buildDampedSystem(GaussianFactorGraph damped, const VectorValues &sqrtHessianDiagonal) const
Build a damped system, use hessianDiagonal per variable (more expensive)
std::vector< CachedModel > noiseModelCache
std::unique_ptr< This > decreaseLambda(const LevenbergMarquardtParams ¶ms, double stepQuality, Values &&newValues, double newError) const
CachedModel(int dim, double sigma, const Vector &diagonal)
bool useFixedLambdaFactor
if true applies constant increase (or decrease) to lambda according to lambdaFactor ...
Linear Factor Graph where all factors are Gaussians.
static SmartStereoProjectionParams params
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
noiseModel::Diagonal::shared_ptr SharedDiagonal
typedef and functions to augment Eigen's VectorXd
double lambdaLowerBound
The minimum lambda used in LM (default: 0)
LevenbergMarquardtState(const Values &initialValues, double error, double lambda, double currentFactor, unsigned int iterations=0, unsigned int totalNumberInnerIterations=0)
Private class for NonlinearOptimizer state.
int totalNumberInnerIterations
The total number of inner iterations in the.
void reserve(size_t size)
Jet< T, N > pow(const Jet< T, N > &f, double g)
friend const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
std::uint64_t Key
Integer nonlinear key type.
void increaseLambda(const LevenbergMarquardtParams ¶ms)