25 #ifndef INCLUDED_SigmaPointGenerator_h_GUID_1277DE61_21A1_42BD_0401_78E74169E598
26 #define INCLUDED_SigmaPointGenerator_h_GUID_1277DE61_21A1_42BD_0401_78E74169E598
32 #include <Eigen/Cholesky>
39 inline double computeNu(std::size_t L,
double alpha) {
40 auto lambda = (L * (alpha * alpha - 1));
41 auto nu = std::sqrt(L + lambda);
89 template <std::
size_t Dim, std::
size_t OrigDim = Dim>
92 static_assert(OrigDim <= Dim,
"Original, non-augmented dimension must "
93 "be equal or less than the full "
95 static const std::size_t L = Dim;
96 static const std::size_t OriginalDimension = OrigDim;
97 static const std::size_t NumSigmaPoints = L * 2 + 1;
105 : p_(params, L), mean_(mean), covariance_(cov) {
106 weights_ = SigmaPointWeightVec::Constant(p_.weight);
107 weightsForCov_ = weights_;
108 weights_[0] = p_.weightMean0;
109 weightsForCov_[0] = p_.weightCov0;
110 scaledMatrixSqrt_ = cov.llt().matrixL();
112 sigmaPoints_ << mean,
113 (p_.gamma * scaledMatrixSqrt_).colwise() + mean,
114 (-p_.gamma * scaledMatrixSqrt_).colwise() + mean;
117 SigmaPointsMat
const &getSigmaPoints()
const {
return sigmaPoints_; }
119 using SigmaPointBlock = Eigen::Block<SigmaPointsMat, OrigDim, 1>;
120 using ConstSigmaPointBlock =
121 Eigen::Block<const SigmaPointsMat, OrigDim, 1>;
123 ConstSigmaPointBlock getSigmaPoint(std::size_t i)
const {
124 return sigmaPoints_.template block<OrigDim, 1>(0, i);
127 SigmaPointWeightVec
const &getWeightsForMean()
const {
130 SigmaPointWeightVec
const &getWeightsForCov()
const {
131 return weightsForCov_;
134 MeanVec
const &getMean()
const {
return mean_; }
136 using ConstOrigMeanVec = Eigen::VectorBlock<const MeanVec, OrigDim>;
139 ConstOrigMeanVec getOrigMean()
const {
return mean_.template head<OrigDim>(); }
144 CovMatrix covariance_;
145 CovMatrix scaledMatrixSqrt_;
146 SigmaPointsMat sigmaPoints_;
147 SigmaPointWeightVec weights_;
148 SigmaPointWeightVec weightsForCov_;
151 template <std::
size_t Dim>
154 template <std::
size_t XformedDim,
typename SigmaPo
intsGenType>
157 static const std::size_t DIMENSION = XformedDim;
158 using SigmaPointsGen = SigmaPointsGenType;
159 static const std::size_t NumSigmaPoints =
160 SigmaPointsGen::NumSigmaPoints;
163 SigmaPointsGen::OriginalDimension;
164 using TransformedSigmaPointsMat =
172 SigmaPointsGen
const &sigmaPoints,
173 TransformedSigmaPointsMat
const &xformedPointsMat)
174 : xformedCov_(CovMat::Zero()), crossCov_(CrossCovMatrix::Zero()) {
177 xformedMean_ = MeanVec::Zero();
178 for (std::size_t i = 0; i < NumSigmaPoints; ++i) {
179 auto weight = sigmaPoints.getWeightsForMean()[i];
180 xformedMean_ += weight * xformedPointsMat.col(i);
184 xformedPointsMat.rowwise() * sigmaPoints.getWeightsForMean();
186 TransformedSigmaPointsMat zeroMeanPoints =
187 xformedPointsMat.colwise() - xformedMean_;
189 for (std::size_t i = 0; i < NumSigmaPoints; ++i) {
190 auto weight = sigmaPoints.getWeightsForCov()[i];
191 xformedCov_ += weight * zeroMeanPoints.col(i) *
192 zeroMeanPoints.col(i).transpose();
193 crossCov_ += weight * (sigmaPoints.getSigmaPoint(i) -
194 sigmaPoints.getOrigMean()) *
195 zeroMeanPoints.col(i).transpose();
199 MeanVec
const &getMean()
const {
return xformedMean_; }
200 CovMat
const &getCov()
const {
return xformedCov_; }
203 CrossCovMatrix
const &getCrossCov()
const {
return crossCov_; }
206 MeanVec xformedMean_;
208 CrossCovMatrix crossCov_;
213 #endif // INCLUDED_SigmaPointGenerator_h_GUID_1277DE61_21A1_42BD_0401_78E74169E598
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
Eigen::Matrix< Scalar, n, n > SquareMatrix
A square matrix, n x n.
double weightCov0
Element 0 of weight vector for computing covariance.
double weightMean0
Element 0 of weight vector for computing means.
double lambda
"Compound scaling factor"
double gamma
Scales the matrix square root in computing sigma points.
std::size_t DimensionType
Type for dimensions.
double weight
Other elements of weight vector.
ReconstructedDistributionFromSigmaPoints(SigmaPointsGen const &sigmaPoints, TransformedSigmaPointsMat const &xformedPointsMat)
Eigen::Matrix< Scalar, m, n > Matrix
A matrix with rows = m, cols = n.