Main MRPT website > C++ reference for MRPT 1.9.9
CPointPDFSOG.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-2018, 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 CPointPDFSOG_H
10 #define CPointPDFSOG_H
11 
12 #include <mrpt/poses/CPointPDF.h>
14 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/math/CMatrixD.h>
16 
17 namespace mrpt
18 {
19 namespace poses
20 {
21 /** Declares a class that represents a Probability Density function (PDF) of a
22  * 3D point \f$ p(\mathbf{x}) = [x ~ y ~ z ]^t \f$.
23  * This class implements that PDF as the following multi-modal Gaussian
24  * distribution:
25  *
26  * \f$ p(\mathbf{x}) = \sum\limits_{i=1}^N \omega^i \mathcal{N}( \mathbf{x} ;
27  * \bar{\mathbf{x}}^i, \mathbf{\Sigma}^i ) \f$
28  *
29  * Where the number of modes N is the size of CPointPDFSOG::m_modes
30  *
31  * See mrpt::poses::CPointPDF for more details.
32  *
33  * \sa CPointPDF, CPosePDF,
34  * \ingroup poses_pdf_grp
35  */
36 class CPointPDFSOG : public CPointPDF
37 {
39 
40  public:
41  /** The struct for each mode:
42  */
44  {
45  TGaussianMode() : val(), log_w(0) {}
47 
48  /** The log-weight
49  */
50  double log_w;
51  };
52 
53  using CListGaussianModes = std::deque<TGaussianMode>;
56 
57  protected:
58  /** Assures the symmetry of the covariance matrix (eventually certain
59  * operations in the math-coprocessor lead to non-symmetric matrixes!)
60  */
61  void assureSymmetry();
62 
63  /** The list of SOG modes */
65 
66  public:
67  /** Default constructor
68  * \param nModes The initial size of CPointPDFSOG::m_modes
69  */
70  CPointPDFSOG(size_t nModes = 1);
71 
72  /** Clear all the gaussian modes */
73  void clear();
74 
75  /** Access to individual beacons */
76  const TGaussianMode& operator[](size_t i) const
77  {
78  ASSERT_(i < m_modes.size());
79  return m_modes[i];
80  }
81  /** Access to individual beacons */
83  {
84  ASSERT_(i < m_modes.size());
85  return m_modes[i];
86  }
87 
88  /** Access to individual beacons */
89  const TGaussianMode& get(size_t i) const
90  {
91  ASSERT_(i < m_modes.size());
92  return m_modes[i];
93  }
94  /** Access to individual beacons */
95  TGaussianMode& get(size_t i)
96  {
97  ASSERT_(i < m_modes.size());
98  return m_modes[i];
99  }
100 
101  /** Inserts a copy of the given mode into the SOG */
102  void push_back(const TGaussianMode& m) { m_modes.push_back(m); }
103  iterator begin() { return m_modes.begin(); }
104  iterator end() { return m_modes.end(); }
105  const_iterator begin() const { return m_modes.begin(); }
106  const_iterator end() const { return m_modes.end(); }
107  iterator erase(iterator i) { return m_modes.erase(i); }
108  /** Resize the number of SOG modes */
109  void resize(const size_t N);
110  /** Return the number of Gaussian modes. */
111  size_t size() const { return m_modes.size(); }
112  /** Return whether there is any Gaussian mode. */
113  bool empty() const { return m_modes.empty(); }
114  /** Returns an estimate of the point, (the mean, or mathematical expectation
115  * of the PDF) \sa getCovariance */
116  void getMean(CPoint3D& mean_point) const override;
117 
118  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and
119  * the mean, both at once. \sa getMean */
121  mrpt::math::CMatrixDouble33& cov, CPoint3D& mean_point) const override;
122 
123  /** Normalize the weights in m_modes such as the maximum log-weight is 0 */
124  void normalizeWeights();
125 
126  /** Return the Gaussian mode with the highest likelihood (or an empty
127  * Gaussian if there are no modes in this SOG) */
128  void getMostLikelyMode(CPointPDFGaussian& outVal) const;
129 
130  /** Computes the "Effective sample size" (typical measure for Particle
131  * Filters), applied to the weights of the individual Gaussian modes, as a
132  * measure of the equality of the modes (in the range [0,total # of modes]).
133  */
134  double ESS() const;
135 
136  /** Copy operator, translating if necesary (for example, between particles
137  * and gaussian representations) */
138  void copyFrom(const CPointPDF& o) override;
139 
140  /** Save the density to a text file, with the following format:
141  * There is one row per Gaussian "mode", and each row contains 10
142  * elements:
143  * - w (The weight)
144  * - x_mean (gaussian mean value)
145  * - y_mean (gaussian mean value)
146  * - x_mean (gaussian mean value)
147  * - C11 (Covariance elements)
148  * - C22 (Covariance elements)
149  * - C33 (Covariance elements)
150  * - C12 (Covariance elements)
151  * - C13 (Covariance elements)
152  * - C23 (Covariance elements)
153  *
154  */
155  bool saveToTextFile(const std::string& file) const override;
156 
157  /** this = p (+) this. This can be used to convert a PDF from local
158  * coordinates to global, providing the point (newReferenceBase) from which
159  * "to project" the current pdf. Result PDF substituted the currently
160  * stored one in the object. */
161  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
162 
163  /** Draw a sample from the pdf. */
164  void drawSingleSample(CPoint3D& outSample) const override;
165 
166  /** Bayesian fusion of two point distributions (product of two
167  * distributions->new distribution), then save the result in this object
168  * (WARNING: See implementing classes to see classes that can and cannot be
169  * mixtured!)
170  * \param p1 The first distribution to fuse
171  * \param p2 The second distribution to fuse
172  * \param minMahalanobisDistToDrop If set to different of 0, the result of
173  * very separate Gaussian modes (that will result in negligible components)
174  * in SOGs will be dropped to reduce the number of modes in the output.
175  */
176  void bayesianFusion(
177  const CPointPDF& p1, const CPointPDF& p2,
178  const double minMahalanobisDistToDrop = 0) override;
179 
180  /** Evaluates the PDF within a rectangular grid and saves the result in a
181  * matrix (each row contains values for a fixed y-coordinate value).
182  */
183  void evaluatePDFInArea(
184  float x_min, float x_max, float y_min, float y_max, float resolutionXY,
185  float z, mrpt::math::CMatrixD& outMatrix, bool sumOverAllZs = false);
186 
187  /** Evaluates the PDF at a given point */
188  double evaluatePDF(const CPoint3D& x, bool sumOverAllZs) const;
189 
190 }; // End of class def.
191 } // End of namespace
192 } // End of namespace
193 #endif
mrpt::poses::CPointPDFSOG::assureSymmetry
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
Definition: CPointPDFSOG.cpp:402
mrpt::poses::CPointPDFSOG::end
const_iterator end() const
Definition: CPointPDFSOG.h:106
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::poses::CPointPDFSOG::operator[]
TGaussianMode & operator[](size_t i)
Access to individual beacons.
Definition: CPointPDFSOG.h:82
mrpt::poses::CPointPDFSOG::evaluatePDFInArea
void evaluatePDFInArea(float x_min, float x_max, float y_min, float y_max, float resolutionXY, float z, mrpt::math::CMatrixD &outMatrix, bool sumOverAllZs=false)
Evaluates the PDF within a rectangular grid and saves the result in a matrix (each row contains value...
Definition: CPointPDFSOG.cpp:465
mrpt::poses::CPointPDFSOG::changeCoordinatesReference
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
Definition: CPointPDFSOG.cpp:203
mrpt::poses::CPointPDFSOG::normalizeWeights
void normalizeWeights()
Normalize the weights in m_modes such as the maximum log-weight is 0.
Definition: CPointPDFSOG.cpp:421
mrpt::poses::CPointPDFSOG::getMean
void getMean(CPoint3D &mean_point) const override
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
Definition: CPointPDFSOG.cpp:49
mrpt::poses::CPointPDFSOG::evaluatePDF
double evaluatePDF(const CPoint3D &x, bool sumOverAllZs) const
Evaluates the PDF at a given point.
Definition: CPointPDFSOG.cpp:495
mrpt::poses::CPointPDFSOG::resize
void resize(const size_t N)
Resize the number of SOG modes.
Definition: CPointPDFSOG.cpp:43
mrpt::poses::CPointPDFSOG::clear
void clear()
Clear all the gaussian modes.
Definition: CPointPDFSOG.cpp:39
mrpt::poses::CPointPDFSOG::get
const TGaussianMode & get(size_t i) const
Access to individual beacons.
Definition: CPointPDFSOG.h:89
mrpt::poses::CPointPDFGaussian
A gaussian distribution for 3D points.
Definition: CPointPDFGaussian.h:25
mrpt::poses::CPointPDFSOG::TGaussianMode::val
CPointPDFGaussian val
Definition: CPointPDFSOG.h:46
CMatrix.h
mrpt::poses::CPointPDFSOG::saveToTextFile
bool saveToTextFile(const std::string &file) const override
Save the density to a text file, with the following format: There is one row per Gaussian "mode",...
Definition: CPointPDFSOG.cpp:184
mrpt::poses::CPointPDFSOG::empty
bool empty() const
Return whether there is any Gaussian mode.
Definition: CPointPDFSOG.h:113
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::poses::CPointPDFSOG::get
TGaussianMode & get(size_t i)
Access to individual beacons.
Definition: CPointPDFSOG.h:95
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::poses::CPointPDFSOG::end
iterator end()
Definition: CPointPDFSOG.h:104
mrpt::poses::CPointPDFSOG::ESS
double ESS() const
Computes the "Effective sample size" (typical measure for Particle Filters), applied to the weights o...
Definition: CPointPDFSOG.cpp:440
mrpt::math::cov
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:148
mrpt::poses::CPointPDFSOG::drawSingleSample
void drawSingleSample(CPoint3D &outSample) const override
Draw a sample from the pdf.
Definition: CPointPDFSOG.cpp:211
CPointPDFGaussian.h
mrpt::poses::CPointPDFSOG::TGaussianMode::log_w
double log_w
The log-weight.
Definition: CPointPDFSOG.h:50
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::poses::CPointPDFSOG::CPointPDFSOG
CPointPDFSOG(size_t nModes=1)
Default constructor.
Definition: CPointPDFSOG.cpp:35
CMatrixD.h
mrpt::poses::CPointPDFSOG::iterator
std::deque< TGaussianMode >::iterator iterator
Definition: CPointPDFSOG.h:55
mrpt::math::CMatrixFixedNumeric< double, 3, 3 >
mrpt::poses::CPointPDFSOG::CListGaussianModes
std::deque< TGaussianMode > CListGaussianModes
Definition: CPointPDFSOG.h:53
mrpt::poses::CPointPDFSOG::begin
iterator begin()
Definition: CPointPDFSOG.h:103
mrpt::poses::CPointPDFSOG::getMostLikelyMode
void getMostLikelyMode(CPointPDFGaussian &outVal) const
Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in t...
Definition: CPointPDFSOG.cpp:543
mrpt::poses::CPointPDFSOG::m_modes
CListGaussianModes m_modes
The list of SOG modes.
Definition: CPointPDFSOG.h:64
mrpt::poses::CPointPDFSOG::const_iterator
std::deque< TGaussianMode >::const_iterator const_iterator
Definition: CPointPDFSOG.h:54
mrpt::poses::CPointPDFSOG
Declares a class that represents a Probability Density function (PDF) of a 3D point .
Definition: CPointPDFSOG.h:36
mrpt::poses::CPointPDFSOG::operator[]
const TGaussianMode & operator[](size_t i) const
Access to individual beacons.
Definition: CPointPDFSOG.h:76
mrpt::poses::CPointPDFSOG::begin
const_iterator begin() const
Definition: CPointPDFSOG.h:105
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::poses::CPointPDFSOG::copyFrom
void copyFrom(const CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations)
Definition: CPointPDFSOG.cpp:160
mrpt::poses::CPointPDFSOG::erase
iterator erase(iterator i)
Definition: CPointPDFSOG.h:107
z
GLdouble GLdouble z
Definition: glext.h:3872
mrpt::poses::CPointPDFSOG::TGaussianMode::TGaussianMode
TGaussianMode()
Definition: CPointPDFSOG.h:45
mrpt::math::CMatrixD
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:24
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::poses::CPointPDFSOG::bayesianFusion
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two point distributions (product of two distributions->new distribution),...
Definition: CPointPDFSOG.cpp:252
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
CPointPDF.h
mrpt::poses::CPointPDF
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x,...
Definition: CPointPDF.h:39
mrpt::poses::CPoint3D
A class used to store a 3D point.
Definition: CPoint3D.h:33
mrpt::poses::CPointPDFSOG::TGaussianMode
The struct for each mode:
Definition: CPointPDFSOG.h:43
x
GLenum GLint x
Definition: glext.h:3538
mrpt::poses::CPointPDFSOG::size
size_t size() const
Return the number of Gaussian modes.
Definition: CPointPDFSOG.h:111
mrpt::poses::CPointPDFSOG::getCovarianceAndMean
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPoint3D &mean_point) const override
Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
Definition: CPointPDFSOG.cpp:83
mrpt::poses::CPointPDFSOG::push_back
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
Definition: CPointPDFSOG.h:102



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST