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 |
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
76  const TGaussianMode& operator[](size_t i) const
77  {
78  ASSERT_(i < m_modes.size());
79  return m_modes[i];
80  }
83  {
84  ASSERT_(i < m_modes.size());
85  return m_modes[i];
86  }
87
89  const TGaussianMode& get(size_t i) const
90  {
91  ASSERT_(i < m_modes.size());
92  return m_modes[i];
93  }
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
Scalar * iterator
Definition: eigen_plugins.h:26
GLdouble GLdouble z
Definition: glext.h:3872
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:24
void getMean(CPoint3D &mean_point) const override
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) ...
void resize(const size_t N)
Resize the number of SOG modes.
Declares a class that represents a Probability Density function (PDF) of a 3D point ...
Definition: CPointPDFSOG.h:36
The struct for each mode:
Definition: CPointPDFSOG.h:43
const TGaussianMode & operator[](size_t i) const
Definition: CPointPDFSOG.h:76
void clear()
Clear all the gaussian modes.
void drawSingleSample(CPoint3D &outSample) const override
Draw a sample from the pdf.
bool empty() const
Return whether there is any Gaussian mode.
Definition: CPointPDFSOG.h:113
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
Definition: CPointPDFSOG.h:102
TGaussianMode & operator[](size_t i)
Definition: CPointPDFSOG.h:82
void normalizeWeights()
Normalize the weights in m_modes such as the maximum log-weight is 0.
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
A class used to store a 3D point.
Definition: CPoint3D.h:33
iterator erase(iterator i)
Definition: CPointPDFSOG.h:107
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void copyFrom(const CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
std::deque< TGaussianMode >::const_iterator const_iterator
Definition: CPointPDFSOG.h:54
double ESS() const
Computes the "Effective sample size" (typical measure for Particle Filters), applied to the weights o...
size_t size() const
Return the number of Gaussian modes.
Definition: CPointPDFSOG.h:111
const_iterator begin() const
Definition: CPointPDFSOG.h:105
const_iterator end() const
Definition: CPointPDFSOG.h:106
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...
CPointPDFSOG(size_t nModes=1)
Default constructor.
void getMostLikelyMode(CPointPDFGaussian &outVal) const
Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in t...
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
GLenum GLint x
Definition: glext.h:3538
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:39
const Scalar * const_iterator
Definition: eigen_plugins.h:27
double evaluatePDF(const CPoint3D &x, bool sumOverAllZs) const
Evaluates the PDF at a given point.
std::deque< TGaussianMode > CListGaussianModes
Definition: CPointPDFSOG.h:53
CListGaussianModes m_modes
The list of SOG modes.
Definition: CPointPDFSOG.h:64
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"...
A gaussian distribution for 3D points.
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), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
std::deque< TGaussianMode >::iterator iterator
Definition: CPointPDFSOG.h:55
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...

 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019 