Main MRPT website > C++ reference
MRPT logo
CPointPDFGaussian.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPointPDFGaussian_H
29 #define CPointPDFGaussian_H
30 
31 #include <mrpt/poses/CPointPDF.h>
32 #include <mrpt/math/CMatrix.h>
33 
34 namespace mrpt
35 {
36 namespace poses
37 {
38  using namespace mrpt::math;
39 
41 
42  /** A gaussian distribution for 3D points. Also a method for bayesian fusion is provided.
43  *
44  * \sa CPointPDF
45  * \ingroup poses_pdf_grp
46  */
48  {
49  // This must be added to any CSerializable derived class:
51 
52  public:
53  /** Default constructor
54  */
56 
57  /** Constructor
58  */
59  CPointPDFGaussian( const CPoint3D &init_Mean );
60 
61  /** Constructor
62  */
63  CPointPDFGaussian( const CPoint3D &init_Mean, const CMatrixDouble33 &init_Cov );
64 
65  /** The mean value
66  */
68 
69  /** The 3x3 covariance matrix
70  */
72 
73  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
74  */
75  void getMean(CPoint3D &p) const;
76 
77  /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
78  * \sa getMean
79  */
80  void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const;
81 
82  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
83  */
84  void copyFrom(const CPointPDF &o);
85 
86  /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines.
87  */
88  void saveToTextFile(const std::string &file) const;
89 
90  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
91  * "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.
92  */
93  void changeCoordinatesReference( const CPose3D &newReferenceBase );
94 
95  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
96  * The process is as follows:<br>
97  * - (x1,S1): Mean and variance of the p1 distribution.
98  * - (x2,S2): Mean and variance of the p2 distribution.
99  * - (x,S): Mean and variance of the resulting distribution.
100  *
101  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
102  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
103  */
104  void bayesianFusion( const CPointPDFGaussian &p1, const CPointPDFGaussian &p2 );
105 
106  /** 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.
107  * The resulting number is >=0.
108  * \sa productIntegralNormalizedWith
109  * \exception std::exception On errors like covariance matrix with null determinant, etc...
110  */
111  double productIntegralWith( const CPointPDFGaussian &p) const;
112 
113  /** 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.
114  * The resulting number is >=0.
115  * NOTE: This version ignores the "z" coordinates!!
116  * \sa productIntegralNormalizedWith
117  * \exception std::exception On errors like covariance matrix with null determinant, etc...
118  */
119  double productIntegralWith2D( const CPointPDFGaussian &p) const;
120 
121  /** 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.
122  * The resulting number is in the range [0,1]
123  * Note that the resulting value is in fact
124  * \f[ exp( -\frac{1}{2} D^2 ) \f]
125  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
126  * \sa productIntegralWith
127  * \exception std::exception On errors like covariance matrix with null determinant, etc...
128  */
129  double productIntegralNormalizedWith( const CPointPDFGaussian &p) const;
130 
131  /** 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.
132  * The resulting number is in the range [0,1]. This versions ignores the "z" coordinate.
133  *
134  * Note that the resulting value is in fact
135  * \f[ exp( -\frac{1}{2} D^2 ) \f]
136  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
137  * \sa productIntegralWith
138  * \exception std::exception On errors like covariance matrix with null determinant, etc...
139  */
140  double productIntegralNormalizedWith2D( const CPointPDFGaussian &p) const;
141 
142  /** Draw a sample from the pdf.
143  */
144  void drawSingleSample(CPoint3D &outSample) const;
145 
146  /** 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!)
147  * \param p1 The first distribution to fuse
148  * \param p2 The second distribution to fuse
149  * \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.
150  */
151  void bayesianFusion( const CPointPDF &p1,const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0);
152 
153 
154  /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0)
155  */
156  double mahalanobisDistanceTo( const CPointPDFGaussian & other, bool only_2D = false ) const;
157 
158 
159  }; // End of class def.
160 
161 
162  } // End of namespace
163 } // End of namespace
164 
165 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013