Loading...
Searching...
No Matches
NonlinearOptimizerParams.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/linear/SubgraphSolver.h>
#include <boost/optional.hpp>
#include <string>
namespace gtsam {
class GTSAM_EXPORT NonlinearOptimizerParams {
public:
enum Verbosity {
SILENT, TERMINATION, ERROR, VALUES, DELTA, LINEAR
};
size_t maxIterations = 100;
double relativeErrorTol = 1e-5;
double absoluteErrorTol = 1e-5;
double errorTol = 0.0;
Verbosity verbosity = SILENT;
Ordering::OrderingType orderingType = Ordering::COLAMD;
size_t getMaxIterations() const { return maxIterations; }
double getRelativeErrorTol() const { return relativeErrorTol; }
double getAbsoluteErrorTol() const { return absoluteErrorTol; }
double getErrorTol() const { return errorTol; }
std::string getVerbosity() const { return verbosityTranslator(verbosity); }
void setMaxIterations(int value) { maxIterations = value; }
void setRelativeErrorTol(double value) { relativeErrorTol = value; }
void setAbsoluteErrorTol(double value) { absoluteErrorTol = value; }
void setErrorTol(double value) { errorTol = value; }
void setVerbosity(const std::string& src) {
verbosity = verbosityTranslator(src);
}
static Verbosity verbosityTranslator(const std::string &s) ;
static std::string verbosityTranslator(Verbosity value) ;
using IterationHook = std::function<
void(size_t /*iteration*/, double/*errorBefore*/, double/*errorAfter*/)>;
IterationHook iterationHook;
enum LinearSolverType {
MULTIFRONTAL_CHOLESKY,
MULTIFRONTAL_QR,
SEQUENTIAL_CHOLESKY,
SEQUENTIAL_QR,
Iterative, /* Experimental Flag */
CHOLMOD, /* Experimental Flag */
};
LinearSolverType linearSolverType = MULTIFRONTAL_CHOLESKY;
boost::optional<Ordering> ordering;
IterativeOptimizationParameters::shared_ptr iterativeParams;
NonlinearOptimizerParams() = default;
virtual ~NonlinearOptimizerParams() {
}
virtual void print(const std::string& str = "") const;
bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9) const {
return maxIterations == other.getMaxIterations()
&& std::abs(relativeErrorTol - other.getRelativeErrorTol()) <= tol
&& std::abs(absoluteErrorTol - other.getAbsoluteErrorTol()) <= tol
&& std::abs(errorTol - other.getErrorTol()) <= tol
&& verbosityTranslator(verbosity) == other.getVerbosity();
// && orderingType.equals(other.getOrderingType()_;
// && linearSolverType == other.getLinearSolverType();
// TODO: check ordering, iterativeParams, and iterationsHook
}
inline bool isMultifrontal() const {
return (linearSolverType == MULTIFRONTAL_CHOLESKY)
|| (linearSolverType == MULTIFRONTAL_QR);
}
inline bool isSequential() const {
return (linearSolverType == SEQUENTIAL_CHOLESKY)
|| (linearSolverType == SEQUENTIAL_QR);
}
inline bool isCholmod() const {
return (linearSolverType == CHOLMOD);
}
inline bool isIterative() const {
return (linearSolverType == Iterative);
}
GaussianFactorGraph::Eliminate getEliminationFunction() const {
switch (linearSolverType) {
case MULTIFRONTAL_CHOLESKY:
case SEQUENTIAL_CHOLESKY:
return EliminatePreferCholesky;
case MULTIFRONTAL_QR:
case SEQUENTIAL_QR:
return EliminateQR;
default:
throw std::runtime_error(
"Nonlinear optimization parameter \"factorization\" is invalid");
}
}
std::string getLinearSolverType() const {
return linearSolverTranslator(linearSolverType);
}
void setLinearSolverType(const std::string& solver) {
linearSolverType = linearSolverTranslator(solver);
}
void setIterativeParams(const boost::shared_ptr<IterativeOptimizationParameters> params);
void setOrdering(const Ordering& ordering) {
this->ordering = ordering;
this->orderingType = Ordering::CUSTOM;
}
std::string getOrderingType() const {
return orderingTypeTranslator(orderingType);
}
// Note that if you want to use a custom ordering, you must set the ordering directly, this will switch to custom type
void setOrderingType(const std::string& ordering){
orderingType = orderingTypeTranslator(ordering);
}
private:
std::string linearSolverTranslator(LinearSolverType linearSolverType) const;
LinearSolverType linearSolverTranslator(const std::string& linearSolverType) const;
std::string orderingTypeTranslator(Ordering::OrderingType type) const;
Ordering::OrderingType orderingTypeTranslator(const std::string& type) const;
};
// For backward compatibility:
typedef NonlinearOptimizerParams SuccessiveLinearizationParams;
} /* namespace gtsam */
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
SubgraphSolver.h
Subgraph Solver from IROS 2010.
gtsam::EliminatePreferCholesky
std::pair< boost::shared_ptr< GaussianConditional >, boost::shared_ptr< GaussianFactor > > EliminatePreferCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
Densely partially eliminate with Cholesky factorization.
Definition HessianFactor.cpp:548
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::EliminateQR
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Multiply all factors and eliminate the given keys from the resulting factor using a QR variant that h...
Definition JacobianFactor.cpp:789
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Ordering::OrderingType
OrderingType
Type of ordering to use.
Definition Ordering.h:41
gtsam::NonlinearOptimizerParams
The common parameters for Nonlinear optimizers.
Definition NonlinearOptimizerParams.h:34
gtsam::NonlinearOptimizerParams::absoluteErrorTol
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5).
Definition NonlinearOptimizerParams.h:43
gtsam::NonlinearOptimizerParams::iterationHook
IterationHook iterationHook
Optional user-provided iteration hook to be called after each optimization iteration (Default: none).
Definition NonlinearOptimizerParams.h:94
gtsam::NonlinearOptimizerParams::maxIterations
size_t maxIterations
The maximum iterations to stop iterating (default 100).
Definition NonlinearOptimizerParams.h:41
gtsam::NonlinearOptimizerParams::verbosity
Verbosity verbosity
The printing verbosity during optimization (default SILENT).
Definition NonlinearOptimizerParams.h:45
gtsam::NonlinearOptimizerParams::iterativeParams
IterativeOptimizationParameters::shared_ptr iterativeParams
The container for iterativeOptimization parameters. used in CG Solvers.
Definition NonlinearOptimizerParams.h:108
gtsam::NonlinearOptimizerParams::Verbosity
Verbosity
See NonlinearOptimizerParams::verbosity.
Definition NonlinearOptimizerParams.h:37
gtsam::NonlinearOptimizerParams::linearSolverType
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
Definition NonlinearOptimizerParams.h:106
gtsam::NonlinearOptimizerParams::LinearSolverType
LinearSolverType
See NonlinearOptimizerParams::linearSolverType.
Definition NonlinearOptimizerParams.h:97
gtsam::NonlinearOptimizerParams::relativeErrorTol
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5).
Definition NonlinearOptimizerParams.h:42
gtsam::NonlinearOptimizerParams::orderingType
Ordering::OrderingType orderingType
The method of ordering use during variable elimination (default COLAMD).
Definition NonlinearOptimizerParams.h:46
gtsam::NonlinearOptimizerParams::errorTol
double errorTol
The maximum total error to stop iterating (default 0.0).
Definition NonlinearOptimizerParams.h:44
gtsam::NonlinearOptimizerParams::IterationHook
std::function< void(size_t, double, double)> IterationHook
Type for an optional user-provided hook to be called after each internal optimizer iteration.
Definition NonlinearOptimizerParams.h:67
gtsam::NonlinearOptimizerParams::ordering
boost::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty).
Definition NonlinearOptimizerParams.h:107