Main MRPT website > C++ reference for MRPT 1.5.9
CPointPDFGaussian.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-2017, 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 CPointPDFGaussian_H
10 #define CPointPDFGaussian_H
11 
12 #include <mrpt/poses/CPointPDF.h>
13 #include <mrpt/math/CMatrix.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
19  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPointPDFGaussian, CPointPDF )
20 
21  /** A gaussian distribution for 3D points. Also a method for bayesian fusion is provided.
22  *
23  * \sa CPointPDF
24  * \ingroup poses_pdf_grp
25  */
27  {
28  // This must be added to any CSerializable derived class:
30 
31  public:
32  /** Default constructor
33  */
35 
36  /** Constructor
37  */
38  CPointPDFGaussian( const CPoint3D &init_Mean );
39 
40  /** Constructor
41  */
42  CPointPDFGaussian( const CPoint3D &init_Mean, const mrpt::math::CMatrixDouble33 &init_Cov );
43 
44  CPoint3D mean; //!< The mean value
45  mrpt::math::CMatrixDouble33 cov; //!< The 3x3 covariance matrix
46 
47  void getMean(CPoint3D &p) const MRPT_OVERRIDE; //!< Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
48 
49  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once. \sa getMean */
50  void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov,CPoint3D &mean_point) const MRPT_OVERRIDE;
51 
52  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
53  void copyFrom(const CPointPDF &o) MRPT_OVERRIDE;
54 
55  /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines. */
56  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
57 
58  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
59  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. Both the mean value and the covariance matrix are updated correctly. */
60  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
61 
62  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
63  * The process is as follows:<br>
64  * - (x1,S1): Mean and variance of the p1 distribution.
65  * - (x2,S2): Mean and variance of the p2 distribution.
66  * - (x,S): Mean and variance of the resulting distribution.
67  *
68  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
69  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
70  */
71  void bayesianFusion( const CPointPDFGaussian &p1, const CPointPDFGaussian &p2 );
72 
73  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
74  * The resulting number is >=0.
75  * \sa productIntegralNormalizedWith
76  * \exception std::exception On errors like covariance matrix with null determinant, etc...
77  */
78  double productIntegralWith( const CPointPDFGaussian &p) const;
79 
80  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
81  * The resulting number is >=0.
82  * NOTE: This version ignores the "z" coordinates!!
83  * \sa productIntegralNormalizedWith
84  * \exception std::exception On errors like covariance matrix with null determinant, etc...
85  */
86  double productIntegralWith2D( const CPointPDFGaussian &p) const;
87 
88  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
89  * The resulting number is in the range [0,1]
90  * Note that the resulting value is in fact
91  * \f[ exp( -\frac{1}{2} D^2 ) \f]
92  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
93  * \sa productIntegralWith
94  * \exception std::exception On errors like covariance matrix with null determinant, etc...
95  */
96  double productIntegralNormalizedWith( const CPointPDFGaussian &p) const;
97 
98  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
99  * The resulting number is in the range [0,1]. This versions ignores the "z" coordinate.
100  *
101  * Note that the resulting value is in fact
102  * \f[ exp( -\frac{1}{2} D^2 ) \f]
103  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
104  * \sa productIntegralWith
105  * \exception std::exception On errors like covariance matrix with null determinant, etc...
106  */
107  double productIntegralNormalizedWith2D( const CPointPDFGaussian &p) const;
108 
109  /** Draw a sample from the pdf */
110  void drawSingleSample(CPoint3D &outSample) const MRPT_OVERRIDE;
111 
112  /** 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!)
113  * \param p1 The first distribution to fuse
114  * \param p2 The second distribution to fuse
115  * \param minMahalanobisDistToDrop If set to different of 0, the result of very separate Gaussian modes (that will result in negligible components) in SOGs will be dropped to reduce the number of modes in the output.
116  */
117  void bayesianFusion( const CPointPDF &p1,const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0) MRPT_OVERRIDE;
118 
119 
120  /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0) */
121  double mahalanobisDistanceTo( const CPointPDFGaussian & other, bool only_2D = false ) const;
122 
123 
124  }; // End of class def.
126 
127 
128  } // End of namespace
129 } // End of namespace
130 
131 #endif
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
CPoint3D mean
The mean value.
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...
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
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
GLsizei const GLchar ** string
Definition: glext.h:3919
A class used to store a 3D point.
Definition: CPoint3D.h:32
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:38
GLfloat GLfloat p
Definition: glext.h:5587
A gaussian distribution for 3D points.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020