30 std::cout <<
" Factors:" << std::endl;
50 const boost::optional< std::vector<size_t> >& removeFactorIndices) {
58 gttic(augment_system);
64 for(
const auto key_value: newTheta) {
74 if(removeFactorIndices)
77 gttoc(augment_system);
117 gttic(get_summarized_factors);
125 gttoc(get_summarized_factors);
138 for(
const auto key_value: smootherValues) {
139 std::pair<Values::iterator, bool> iter_inserted =
theta_.
tryInsert(key_value.key, key_value.value);
140 if(iter_inserted.second) {
143 delta_.
insert(key_value.key, Vector::Zero(key_value.value.dim()));
146 iter_inserted.first->value = key_value.value;
149 for(
const auto key_value: separatorValues) {
150 std::pair<Values::iterator, bool> iter_inserted =
theta_.
tryInsert(key_value.key, key_value.value);
151 if(iter_inserted.second) {
154 delta_.
insert(key_value.key, Vector::Zero(key_value.value.dim()));
157 iter_inserted.first->value = key_value.value;
184 gttic(insert_factors);
187 std::vector<size_t> slots;
188 slots.reserve(factors.
size());
201 slots.push_back(slot);
204 gttoc(insert_factors);
212 gttic(remove_factors);
215 for(
size_t slot: slots) {
224 gttoc(remove_factors);
258 double previousError;
261 previousError = result.
error;
264 gttic(optimizer_iteration);
272 std::cout <<
"trying lambda = " << lambda << std::endl;
281 size_t dim = key_value.second.size();
282 Matrix A = Matrix::Identity(dim,dim);
291 dampedFactorGraph.
print(
"damped");
302 std::cout <<
"linear delta norm = " << newDelta.
norm() << std::endl;
304 newDelta.
print(
"delta");
307 gttic(compute_error);
309 gttoc(compute_error);
312 std::cout <<
"next error = " << error << std::endl;
314 if(error < result.
error) {
326 delta_.
at(key_value.key) = newDelta.
at(key_value.key);
338 std::cout <<
"Warning: Levenberg-Marquardt giving up because cannot decrease error with maximum lambda" << std::endl;
347 gttoc(optimizer_iteration);
350 std::cout <<
"using lambda = " << lambda << std::endl;
376 separatorKeys.insert(key_value.key);
387 if(boost::dynamic_pointer_cast<LinearContainerFactor>(factor)) {
393 std::cout << keyFormatter(
key) <<
" ";
395 std::cout <<
")" << std::endl;
397 std::cout <<
"{ nullptr }" << std::endl;
407 std::cout << keyFormatter(
key) <<
" ";
409 std::cout <<
")" << std::endl;
411 std::cout <<
"{ nullptr }" << std::endl;
NonlinearFactorGraph smootherSummarization_
A temporary holding place for calculated smoother summarization.
static void PrintNonlinearFactor(const NonlinearFactor::shared_ptr &factor, const std::string &indent="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
bool equals(const ConcurrentSmoother &rhs, double tol=1e-9) const override
void replace(size_t index, sharedFactor factor)
VectorValues optimize(const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
GTSAM_EXPORT bool equals(const Ordering &other, double tol=1e-9) const
size_t nonlinearVariables
The number of variables that can be relinearized.
virtual Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const boost::optional< std::vector< size_t > > &removeFactorIndices=boost::none)
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph...
size_t lambdas
The number of different L-M lambda factors that were tried during optimization.
Point2 prior(const Point2 &x)
Prior on a single pose.
noiseModel::Diagonal::shared_ptr model
static void PrintLinearFactor(const GaussianFactor::shared_ptr &factor, const std::string &indent="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
void insert(Key j, const Value &val)
void print(const std::string &s="Concurrent Batch Smoother:\n", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
double lambdaFactor
The amount by which to multiply or divide lambda when adjusting lambda (default: 10.0)
Ordering ordering_
The current ordering used to calculate the linear deltas.
Values separatorValues_
The linearization points of the separator variables. These should not be updated during optimization...
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
VectorValues delta_
The current set of linear deltas from the linearization point.
Values retract(const VectorValues &delta) const
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
NonlinearFactorGraph graph
bool equals(const Values &other, double tol=1e-9) const
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues) override
double errorTol
The maximum total error to stop iterating (default 0.0)
bool equals(const NonlinearFactorGraph &other, double tol=1e-9) const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
bool checkConvergence(double relativeErrorTreshold, double absoluteErrorTreshold, double errorThreshold, double currentError, double newError, NonlinearOptimizerParams::Verbosity verbosity)
size_t iterations
The number of optimizer iterations performed.
double error
The final factor graph error.
boost::shared_ptr< This > shared_ptr
VariableIndex variableIndex_
The current variable index, which allows efficient factor lookup by variable.
GaussianFactorGraph::Eliminate getEliminationFunction() const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
NonlinearFactorGraph calculateMarginalFactors(const NonlinearFactorGraph &graph, const Values &theta, const KeySet &remainingKeys, const GaussianFactorGraph::Eliminate &eliminateFunction)
bool equals(const VectorValues &x, double tol=1e-9) const
value_type KeyValuePair
Typedef to pair<Key, Vector>
std::vector< size_t > insertFactors(const NonlinearFactorGraph &factors)
LevenbergMarquardtParams parameters_
LM parameters.
Values theta_
Current linearization point of all variables in the smoother.
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
size_t linearVariables
The number of variables that must keep a constant linearization point.
A Levenberg-Marquardt Batch Smoother that implements the Concurrent Filtering and Smoothing interface...
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
noiseModel::Diagonal::shared_ptr SharedDiagonal
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
std::vector< size_t > filterSummarizationSlots_
The slots in factor graph that correspond to the current filter summarization factors.
virtual void print(const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const
print out graph
NonlinearFactorGraph factors_
The set of all factors currently in the smoother.
void synchronize(const NonlinearFactorGraph &smootherFactors, const Values &smootherValues, const NonlinearFactorGraph &summarizedFactors, const Values &separatorValues) override
void updateSmootherSummarization()
void update(Key j, const Value &val)
void reserve(size_t size)
void removeFactors(const std::vector< size_t > &slots)
double error(const Values &values) const
void print(const std::string &str="VectorValues", const KeyFormatter &formatter=DefaultKeyFormatter) const
double lambdaUpperBound
The maximum lambda to try before assuming the optimization has failed (default: 1e5) ...
std::pair< iterator, bool > tryInsert(Key j, const Value &value)
VerbosityLM verbosityLM
The verbosity level for Levenberg-Marquardt (default: SILENT), see also NonlinearOptimizerParams::ver...
boost::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
std::queue< size_t > availableSlots_
The set of available factor graph slots caused by deleting factors.
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
iterator insert(const std::pair< Key, Vector > &key_value)
std::uint64_t Key
Integer nonlinear key type.
size_t maxIterations
The maximum iterations to stop iterating (default 100)
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
double lambdaInitial
The initial Levenberg-Marquardt damping term (default: 1e-5)