Main MRPT website > C++ reference for MRPT 1.3.2
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-2015, 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  /** The mean value
45  */
47 
48  /** The 3x3 covariance matrix
49  */
51 
52  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
53  */
54  void getMean(CPoint3D &p) const;
55 
56  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
57  * \sa getMean
58  */
59  void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov,CPoint3D &mean_point) const;
60 
61  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
62  */
63  void copyFrom(const CPointPDF &o);
64 
65  /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines.
66  */
67  void saveToTextFile(const std::string &file) const;
68 
69  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
70  * "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.
71  */
72  void changeCoordinatesReference( const CPose3D &newReferenceBase );
73 
74  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
75  * The process is as follows:<br>
76  * - (x1,S1): Mean and variance of the p1 distribution.
77  * - (x2,S2): Mean and variance of the p2 distribution.
78  * - (x,S): Mean and variance of the resulting distribution.
79  *
80  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
81  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
82  */
83  void bayesianFusion( const CPointPDFGaussian &p1, const CPointPDFGaussian &p2 );
84 
85  /** 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.
86  * The resulting number is >=0.
87  * \sa productIntegralNormalizedWith
88  * \exception std::exception On errors like covariance matrix with null determinant, etc...
89  */
90  double productIntegralWith( const CPointPDFGaussian &p) const;
91 
92  /** 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.
93  * The resulting number is >=0.
94  * NOTE: This version ignores the "z" coordinates!!
95  * \sa productIntegralNormalizedWith
96  * \exception std::exception On errors like covariance matrix with null determinant, etc...
97  */
98  double productIntegralWith2D( const CPointPDFGaussian &p) const;
99 
100  /** 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.
101  * The resulting number is in the range [0,1]
102  * Note that the resulting value is in fact
103  * \f[ exp( -\frac{1}{2} D^2 ) \f]
104  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
105  * \sa productIntegralWith
106  * \exception std::exception On errors like covariance matrix with null determinant, etc...
107  */
108  double productIntegralNormalizedWith( const CPointPDFGaussian &p) const;
109 
110  /** 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.
111  * The resulting number is in the range [0,1]. This versions ignores the "z" coordinate.
112  *
113  * Note that the resulting value is in fact
114  * \f[ exp( -\frac{1}{2} D^2 ) \f]
115  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
116  * \sa productIntegralWith
117  * \exception std::exception On errors like covariance matrix with null determinant, etc...
118  */
119  double productIntegralNormalizedWith2D( const CPointPDFGaussian &p) const;
120 
121  /** Draw a sample from the pdf.
122  */
123  void drawSingleSample(CPoint3D &outSample) const;
124 
125  /** 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!)
126  * \param p1 The first distribution to fuse
127  * \param p2 The second distribution to fuse
128  * \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.
129  */
130  void bayesianFusion( const CPointPDF &p1,const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
131 
132 
133  /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0)
134  */
135  double mahalanobisDistanceTo( const CPointPDFGaussian & other, bool only_2D = false ) const;
136 
137 
138  }; // End of class def.
139  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPointPDFGaussian, CPointPDF )
140 
141 
142  } // End of namespace
143 } // End of namespace
144 
145 #endif
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...
STL namespace.
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
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
Definition: eigen_frwds.h:48
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)
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:38
A gaussian distribution for 3D points.



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Tue Dec 8 09:49:21 UTC 2015