Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gnc #617

Merged
merged 45 commits into from
Jan 4, 2021
Merged

Gnc #617

Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7e29944
Initial design
dellaert Nov 25, 2020
b5d06b5
starting to create test and code for gncParams
Nov 26, 2020
ff40590
added equals in NonlinearOptimizerParams
Nov 27, 2020
90dd2c7
params parsed correctly
Nov 27, 2020
f897fa8
added gnc loop
Nov 27, 2020
a33c50f
now we have very cool tests!
Nov 27, 2020
5222599
2 tests to go
Nov 27, 2020
7c22c2c
simplified small test to make it more understandable
Nov 27, 2020
0f07251
1 test to go
Nov 27, 2020
e991880
stuck on conversion of noise model
Nov 27, 2020
5db6894
finally I have a way to properly change the noise model!
Nov 27, 2020
7ce0641
working on make graph
Nov 27, 2020
556fa83
new constructor test which gets rid of robust loss now passes!
Nov 28, 2020
9e3263f
yay! only the final monster to go!
Nov 28, 2020
dab0090
added verbosity
Nov 28, 2020
ef47741
ladies and gents... GNC!
Nov 28, 2020
c4644a0
added functionality to fix weights
Nov 28, 2020
7699f04
correct formatting
Nov 28, 2020
786d4bb
done - PGO works like a charm!
Nov 28, 2020
fcf2d31
moved class to .h
Dec 5, 2020
db1a366
added comments
Dec 5, 2020
af069ab
fix comment
jingnanshi Dec 6, 2020
47775a7
TLS wip
jingnanshi Dec 7, 2020
9903fb9
tls done except unit tests
jingnanshi Dec 7, 2020
d85d9c6
minor fix
jingnanshi Dec 7, 2020
58e49fc
fix scoping
jingnanshi Dec 7, 2020
d0a81f8
mu initialization test & minor formatting fixes
jingnanshi Dec 7, 2020
9caa0d1
mu update test
jingnanshi Dec 7, 2020
428d17a
correctly check relative difference between mu valus at consecutive i…
jingnanshi Dec 7, 2020
594f63d
test fix
jingnanshi Dec 7, 2020
398c013
more unit tests
jingnanshi Dec 8, 2020
75bd3dc
templating on params is still problematic
Dec 22, 2020
7efd5cc
finally fixed the typedef
Dec 22, 2020
0e09f01
fixed templating, added a strict unit test on inlier threshold
Dec 22, 2020
cd82a56
made function name less ambiguous, added more comments on inlierThres…
Dec 22, 2020
046db87
Fix TLS convergence check
jingnanshi Dec 22, 2020
be5d3d2
update function name
jingnanshi Dec 23, 2020
c571744
fix test
jingnanshi Dec 23, 2020
dc5c769
- fixed stopping conditions
Dec 24, 2020
92ed225
minor fixes
jingnanshi Dec 24, 2020
06dfeb7
moved GncParams to separate file, addressing comments by Frank, 1/n
Dec 29, 2020
eea5276
renamed enum
Dec 29, 2020
dfdd206
addressed all except 2 comments by Frank. waiting for inputs on the 2…
Dec 29, 2020
2467238
moved gncLossType outside params
Dec 30, 2020
248eec8
addressed final comments by Frank
Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gtsam/nonlinear/GaussNewtonOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class GaussNewtonOptimizer;
* NonlinearOptimizationParams.
*/
class GTSAM_EXPORT GaussNewtonParams : public NonlinearOptimizerParams {
public:
typedef GaussNewtonOptimizer OptimizerType;
lucacarlone marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
459 changes: 459 additions & 0 deletions gtsam/nonlinear/GncOptimizer.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions gtsam/nonlinear/LevenbergMarquardtParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace gtsam {

class LevenbergMarquardtOptimizer;

/** Parameters for Levenberg-Marquardt optimization. Note that this parameters
* class inherits from NonlinearOptimizerParams, which specifies the parameters
* common to all nonlinear optimization algorithms. This class also contains
Expand All @@ -40,6 +42,7 @@ class GTSAM_EXPORT LevenbergMarquardtParams: public NonlinearOptimizerParams {

static VerbosityLM verbosityLMTranslator(const std::string &s);
static std::string verbosityLMTranslator(VerbosityLM value);
typedef LevenbergMarquardtOptimizer OptimizerType;
lucacarlone marked this conversation as resolved.
Show resolved Hide resolved

public:

Expand Down
8 changes: 8 additions & 0 deletions gtsam/nonlinear/NonlinearFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ bool NoiseModelFactor::equals(const NonlinearFactor& f, double tol) const {
&& noiseModel_->equals(*e->noiseModel_, tol)));
}

/* ************************************************************************* */
NoiseModelFactor::shared_ptr NoiseModelFactor::cloneWithNewNoiseModel(
const SharedNoiseModel newNoise) const {
NoiseModelFactor::shared_ptr new_factor = boost::dynamic_pointer_cast<NoiseModelFactor>(clone());
new_factor->noiseModel_ = newNoise;
return new_factor;
}

/* ************************************************************************* */
static void check(const SharedNoiseModel& noiseModel, size_t m) {
if (noiseModel && m != noiseModel->dim())
Expand Down
6 changes: 6 additions & 0 deletions gtsam/nonlinear/NonlinearFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor {
*/
boost::shared_ptr<GaussianFactor> linearize(const Values& x) const override;

/**
* Creates a shared_ptr clone of the
* factor with a new noise model
*/
shared_ptr cloneWithNewNoiseModel(const SharedNoiseModel newNoise) const;

private:
/** Serialization function */
friend class boost::serialization::access;
Expand Down
11 changes: 11 additions & 0 deletions gtsam/nonlinear/NonlinearOptimizerParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ class GTSAM_EXPORT 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);
Expand Down
63 changes: 63 additions & 0 deletions tests/smallExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,25 @@ struct UnaryFactor: public gtsam::NoiseModelFactor1<Point2> {
return (h(x) - z_);
}

gtsam::NonlinearFactor::shared_ptr clone() const override {
return boost::static_pointer_cast<gtsam::NonlinearFactor>(
gtsam::NonlinearFactor::shared_ptr(new UnaryFactor(*this))); }
};

}

/* ************************************************************************* */
inline NonlinearFactorGraph nonlinearFactorGraphWithGivenSigma(const double sigma) {
using symbol_shorthand::X;
using symbol_shorthand::L;
boost::shared_ptr<NonlinearFactorGraph> fg(new NonlinearFactorGraph);
Point2 z(1.0, 0.0);
boost::shared_ptr<smallOptimize::UnaryFactor> factor(
new smallOptimize::UnaryFactor(z, noiseModel::Isotropic::Sigma(2,sigma), X(1)));
fg->push_back(factor);
return *fg;
}

/* ************************************************************************* */
inline boost::shared_ptr<const NonlinearFactorGraph> sharedReallyNonlinearFactorGraph() {
using symbol_shorthand::X;
Expand All @@ -363,6 +378,54 @@ inline NonlinearFactorGraph createReallyNonlinearFactorGraph() {
return *sharedReallyNonlinearFactorGraph();
}

/* ************************************************************************* */
inline NonlinearFactorGraph sharedNonRobustFactorGraphWithOutliers() {
using symbol_shorthand::X;
boost::shared_ptr<NonlinearFactorGraph> fg(new NonlinearFactorGraph);
Point2 z(0.0, 0.0);
double sigma = 0.1;

boost::shared_ptr<PriorFactor<Point2>> factor(
new PriorFactor<Point2>(X(1), z, noiseModel::Isotropic::Sigma(2,sigma)));
// 3 noiseless inliers
fg->push_back(factor);
fg->push_back(factor);
fg->push_back(factor);

// 1 outlier
Point2 z_out(1.0, 0.0);
boost::shared_ptr<PriorFactor<Point2>> factor_out(
new PriorFactor<Point2>(X(1), z_out, noiseModel::Isotropic::Sigma(2,sigma)));
fg->push_back(factor_out);

return *fg;
}

/* ************************************************************************* */
inline NonlinearFactorGraph sharedRobustFactorGraphWithOutliers() {
using symbol_shorthand::X;
boost::shared_ptr<NonlinearFactorGraph> fg(new NonlinearFactorGraph);
Point2 z(0.0, 0.0);
double sigma = 0.1;
auto gmNoise = noiseModel::Robust::Create(
noiseModel::mEstimator::GemanMcClure::Create(1.0), noiseModel::Isotropic::Sigma(2,sigma));
boost::shared_ptr<PriorFactor<Point2>> factor(
new PriorFactor<Point2>(X(1), z, gmNoise));
// 3 noiseless inliers
fg->push_back(factor);
fg->push_back(factor);
fg->push_back(factor);

// 1 outlier
Point2 z_out(1.0, 0.0);
boost::shared_ptr<PriorFactor<Point2>> factor_out(
new PriorFactor<Point2>(X(1), z_out, gmNoise));
fg->push_back(factor_out);

return *fg;
}


/* ************************************************************************* */
inline std::pair<NonlinearFactorGraph, Values> createNonlinearSmoother(int T) {
using namespace impl;
Expand Down
Loading