Main MRPT website > C++ reference for MRPT 1.4.0
CPosePDFSOG.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CPosePDFSOG_H
10 #define CPosePDFSOG_H
11 
12 #include <mrpt/poses/CPosePDF.h>
14 #include <mrpt/math/math_frwds.h>
15 
16 
17 namespace mrpt
18 {
19  namespace poses
20  {
21  // This must be added to any CSerializable derived class:
23 
24  /** Declares a class that represents a Probability Density function (PDF) of a 2D pose \f$ p(\mathbf{x}) = [x ~ y ~ \phi ]^t \f$.
25  * This class implements that PDF as the following multi-modal Gaussian distribution:
26  *
27  * \f$ p(\mathbf{x}) = \sum\limits_{i=1}^N \omega^i \mathcal{N}( \mathbf{x} ; \bar{\mathbf{x}}^i, \mathbf{\Sigma}^i ) \f$
28  *
29  * Where the number of modes N is the size of CPosePDFSOG::m_modes
30  *
31  * See mrpt::poses::CPosePDF for more details.
32  *
33  * \sa CPose2D, CPosePDF, CPosePDFParticles
34  * \ingroup poses_pdf_grp
35  */
37  {
38  // This must be added to any CSerializable derived class:
40 
41  public:
42  /** The struct for each mode:
43  */
45  {
47  mean(),
48  cov(),
49  log_w(0)
50  { }
51 
54 
55  /** The log-weight
56  */
57  double log_w;
58 
59  public:
61  };
62 
66 
67  protected:
68  void assureSymmetry(); //!< Ensures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
69 
70  CListGaussianModes m_modes; //!< The list of SOG modes
71 
72  public:
73  /** Default constructor
74  * \param nModes The initial size of CPosePDFSOG::m_modes */
75  CPosePDFSOG( size_t nModes = 1 );
76 
77  size_t size() const { return m_modes.size(); } //!< Return the number of Gaussian modes.
78  bool empty() const { return m_modes.empty(); } //!< Return whether there is any Gaussian mode.
79 
80 
81  void clear(); //!< Clear the list of modes
82 
83  /** Access to individual beacons */
84  const TGaussianMode& operator [](size_t i) const {
85  ASSERT_(i<m_modes.size())
86  return m_modes[i];
87  }
88  /** Access to individual beacons */
89  TGaussianMode& operator [](size_t i) {
90  ASSERT_(i<m_modes.size())
91  return m_modes[i];
92  }
93 
94  /** Access to individual beacons */
95  const TGaussianMode& get(size_t i) const {
96  ASSERT_(i<m_modes.size())
97  return m_modes[i];
98  }
99  /** Access to individual beacons */
100  TGaussianMode& get(size_t i) {
101  ASSERT_(i<m_modes.size())
102  return m_modes[i];
103  }
104 
105  /** Inserts a copy of the given mode into the SOG */
106  void push_back(const TGaussianMode& m) {
107  m_modes.push_back(m);
108  }
109 
110  iterator begin() { return m_modes.begin(); }
111  iterator end() { return m_modes.end(); }
112  const_iterator begin() const { return m_modes.begin(); }
113  const_iterator end()const { return m_modes.end(); }
114 
115  iterator erase(iterator i) { return m_modes.erase(i); }
116 
117  void resize(const size_t N); //!< Resize the number of SOG modes
118 
119  /** Merge very close modes so the overall number of modes is reduced while preserving the total distribution.
120  * This method uses the approach described in the paper:
121  * - "Kullback-Leibler Approach to Gaussian Mixture Reduction" AR Runnalls. IEEE Transactions on Aerospace and Electronic Systems, 2007.
122  *
123  * \param max_KLd The maximum KL-divergence to consider the merge of two nodes (and then stops the process).
124  */
125  void mergeModes( double max_KLd = 0.5, bool verbose = false );
126 
127  void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE; //!< Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF) \sa getCovariance
128  void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov,CPose2D &mean_point) const MRPT_OVERRIDE; //!< Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once. \sa getMean
129  void getMostLikelyCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov,CPose2D &mean_point) const; //!< For the most likely Gaussian mode in the SOG, returns the pose covariance matrix (3x3 cov matrix) and the mean. \sa getMean
130  void normalizeWeights(); //!< Normalize the weights in m_modes such as the maximum log-weight is 0
131 
132  void copyFrom(const CPosePDF &o) MRPT_OVERRIDE; //!< Copy operator, translating if necesary (for example, between particles and gaussian representations)
133 
134  /** Save the density to a text file, with the following format:
135  * There is one row per Gaussian "mode", and each row contains 10 elements:
136  * - w (The weight)
137  * - x_mean (gaussian mean value)
138  * - y_mean (gaussian mean value)
139  * - phi_mean (gaussian mean value)
140  * - C11 (Covariance elements)
141  * - C22 (Covariance elements)
142  * - C33 (Covariance elements)
143  * - C12 (Covariance elements)
144  * - C13 (Covariance elements)
145  * - C23 (Covariance elements)
146  */
147  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
148 
149  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
150  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. */
151  void changeCoordinatesReference(const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
152 
153  void rotateAllCovariances(const double &ang); //!< Rotate all the covariance matrixes by replacing them by \f$ \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[ \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$
154  void drawSingleSample( CPose2D &outPart ) const MRPT_OVERRIDE; //!< Draws a single sample from the distribution
155  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE; //!< Draws a number of samples from the distribution, and saves as a list of 1x3 vectors, where each row contains a (x,y,phi) datum.
156  void inverse(CPosePDF &o) const MRPT_OVERRIDE; //!< Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
157 
158  void operator += ( const mrpt::poses::CPose2D &Ap); //!< Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated).
159 
160  double evaluatePDF( const mrpt::poses::CPose2D &x, bool sumOverAllPhis = false ) const; //!< Evaluates the PDF at a given point.
161  double evaluateNormalizedPDF( const mrpt::poses::CPose2D &x ) const; //!< Evaluates the ratio PDF(x) / max_PDF(x*), that is, the normalized PDF in the range [0,1].
162 
163  /** Evaluates the PDF within a rectangular grid (and a fixed orientation) and saves the result in a matrix (each row contains values for a fixed y-coordinate value). */
165  const double & x_min,
166  const double & x_max,
167  const double & y_min,
168  const double & y_max,
169  const double & resolutionXY,
170  const double & phi,
171  mrpt::math::CMatrixD &outMatrix,
172  bool sumOverAllPhis = false );
173 
174  /** Bayesian fusion of two pose distributions, then save the result in this object (WARNING: Currently p1 must be a mrpt::poses::CPosePDFSOG object and p2 a mrpt::poses::CPosePDFGaussian object) */
175  void bayesianFusion(const CPosePDF &p1,const CPosePDF &p2, const double &minMahalanobisDistToDrop=0 ) MRPT_OVERRIDE;
176 
177  }; // End of class def.
179  } // End of namespace
180 } // End of namespace
181 #endif
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:31
A numeric matrix of compile-time fixed size.
A class used to store a 2D pose.
Definition: CPose2D.h:37
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition: CPosePDF.h:40
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
Definition: CPosePDFSOG.h:37
void rotateAllCovariances(const double &ang)
Rotate all the covariance matrixes by replacing them by , where .
void resize(const size_t N)
Resize the number of SOG modes.
double evaluateNormalizedPDF(const mrpt::poses::CPose2D &x) const
Evaluates the ratio PDF(x) / max_PDF(x*), that is, the normalized PDF in the range [0,...
const_iterator begin() const
Definition: CPosePDFSOG.h:112
iterator erase(iterator i)
Definition: CPosePDFSOG.h:115
mrpt::aligned_containers< TGaussianMode >::vector_t CListGaussianModes
Definition: CPosePDFSOG.h:63
const TGaussianMode & get(size_t i) const
Access to individual beacons.
Definition: CPosePDFSOG.h:95
void normalizeWeights()
Normalize the weights in m_modes such as the maximum log-weight is 0.
void drawSingleSample(CPose2D &outPart) const MRPT_OVERRIDE
Draws a single sample from the distribution.
void copyFrom(const CPosePDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations)
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPose2D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
void mergeModes(double max_KLd=0.5, bool verbose=false)
Merge very close modes so the overall number of modes is reduced while preserving the total distribut...
void evaluatePDFInArea(const double &x_min, const double &x_max, const double &y_min, const double &y_max, const double &resolutionXY, const double &phi, mrpt::math::CMatrixD &outMatrix, bool sumOverAllPhis=false)
Evaluates the PDF within a rectangular grid (and a fixed orientation) and saves the result in a matri...
CListGaussianModes::iterator iterator
Definition: CPosePDFSOG.h:65
bool empty() const
Return whether there is any Gaussian mode.
Definition: CPosePDFSOG.h:78
TGaussianMode & get(size_t i)
Access to individual beacons.
Definition: CPosePDFSOG.h:100
const_iterator end() const
Definition: CPosePDFSOG.h:113
void clear()
Clear the list of modes.
void saveToTextFile(const std::string &file) const MRPT_OVERRIDE
Save the density to a text file, with the following format: There is one row per Gaussian "mode",...
void getMostLikelyCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPose2D &mean_point) const
For the most likely Gaussian mode in the SOG, returns the pose covariance matrix (3x3 cov matrix) and...
CListGaussianModes::const_iterator const_iterator
Definition: CPosePDFSOG.h:64
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double &minMahalanobisDistToDrop=0) MRPT_OVERRIDE
Bayesian fusion of two pose distributions, then save the result in this object (WARNING: Currently p1...
size_t size() const
Return the number of Gaussian modes.
Definition: CPosePDFSOG.h:77
void assureSymmetry()
Ensures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
double evaluatePDF(const mrpt::poses::CPose2D &x, bool sumOverAllPhis=false) const
Evaluates the PDF at a given point.
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
Definition: CPosePDFSOG.h:106
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const MRPT_OVERRIDE
Draws a number of samples from the distribution, and saves as a list of 1x3 vectors,...
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.
void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF)
CListGaussianModes m_modes
The list of SOG modes.
Definition: CPosePDFSOG.h:70
CPosePDFSOG(size_t nModes=1)
Default constructor.
void inverse(CPosePDF &o) const MRPT_OVERRIDE
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
Scalar * iterator
Definition: eigen_plugins.h:23
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
Definition: memory.h:112
#define ASSERT_(f)
Definition: mrpt_macros.h:261
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample,...
Definition: ops_matrices.h:135
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
The struct for each mode:
Definition: CPosePDFSOG.h:45
mrpt::math::CMatrixDouble33 cov
Definition: CPosePDFSOG.h:53



Page generated by Doxygen 1.9.1 for MRPT 1.4.0 SVN: at Fri Sep 3 01:11:30 UTC 2021