Visual Servoing Platform  version 3.6.1 under development (2024-10-18)
vpUKSigmaDrawerMerwe.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Kalman filtering.
33  *
34 *****************************************************************************/
35 
41 #include <visp3/core/vpUKSigmaDrawerMerwe.h>
42 
43 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
44 BEGIN_VISP_NAMESPACE
45 vpUKSigmaDrawerMerwe::vpUKSigmaDrawerMerwe(const int &n, const double &alpha, const double &beta, const double &kappa,
46  const vpAddSubFunction &resFunc, const vpAddSubFunction &addFunc)
48  , m_alpha(alpha)
49  , m_beta(beta)
50  , m_kappa(kappa)
51  , m_resFunc(resFunc)
52  , m_addFunc(addFunc)
53 {
54  computeLambda();
55 }
56 
57 std::vector<vpColVector> vpUKSigmaDrawerMerwe::drawSigmaPoints(const vpColVector &mean, const vpMatrix &covariance)
58 {
59  const unsigned int nbSigmaPoints = 2 * m_n + 1;
60  std::vector<vpColVector> sigmaPoints(nbSigmaPoints);
61  sigmaPoints[0] = mean;
62  vpMatrix scaledCov = (static_cast<double>(m_n) + m_lambda) * covariance;
63  vpMatrix cholesky = scaledCov.cholesky();
64  for (unsigned int i = 0; i < m_n; ++i) {
65  sigmaPoints[i + 1] = m_addFunc(mean, cholesky.getRow(i).transpose());
66  sigmaPoints[i + m_n + 1] = m_resFunc(mean, cholesky.getRow(i).transpose());
67  }
68  return sigmaPoints;
69 }
70 
72 {
73  const unsigned int nbSigmaPoints = 2 * m_n + 1;
74  vpSigmaPointsWeights weights;
75  weights.m_wm.resize(nbSigmaPoints);
76  weights.m_wc.resize(nbSigmaPoints);
77 
78  weights.m_wm[0] = m_lambda / (static_cast<double>(m_n) + m_lambda);
79  weights.m_wc[0] = (m_lambda / (static_cast<double>(m_n) + m_lambda)) + 1.0 - m_alpha * m_alpha + m_beta;
80 
81  double cstWeight = 1. / (2. * (static_cast<double>(m_n) + m_lambda));
82  for (unsigned int i = 1; i < nbSigmaPoints; ++i) {
83  weights.m_wm[i] = cstWeight;
84  weights.m_wc[i] = cstWeight;
85  }
86  return weights;
87 }
88 END_VISP_NAMESPACE
89 #else
90 void vpUKSigmaDrawerMerwe_dummy()
91 {
92 
93 }
94 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
vpMatrix cholesky() const
Definition: vpMatrix.cpp:1652
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:590
vpColVector transpose() const
vpUKSigmaDrawerMerwe(const int &n, const double &alpha, const double &beta, const double &kappa, const vpAddSubFunction &resFunc=vpUnscentedKalman::simpleResidual, const vpAddSubFunction &addFunc=vpUnscentedKalman::simpleAdd)
Construct a new vpUKSigmaDrawerMerwe object.
vpAddSubFunction m_resFunc
virtual std::vector< vpColVector > drawSigmaPoints(const vpColVector &mean, const vpMatrix &covariance) override
Draw the sigma points according to the current mean and covariance of the state of the Unscented Kalm...
vpUnscentedKalman::vpAddSubFunction vpAddSubFunction
virtual vpSigmaPointsWeights computeWeights() override
Computed the weigths that correspond to the sigma poitns that have been drawn.
vpAddSubFunction m_addFunc
The weights corresponding to the sigma points drawing.