00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CPointPDFSOG_H 00029 #define CPointPDFSOG_H 00030 00031 #include <mrpt/poses/CPointPDF.h> 00032 #include <mrpt/poses/CPointPDFGaussian.h> 00033 #include <mrpt/math/CMatrix.h> 00034 #include <mrpt/math/CMatrixD.h> 00035 00036 namespace mrpt 00037 { 00038 namespace poses 00039 { 00040 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPointPDFSOG, CPointPDF ) 00041 00042 /** Declares a class that represents a Probability Density function (PDF) of a 3D point \f$ p(\mathbf{x}) = [x ~ y ~ z ]^t \f$. 00043 * This class implements that PDF as the following multi-modal Gaussian distribution: 00044 * 00045 * \f$ p(\mathbf{x}) = \sum\limits_{i=1}^N \omega^i \mathcal{N}( \mathbf{x} ; \bar{\mathbf{x}}^i, \mathbf{\Sigma}^i ) \f$ 00046 * 00047 * Where the number of modes N is the size of CPointPDFSOG::m_modes 00048 * 00049 * See mrpt::poses::CPointPDF for more details. 00050 * 00051 * \sa CPointPDF, CPosePDF, 00052 * \ingroup poses_pdf_grp 00053 */ 00054 class BASE_IMPEXP CPointPDFSOG : public CPointPDF 00055 { 00056 // This must be added to any CSerializable derived class: 00057 DEFINE_SERIALIZABLE( CPointPDFSOG ) 00058 00059 public: 00060 /** The struct for each mode: 00061 */ 00062 struct BASE_IMPEXP TGaussianMode 00063 { 00064 TGaussianMode() : val(), log_w(0) 00065 { 00066 } 00067 00068 CPointPDFGaussian val; 00069 00070 /** The log-weight 00071 */ 00072 double log_w; 00073 }; 00074 00075 typedef std::deque<TGaussianMode> CListGaussianModes; 00076 typedef std::deque<TGaussianMode>::const_iterator const_iterator; 00077 typedef std::deque<TGaussianMode>::iterator iterator; 00078 00079 protected: 00080 /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!) 00081 */ 00082 void assureSymmetry(); 00083 00084 /** The list of SOG modes */ 00085 CListGaussianModes m_modes; 00086 00087 public: 00088 /** Default constructor 00089 * \param nModes The initial size of CPointPDFSOG::m_modes 00090 */ 00091 CPointPDFSOG( size_t nModes = 1 ); 00092 00093 void clear(); //!< Clear all the gaussian modes 00094 00095 /** Access to individual beacons */ 00096 const TGaussianMode& operator [](size_t i) const { 00097 ASSERT_(i<m_modes.size()) 00098 return m_modes[i]; 00099 } 00100 /** Access to individual beacons */ 00101 TGaussianMode& operator [](size_t i) { 00102 ASSERT_(i<m_modes.size()) 00103 return m_modes[i]; 00104 } 00105 00106 /** Access to individual beacons */ 00107 const TGaussianMode& get(size_t i) const { 00108 ASSERT_(i<m_modes.size()) 00109 return m_modes[i]; 00110 } 00111 /** Access to individual beacons */ 00112 TGaussianMode& get(size_t i) { 00113 ASSERT_(i<m_modes.size()) 00114 return m_modes[i]; 00115 } 00116 00117 /** Inserts a copy of the given mode into the SOG */ 00118 void push_back(const TGaussianMode& m) { 00119 m_modes.push_back(m); 00120 } 00121 00122 iterator begin() { return m_modes.begin(); } 00123 iterator end() { return m_modes.end(); } 00124 const_iterator begin() const { return m_modes.begin(); } 00125 const_iterator end()const { return m_modes.end(); } 00126 00127 iterator erase(iterator i) { return m_modes.erase(i); } 00128 00129 void resize(const size_t N); //!< Resize the number of SOG modes 00130 size_t size() const { return m_modes.size(); } //!< Return the number of Gaussian modes. 00131 bool empty() const { return m_modes.empty(); } //!< Return whether there is any Gaussian mode. 00132 00133 /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF). 00134 * \sa getCovariance 00135 */ 00136 void getMean(CPoint3D &mean_point) const; 00137 00138 /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once. 00139 * \sa getMean 00140 */ 00141 void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const; 00142 00143 /** Normalize the weights in m_modes such as the maximum log-weight is 0. 00144 */ 00145 void normalizeWeights(); 00146 00147 /** Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in this SOG) */ 00148 void getMostLikelyMode( CPointPDFGaussian& outVal ) const; 00149 00150 /** Computes the "Effective sample size" (typical measure for Particle Filters), applied to the weights of the individual Gaussian modes, as a measure of the equality of the modes (in the range [0,total # of modes]). 00151 */ 00152 double ESS() const; 00153 00154 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) 00155 */ 00156 void copyFrom(const CPointPDF &o); 00157 00158 /** Save the density to a text file, with the following format: 00159 * There is one row per Gaussian "mode", and each row contains 10 elements: 00160 * - w (The weight) 00161 * - x_mean (gaussian mean value) 00162 * - y_mean (gaussian mean value) 00163 * - x_mean (gaussian mean value) 00164 * - C11 (Covariance elements) 00165 * - C22 (Covariance elements) 00166 * - C33 (Covariance elements) 00167 * - C12 (Covariance elements) 00168 * - C13 (Covariance elements) 00169 * - C23 (Covariance elements) 00170 * 00171 */ 00172 void saveToTextFile(const std::string &file) const; 00173 00174 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which 00175 * "to project" the current pdf. Result PDF substituted the currently stored one in the object. 00176 */ 00177 void changeCoordinatesReference(const CPose3D &newReferenceBase ); 00178 00179 /** Draw a sample from the pdf. 00180 */ 00181 void drawSingleSample(CPoint3D &outSample) const; 00182 00183 /** 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!) 00184 * \param p1 The first distribution to fuse 00185 * \param p2 The second distribution to fuse 00186 * \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. 00187 */ 00188 void bayesianFusion( const CPointPDF &p1, const CPointPDF &p2, const double &minMahalanobisDistToDrop = 0); 00189 00190 00191 /** Evaluates the PDF within a rectangular grid and saves the result in a matrix (each row contains values for a fixed y-coordinate value). 00192 */ 00193 void evaluatePDFInArea( 00194 float x_min, 00195 float x_max, 00196 float y_min, 00197 float y_max, 00198 float resolutionXY, 00199 float z, 00200 CMatrixD &outMatrix, 00201 bool sumOverAllZs = false ); 00202 00203 /** Evaluates the PDF at a given point. 00204 */ 00205 double evaluatePDF( 00206 const CPoint3D &x, 00207 bool sumOverAllZs ) const; 00208 00209 00210 }; // End of class def. 00211 00212 00213 } // End of namespace 00214 } // End of namespace 00215 00216 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |