g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
robust_kernel_impl.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#include "
robust_kernel_impl.h
"
28
29
#include <cmath>
30
31
#include "
robust_kernel_factory.h
"
32
33
namespace
g2o
{
34
35
RobustKernelScaleDelta::RobustKernelScaleDelta
(
const
RobustKernelPtr
&
kernel
,
36
double
delta
)
37
:
RobustKernel
(
delta
),
_kernel
(
kernel
) {}
38
39
RobustKernelScaleDelta::RobustKernelScaleDelta
(
double
delta
)
40
:
RobustKernel
(
delta
) {}
41
42
void
RobustKernelScaleDelta::setKernel
(
const
RobustKernelPtr
& ptr) {
43
_kernel
= ptr;
44
}
45
46
void
RobustKernelScaleDelta::robustify
(
double
error,
Vector3
& rho)
const
{
47
if
(
_kernel
.get()) {
48
double
dsqr =
_delta
*
_delta
;
49
double
dsqrReci = 1. / dsqr;
50
_kernel
->robustify(dsqrReci * error, rho);
51
rho[0] *= dsqr;
52
rho[2] *= dsqrReci;
53
}
else
{
// no robustification
54
rho[0] = error;
55
rho[1] = 1.;
56
rho[2] = 0.;
57
}
58
}
59
60
void
RobustKernelHuber::robustify
(
double
e,
Vector3
& rho)
const
{
61
double
dsqr =
_delta
*
_delta
;
62
if
(e <= dsqr) {
// inlier
63
rho[0] = e;
64
rho[1] = 1.;
65
rho[2] = 0.;
66
}
else
{
// outlier
67
double
sqrte = sqrt(e);
// absolute value of the error
68
rho[0] =
69
2 * sqrte *
_delta
- dsqr;
// rho(e) = 2 * delta * e^(1/2) - delta^2
70
rho[1] =
_delta
/ sqrte;
// rho'(e) = delta / sqrt(e)
71
rho[2] = -0.5 * rho[1] /
72
e;
// rho''(e) = -1 / (2*e^(3/2)) = -1/2 * (delta/e) / e
73
}
74
}
75
76
void
RobustKernelPseudoHuber::robustify
(
double
e2,
Vector3
& rho)
const
{
77
double
dsqr =
_delta
*
_delta
;
78
double
dsqrReci = 1. / dsqr;
79
double
aux1 = dsqrReci * e2 + 1.0;
80
double
aux2 = sqrt(aux1);
81
rho[0] = 2 * dsqr * (aux2 - 1);
82
rho[1] = 1. / aux2;
83
rho[2] = -0.5 * dsqrReci * rho[1] / aux1;
84
}
85
86
void
RobustKernelCauchy::robustify
(
double
e2,
Vector3
& rho)
const
{
87
double
dsqr =
_delta
*
_delta
;
88
double
dsqrReci = 1. / dsqr;
89
double
aux = dsqrReci * e2 + 1.0;
90
rho[0] = dsqr * log(aux);
91
rho[1] = 1. / aux;
92
rho[2] = -dsqrReci * std::pow(rho[1], 2);
93
}
94
95
void
RobustKernelGemanMcClure::robustify
(
double
e2,
Vector3
& rho)
const
{
96
const
double
aux = 1. / (
_delta
+ e2);
97
rho[0] =
_delta
* e2 * aux;
98
rho[1] =
_delta
*
_delta
* aux * aux;
99
rho[2] = -2. * rho[1] * aux;
100
}
101
102
void
RobustKernelWelsch::robustify
(
double
e2,
Vector3
& rho)
const
{
103
const
double
dsqr =
_delta
*
_delta
;
104
const
double
aux = e2 / dsqr;
105
const
double
aux2 = exp(-aux);
106
rho[0] = dsqr * (1. - aux2);
107
rho[1] = aux2;
108
rho[2] = -aux2 / dsqr;
109
}
110
111
void
RobustKernelFair::robustify
(
double
e2,
Vector3
& rho)
const
{
112
const
double
sqrte = sqrt(e2);
113
const
double
dsqr =
_delta
*
_delta
;
114
const
double
aux = sqrte /
_delta
;
115
rho[0] = 2. * dsqr * (aux - log1p(aux));
116
rho[1] = 1. / (1. + aux);
117
118
const
double
drec = 1. /
_delta
;
119
const
double
e_3_2 = 1. / (sqrte * e2);
120
const
double
aux2 = drec * sqrte + 1;
121
122
rho[2] = 2 * dsqr *
123
(1 / (4 * dsqr * aux2 * aux2 * e2) + (drec * e_3_2) / (4 * aux2) -
124
(drec * e_3_2) / 4);
125
}
126
127
void
RobustKernelTukey::robustify
(
double
e2,
Vector3
& rho)
const
{
128
const
double
delta2 =
_delta
*
_delta
;
129
if
(e2 <= delta2) {
130
const
double
aux = e2 / delta2;
131
rho[0] = delta2 * (1. - std::pow((1. - aux), 3)) / 3.;
132
rho[1] = std::pow((1. - aux), 2);
133
rho[2] = -2. * (1. - aux) / delta2;
134
}
else
{
135
rho[0] = delta2 / 3.;
136
rho[1] = 0;
137
rho[2] = 0;
138
}
139
}
140
141
void
RobustKernelSaturated::robustify
(
double
e2,
Vector3
& rho)
const
{
142
double
dsqr =
_delta
*
_delta
;
143
if
(e2 <= dsqr) {
// inlier
144
rho[0] = e2;
145
rho[1] = 1.;
146
rho[2] = 0.;
147
}
else
{
// outlier
148
rho[0] = dsqr;
149
rho[1] = 0.;
150
rho[2] = 0.;
151
}
152
}
153
154
// delta is used as $phi$
155
void
RobustKernelDCS::robustify
(
double
e2,
Vector3
& rho)
const
{
156
const
double
& phi =
_delta
;
157
double
scale = (2.0 * phi) / (phi + e2);
158
if
(scale >= 1.0) {
// limit scale to max of 1 and return this
159
rho[0] = e2;
160
rho[1] = 1.;
161
rho[2] = 0;
162
}
else
{
163
double
phi_sqr = phi * phi;
164
rho[0] = scale * e2 * scale;
165
rho[1] = (4 * phi_sqr * (phi - e2)) / std::pow(phi + e2, 3);
166
rho[2] = -(8 * phi_sqr * (2 * phi - e2)) / std::pow(phi + e2, 4);
167
}
168
}
169
170
// register the kernel to their factory
171
G2O_REGISTER_ROBUST_KERNEL
(Huber,
RobustKernelHuber
)
172
G2O_REGISTER_ROBUST_KERNEL
(PseudoHuber,
RobustKernelPseudoHuber
)
173
G2O_REGISTER_ROBUST_KERNEL
(Cauchy,
RobustKernelCauchy
)
174
G2O_REGISTER_ROBUST_KERNEL
(GemanMcClure,
RobustKernelGemanMcClure
)
175
G2O_REGISTER_ROBUST_KERNEL
(Welsch,
RobustKernelWelsch
)
176
G2O_REGISTER_ROBUST_KERNEL
(Fair,
RobustKernelFair
)
177
G2O_REGISTER_ROBUST_KERNEL
(Tukey,
RobustKernelTukey
)
178
G2O_REGISTER_ROBUST_KERNEL
(Saturated,
RobustKernelSaturated
)
179
G2O_REGISTER_ROBUST_KERNEL
(DCS,
RobustKernelDCS
)
180
}
// end namespace g2o
g2o::RobustKernelCauchy
Cauchy cost function.
Definition
robust_kernel_impl.h:106
g2o::RobustKernelCauchy::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:86
g2o::RobustKernelDCS
Dynamic covariance scaling - DCS.
Definition
robust_kernel_impl.h:190
g2o::RobustKernelDCS::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:155
g2o::RobustKernelFair
Fair cost function.
Definition
robust_kernel_impl.h:150
g2o::RobustKernelFair::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:111
g2o::RobustKernelGemanMcClure
Geman-McClure cost function.
Definition
robust_kernel_impl.h:122
g2o::RobustKernelGemanMcClure::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:95
g2o::RobustKernelHuber
Huber Cost Function.
Definition
robust_kernel_impl.h:77
g2o::RobustKernelHuber::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:60
g2o::RobustKernelPseudoHuber
Pseudo Huber Cost Function.
Definition
robust_kernel_impl.h:93
g2o::RobustKernelPseudoHuber::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:76
g2o::RobustKernelSaturated
Saturated cost function.
Definition
robust_kernel_impl.h:178
g2o::RobustKernelSaturated::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:141
g2o::RobustKernelScaleDelta::kernel
const RobustKernelPtr kernel() const
return the underlying kernel
Definition
robust_kernel_impl.h:53
g2o::RobustKernelScaleDelta::setKernel
void setKernel(const RobustKernelPtr &ptr)
use another kernel for the underlying operation
Definition
robust_kernel_impl.cpp:42
g2o::RobustKernelScaleDelta::robustify
void robustify(double error, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:46
g2o::RobustKernelScaleDelta::_kernel
RobustKernelPtr _kernel
Definition
robust_kernel_impl.h:60
g2o::RobustKernelScaleDelta::RobustKernelScaleDelta
RobustKernelScaleDelta(const RobustKernelPtr &kernel, double delta=1.)
Definition
robust_kernel_impl.cpp:35
g2o::RobustKernelTukey
Tukey Cost Function.
Definition
robust_kernel_impl.h:168
g2o::RobustKernelTukey::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:127
g2o::RobustKernelWelsch
Welsch cost function.
Definition
robust_kernel_impl.h:136
g2o::RobustKernelWelsch::robustify
virtual void robustify(double e2, Vector3 &rho) const
Definition
robust_kernel_impl.cpp:102
g2o::RobustKernel::_delta
double _delta
Definition
robust_kernel.h:71
g2o::RobustKernel::RobustKernel
RobustKernel()
Definition
robust_kernel.cpp:31
g2o::RobustKernel::delta
double delta() const
Definition
robust_kernel.h:68
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector3
VectorN< 3 > Vector3
Definition
eigen_types.h:51
g2o::RobustKernelPtr
std::shared_ptr< RobustKernel > RobustKernelPtr
Definition
robust_kernel.h:73
robust_kernel_factory.h
G2O_REGISTER_ROBUST_KERNEL
#define G2O_REGISTER_ROBUST_KERNEL(name, classname)
Definition
robust_kernel_factory.h:139
robust_kernel_impl.h
Generated on
for g2o by
1.17.0