26 namespace noiseModel {
32 namespace mEstimator {
35 const size_t n = error.rows();
37 for (
size_t i = 0;
i <
n; ++
i)
46 if (reweight_ == Block) {
47 const double w = sqrtWeight(error.norm());
50 error.array() *= weight(error).cwiseSqrt().array();
56 if ( reweight_ == Block ) {
57 const double w = sqrtWeight(error.norm());
64 const Vector W = sqrtWeight(error);
68 error = W.cwiseProduct(error);
74 if ( reweight_ == Block ) {
75 const double w = sqrtWeight(error.norm());
80 const Vector W = sqrtWeight(error);
82 error = W.cwiseProduct(error);
88 if ( reweight_ == Block ) {
89 const double w = sqrtWeight(error.norm());
95 const Vector W = sqrtWeight(error);
98 error = W.cwiseProduct(error);
104 if ( reweight_ == Block ) {
105 const double w = sqrtWeight(error.norm());
112 const Vector W = sqrtWeight(error);
116 error = W.cwiseProduct(error);
125 { cout <<
s <<
"null ()" << endl; }
136 throw runtime_error(
"mEstimator Fair takes only positive double in constructor.");
145 const double absError =
std::abs(distance);
146 const double normalizedError = absError /
c_;
147 const double c_2 =
c_ *
c_;
148 return c_2 * (normalizedError -
std::log1p(normalizedError));
152 { cout <<
s <<
"fair (" <<
c_ <<
")" << endl; }
156 if (p ==
nullptr)
return false;
169 throw runtime_error(
"mEstimator Huber takes only positive double in constructor.");
174 const double absError =
std::abs(distance);
175 return (absError <=
k_) ? (1.0) : (
k_ / absError);
179 const double absError =
std::abs(distance);
180 if (absError <=
k_) {
181 return distance*distance / 2;
183 return k_ * (absError - (
k_/2));
188 cout <<
s <<
"huber (" <<
k_ <<
")" << endl;
193 if (p ==
nullptr)
return false;
207 throw runtime_error(
"mEstimator Cauchy takes only positive double in constructor.");
221 cout <<
s <<
"cauchy (" <<
k_ <<
")" << endl;
226 if (p ==
nullptr)
return false;
240 throw runtime_error(
"mEstimator Tukey takes only positive double in constructor.");
246 const double one_minus_xc2 = 1.0 - distance*distance/
csquared_;
247 return one_minus_xc2 * one_minus_xc2;
253 double absError =
std::abs(distance);
254 if (absError <=
c_) {
255 const double one_minus_xc2 = 1.0 - distance*distance/
csquared_;
256 const double t = one_minus_xc2*one_minus_xc2*one_minus_xc2;
264 std::cout <<
s <<
": Tukey (" <<
c_ <<
")" << std::endl;
269 if (p ==
nullptr)
return false;
284 const double xc2 = (distance*distance)/
csquared_;
289 const double xc2 = (distance*distance)/
csquared_;
294 std::cout <<
s <<
": Welsch (" <<
c_ <<
")" << std::endl;
299 if (p ==
nullptr)
return false;
316 const double c4 = c2*
c2;
317 const double c2error = c2 + distance*distance;
318 return c4/(c2error*c2error);
323 const double error2 = distance*distance;
324 return 0.5 * (c2 * error2) / (c2 + error2);
328 std::cout <<
s <<
": Geman-McClure (" <<
c_ <<
")" << std::endl;
333 if (p ==
nullptr)
return false;
349 const double e2 = distance*distance;
352 const double w = 2.0*
c_/(
c_ + e2);
362 const double e2 = distance*distance;
363 const double e4 = e2*e2;
366 return (c2*e2 + c_*e4) / ((e2 +
c_)*(e2 + c_));
370 std::cout <<
s <<
": DCS (" <<
c_ <<
")" << std::endl;
375 if (p ==
nullptr)
return false;
388 :
Base(reweight), k_(k) {
390 throw runtime_error(
"mEstimator L2WithDeadZone takes only positive double in constructor.");
399 else if (distance >
k_)
return (-
k_+distance)/distance;
400 else return (
k_+distance)/distance;
404 const double abs_error =
std::abs(distance);
405 return (abs_error <
k_) ? 0.0 : 0.5*(
k_-abs_error)*(
k_-abs_error);
409 std::cout <<
s <<
": L2WithDeadZone (" <<
k_ <<
")" << std::endl;
414 if (p ==
nullptr)
return false;
void print(const Matrix &A, const string &s, ostream &stream)
boost::shared_ptr< Huber > shared_ptr
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
DCS(double c=1.0, const ReweightScheme reweight=Block)
Tukey(double c=4.6851, const ReweightScheme reweight=Block)
double loss(double distance) const override
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
bool equals(const Base &expected, double tol=1e-8) const override
void vector_scale_inplace(const Vector &v, Matrix &A, bool inf_mask)
void reweight(Vector &error) const
bool equals(const Base &expected, double tol=1e-8) const override
Tukey implements the "Tukey" robust error model (Zhang97ivc)
double weight(double distance) const override
const mpreal expm1(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
double weight(double distance) const override
L2WithDeadZone(double k=1.0, const ReweightScheme reweight=Block)
Huber implements the "Huber" robust error model (Zhang97ivc)
double loss(double distance) const override
double loss(double distance) const override
void print(const std::string &s) const override
bool equals(const Base &expected, double tol=1e-8) const override
boost::shared_ptr< L2WithDeadZone > shared_ptr
Fair implements the "Fair" robust error model (Zhang97ivc)
Welsch(double c=2.9846, const ReweightScheme reweight=Block)
Null class should behave as Gaussian.
double loss(double distance) const override
bool equals(const Base &expected, double tol=1e-8) const override
void print(const std::string &s) const override
bool equals(const Base &expected, double tol=1e-8) const override
double loss(double distance) const override
boost::shared_ptr< Null > shared_ptr
EIGEN_DEVICE_FUNC const Log1pReturnType log1p() const
boost::shared_ptr< GemanMcClure > shared_ptr
double loss(double distance) const override
double weight(double distance) const override
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
Fair(double c=1.3998, const ReweightScheme reweight=Block)
Cauchy(double k=0.1, const ReweightScheme reweight=Block)
boost::shared_ptr< Tukey > shared_ptr
double weight(double distance) const override
boost::shared_ptr< Base > shared_ptr
double weight(double distance) const override
boost::shared_ptr< Cauchy > shared_ptr
void print(const std::string &s) const override
bool equals(const Base &expected, double tol=1e-8) const override
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
void print(const std::string &s) const override
double weight(double distance) const override
void print(const std::string &s) const override
double loss(double distance) const override
static shared_ptr Create(double c, const ReweightScheme reweight=Block)
double weight(double distance) const override
boost::shared_ptr< DCS > shared_ptr
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
void print(const std::string &s) const override
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
void print(const std::string &s) const override
Huber(double k=1.345, const ReweightScheme reweight=Block)
bool equals(const Base &expected, double tol=1e-8) const override
boost::shared_ptr< Fair > shared_ptr
boost::shared_ptr< Welsch > shared_ptr
bool equals(const Base &expected, double tol=1e-8) const override
GemanMcClure(double c=1.0, const ReweightScheme reweight=Block)
double loss(double distance) const override
void print(const std::string &s) const override
static shared_ptr Create(double k, const ReweightScheme reweight=Block)
Welsch implements the "Welsch" robust error model (Zhang97ivc)
double weight(double distance) const override