21#include <gtsam/sam/RISAMGraduationScheduler.h>
32 typedef std::shared_ptr<GraduatedFactor> shared_ptr;
45 std::shared_ptr<double>
mu_;
68 mu_ = std::make_shared<double>(*(other.
mu_));
77 const Values& currentEstimate)
const = 0;
100template <
class FACTOR_TYPE>
102 static_assert(std::is_base_of<NonlinearFactor, FACTOR_TYPE>::value,
103 "GraduatedFactor Must be instantiated with a Factor Derived "
104 "from NonlinearFactor.");
109 typedef std::shared_ptr<GenericGraduatedFactor<FACTOR_TYPE>> shared_ptr;
120 template <
class... Args>
124 : FACTOR_TYPE(
std::forward<Args>(args)...),
134 NonlinearFactor::shared_ptr
clone()
const override {
135 return std::static_pointer_cast<NonlinearFactor>(
136 NonlinearFactor::shared_ptr(
142 const Values& currentEstimate)
const override {
146 auto whitenedLinearSystem = FACTOR_TYPE::linearize(currentEstimate);
147 auto [A, b] = whitenedLinearSystem->jacobian();
148 const size_t outputDim = b.size();
151 auto keys = whitenedLinearSystem->keys();
152 std::vector<Matrix> Ablocks;
153 size_t indexStart = 0;
154 for (
const auto& key : keys) {
155 size_t d = currentEstimate.
at(key).dim();
156 Ablocks.push_back(A.block(0, indexStart, outputDim, d));
161 const double sqrtWeight =
163 for (Matrix& Aj : Ablocks) {
170 for (
size_t i = 0; i < Ablocks.size(); i++) {
171 AblockMap[keys[i]] = Ablocks[i];
173 return std::make_shared<JacobianFactor>(AblockMap, b);
178 const Values& currentEstimate)
const override {
194 return std::sqrt(2.0 * FACTOR_TYPE::error(currentEstimate));
204 return FACTOR_TYPE::clone();
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactor.h:42
Pure virtual class for all robust error function classes.
Definition LossFunctions.h:81
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition Values-inl.h:260
Graduated Factor for riSAM base class.
Definition RISAMGraduatedFactor.h:28
GraduatedFactor(RobustLoss::shared_ptr loss, GraduationScheduler::shared_ptr scheduler)
Constructor.
Definition RISAMGraduatedFactor.h:59
GraduationScheduler::shared_ptr scheduler_
The control param ($\mu$) scheduler for this factor.
Definition RISAMGraduatedFactor.h:42
const RobustLoss::shared_ptr & loss() const
Returns the robust loss for this graduated factor.
Definition RISAMGraduatedFactor.h:86
const GraduationScheduler::shared_ptr & scheduler() const
Returns the graduation scheduler for this factor.
Definition RISAMGraduatedFactor.h:89
friend class RISAM
Befriend RISAM to give access to these protected values.
Definition RISAMGraduatedFactor.h:49
std::shared_ptr< double > mu_
The unique mu control parameter for this factor.
Definition RISAMGraduatedFactor.h:45
virtual double robustLoss(const Values ¤tEstimate) const =0
returns the graduated robust loss \rho_\mu(r) of the factor
RobustLoss::shared_ptr robustLoss_
The robust loss for this factor.
Definition RISAMGraduatedFactor.h:40
GraduatedFactor(const GraduatedFactor &other)
Copy constructor.
Definition RISAMGraduatedFactor.h:66
virtual GaussianFactor::shared_ptr linearizeGraduated(const Values ¤tEstimate) const =0
Linearize this factor using the convexification parameter mu.
virtual double residual(const Values ¤tEstimate) const =0
returns the residual of the factor
virtual NonlinearFactor::shared_ptr cloneUngraduated() const =0
Copies this factor as an instance of its base type without the graduated robust loss or scheduler.
double residual(const Values ¤tEstimate) const override
returns the residual of the factor
Definition RISAMGraduatedFactor.h:193
GenericGraduatedFactor(const GenericGraduatedFactor< FACTOR_TYPE > &other)
Copy Constructor Delegates to GraduatedFactor's copy constructor so the copy preserves the current gr...
Definition RISAMGraduatedFactor.h:130
GenericGraduatedFactor(RobustLoss::shared_ptr loss, GraduationScheduler::shared_ptr scheduler, Args &&... args)
Constructor.
Definition RISAMGraduatedFactor.h:121
NonlinearFactor::shared_ptr cloneUngraduated() const override
See GraduatedFactor::cloneUngraduated.
Definition RISAMGraduatedFactor.h:203
NonlinearFactor::shared_ptr clone() const override
Makes a deep copy of the factor.
Definition RISAMGraduatedFactor.h:134
GaussianFactor::shared_ptr linearize(const Values ¤tEstimate) const override
Linearize the System.
Definition RISAMGraduatedFactor.h:177
double robustLoss(const Values ¤tEstimate) const override
See GraduatedFactor::robustLoss.
Definition RISAMGraduatedFactor.h:198
GaussianFactor::shared_ptr linearizeGraduated(const Values ¤tEstimate) const override
Linearizes the factor using the current value of mu.
Definition RISAMGraduatedFactor.h:141
double error(const Values &values) const override
Returns the graduated robust loss \rho_\mu(r).
Definition RISAMGraduatedFactor.h:185
std::shared_ptr< GraduationScheduler > shared_ptr
Shortcut for shared pointer.
Definition RISAMGraduationScheduler.h:47