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