g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
stuff
unscented.h
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
#ifndef G2O_UNSCENTED_
28
#define G2O_UNSCENTED_
29
30
#include <Eigen/Cholesky>
31
#include <Eigen/Core>
32
#include <cassert>
33
34
namespace
g2o
{
35
36
template
<
class
SampleType>
37
struct
SigmaPoint
{
38
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
;
39
SigmaPoint
(
const
SampleType& sample,
double
wi,
double
wp)
40
:
_sample
(sample),
_wi
(wi),
_wp
(wp) {}
41
SigmaPoint
() :
_wi
(0),
_wp
(0) {}
42
SampleType
_sample
;
43
double
_wi
;
44
double
_wp
;
45
};
46
47
template
<
class
SampleType,
class
CovarianceType>
48
bool
sampleUnscented
(std::vector<
SigmaPoint<SampleType>
>& sigmaPoints,
49
const
SampleType& mean,
const
CovarianceType& covariance) {
50
const
int
dim = mean.size();
51
const
int
numPoints = 2 * dim + 1;
52
assert(covariance.rows() == covariance.cols() &&
53
covariance.cols() == mean.size() &&
"Dimension Mismatch"
);
54
const
double
alpha =
cst
(1e-3);
55
const
double
beta = 2;
56
const
double
lambda = alpha * alpha * dim;
57
const
double
wi =
cst
(1) / (2 * (dim + lambda));
58
59
sigmaPoints.resize(numPoints);
60
sigmaPoints[0] =
SigmaPoint<SampleType>
(
61
mean, lambda / (dim + lambda),
62
lambda / (dim + lambda) + (1. - alpha * alpha + beta));
63
Eigen::LLT<CovarianceType> cholDecomp;
64
cholDecomp.compute(covariance * (dim + lambda));
65
if
(cholDecomp.info() == Eigen::NumericalIssue)
return
false
;
66
const
CovarianceType& L = cholDecomp.matrixL();
67
int
k = 1;
68
for
(
int
i = 0; i < dim; i++) {
69
SampleType s(L.col(i));
70
sigmaPoints[k++] =
SigmaPoint<SampleType>
(mean + s, wi, wi);
71
sigmaPoints[k++] =
SigmaPoint<SampleType>
(mean - s, wi, wi);
72
}
73
return
true
;
74
}
75
76
template
<
class
SampleType,
class
CovarianceType>
77
void
reconstructGaussian
(
78
SampleType& mean, CovarianceType& covariance,
79
const
std::vector<
SigmaPoint<SampleType>
>& sigmaPoints) {
80
mean.fill(0);
81
covariance.fill(0);
82
for
(
size_t
i = 0; i < sigmaPoints.size(); i++) {
83
mean += sigmaPoints[i]._wi * sigmaPoints[i]._sample;
84
}
85
for
(
size_t
i = 0; i < sigmaPoints.size(); i++) {
86
SampleType delta = sigmaPoints[i]._sample - mean;
87
covariance += sigmaPoints[i]._wp * (delta * delta.transpose());
88
}
89
}
90
}
// namespace g2o
91
92
#endif
g2o
Definition
dl_wrapper.cpp:55
g2o::reconstructGaussian
void reconstructGaussian(SampleType &mean, CovarianceType &covariance, const std::vector< SigmaPoint< SampleType > > &sigmaPoints)
Definition
unscented.h:77
g2o::cst
constexpr double cst(long double v)
Definition
misc.h:60
g2o::sampleUnscented
bool sampleUnscented(std::vector< SigmaPoint< SampleType > > &sigmaPoints, const SampleType &mean, const CovarianceType &covariance)
Definition
unscented.h:48
g2o::SigmaPoint
Definition
unscented.h:37
g2o::SigmaPoint< VectorXd >::_wp
double _wp
Definition
unscented.h:44
g2o::SigmaPoint< VectorXd >::_sample
VectorXd _sample
Definition
unscented.h:42
g2o::SigmaPoint< VectorXd >::_wi
double _wi
Definition
unscented.h:43
g2o::SigmaPoint::SigmaPoint
SigmaPoint()
Definition
unscented.h:41
g2o::SigmaPoint< VectorXd >::EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition
unscented.h:38
g2o::SigmaPoint::SigmaPoint
SigmaPoint(const SampleType &sample, double wi, double wp)
Definition
unscented.h:39
Generated on
for g2o by
1.17.0