Main MRPT website > C++ reference for MRPT 1.5.6
CPoint2DPDFGaussian.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 |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CPoint2DPDFGaussian_H
10 #define CPoint2DPDFGaussian_H
11
12 #include <mrpt/poses/CPoint2DPDF.h>
13
14 namespace mrpt
15 {
16 namespace poses
17 {
18  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPoint2DPDFGaussian, CPoint2DPDF )
19
20  /** A gaussian distribution for 2D points. Also a method for bayesian fusion is provided.
21  * \ingroup poses_pdf_grp
22  * \sa CPoint2DPDF
23  */
25  {
26  // This must be added to any CSerializable derived class:
28
29  public:
30  CPoint2DPDFGaussian(); //!< Default constructor
31  CPoint2DPDFGaussian( const CPoint2D &init_Mean ); //!< Constructor
32  CPoint2DPDFGaussian( const CPoint2D &init_Mean, const mrpt::math::CMatrixDouble22 &init_Cov ); //!< Constructor
33
34  CPoint2D mean; //!< The mean value
35  mrpt::math::CMatrixDouble22 cov; //!< The 2x2 covariance matrix
36
37  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) */
38  void getMean(CPoint2D &p) const MRPT_OVERRIDE {
39  p = this->mean;
40  }
41
42  /** Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once. \sa getMean */
44  out_cov = this->cov;
45  mean_point = this->mean;
46  }
47
48  void copyFrom(const CPoint2DPDF &o) MRPT_OVERRIDE; //!< Copy operator, translating if necesary (for example, between particles and gaussian representations)
49
50  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE; //!< Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines
51
52  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
53  * "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. */
54  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
55
56  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
57  * The process is as follows:<br>
58  * - (x1,S1): Mean and variance of the p1 distribution.
59  * - (x2,S2): Mean and variance of the p2 distribution.
60  * - (x,S): Mean and variance of the resulting distribution.
61  *
62  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
63  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
64  */
65  void bayesianFusion( const CPoint2DPDFGaussian &p1, const CPoint2DPDFGaussian &p2 );
66
67  /** 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.
68  * The resulting number is >=0.
69  * \sa productIntegralNormalizedWith
70  * \exception std::exception On errors like covariance matrix with null determinant, etc...
71  */
72  double productIntegralWith( const CPoint2DPDFGaussian &p) const;
73
74  /** 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.
75  * The resulting number is in the range [0,1].
76  * Note that the resulting value is in fact
77  * \f[ exp( -\frac{1}{2} D^2 ) \f]
78  * , with \f$D^2 \f$ being the square Mahalanobis distance between the two pdfs.
79  * \sa productIntegralWith
80  * \exception std::exception On errors like covariance matrix with null determinant, etc...
81  */
82  double productIntegralNormalizedWith( const CPoint2DPDFGaussian &p) const;
83
84  void drawSingleSample(CPoint2D &outSample) const MRPT_OVERRIDE; //!< Draw a sample from the pdf
85
86  /** 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!)
87  * \param p1 The first distribution to fuse
88  * \param p2 The second distribution to fuse
89  * \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.
90  */
91  void bayesianFusion( const CPoint2DPDF &p1, const CPoint2DPDF &p2, const double &minMahalanobisDistToDrop = 0) MRPT_OVERRIDE;
92
93  double mahalanobisDistanceTo( const CPoint2DPDFGaussian & other ) const; //!< Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0)
94  double mahalanobisDistanceToPoint( const double x, const double y ) const; //!< Returns the Mahalanobis distance from this PDF to some point
95
96  }; // End of class def.
98  } // End of namespace
99 } // End of namespace
100 #endif
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(CPose3DPDFGaussianInf, CPose3DPDF)
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1166
A gaussian distribution for 2D points.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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...
A numeric matrix of compile-time fixed size.
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
GLint GLint GLint GLint GLint x
Definition: glew.h:1166
Declares a class that represents a Probability Distribution function (PDF) of a 2D point (x...
Definition: CPoint2DPDF.h:35
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
GLfloat GLfloat p
Definition: glew.h:10113
A class used to store a 2D point.
Definition: CPoint2D.h:36
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
GLsizei const GLcharARB ** string
Definition: glew.h:3293
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
void getCovarianceAndMean(mrpt::math::CMatrixDouble22 &out_cov, CPoint2D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once...
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
CMatrixFixedNumeric< double, 2, 2 > CMatrixDouble22
Definition: eigen_frwds.h:45

 Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018