64 size_t N = m_modes.size();
72 for (it=m_modes.begin();it!=m_modes.end();++it)
75 sumW +=
w = exp(it->log_w);
76 X += it->val.mean.x() *
w;
77 Y += it->val.mean.y() *
w;
78 Z += it->val.mean.z() *
w;
98 size_t N = m_modes.size();
113 for (it=m_modes.begin();it!=m_modes.end();++it)
116 sumW +=
w = exp(it->log_w);
121 partCov.multiply_AAt(estMean_i);
122 partCov+=it->val.cov;
128 estCov *= (1.0/sumW);
146 for (it=m_modes.begin();it!=m_modes.end();++it)
150 out << it->val.cov(0,0) << it->val.cov(1,1) << it->val.cov(2,2);
151 out << it->val.cov(0,1) << it->val.cov(0,2) << it->val.cov(1,2);
174 for (it=m_modes.begin();it!=m_modes.end();++it)
179 if (
version==0) it->log_w = log(max(1e-300,it->log_w));
183 in >>
x; it->val.cov(0,0) =
x;
184 in >>
x; it->val.cov(1,1) =
x;
185 in >>
x; it->val.cov(2,2) =
x;
187 in >>
x; it->val.cov(1,0) =
x; it->val.cov(0,1) =
x;
188 in >>
x; it->val.cov(2,0) =
x; it->val.cov(0,2) =
x;
189 in >>
x; it->val.cov(1,2) =
x; it->val.cov(2,1) =
x;
203 if (
this == &o)
return;
207 m_modes =
static_cast<const CPointPDFSOG*
>(&o)->m_modes;
213 m_modes[0].log_w = 0;
232 it->val.mean.x(), it->val.mean.y(), it->val.mean.z(),
233 it->val.cov(0,0),it->val.cov(1,1),it->val.cov(2,2),
234 it->val.cov(0,1),it->val.cov(0,2),it->val.cov(1,2) );
244 it->val.changeCoordinatesReference( newReferenceBase );
258 vector<double> logWeights( m_modes.size() );
259 vector<size_t> outIdxs;
262 for (it=m_modes.begin(),itW=logWeights.begin();it!=m_modes.end();++it,++itW)
265 CParticleFilterCapable::computeResampling(
266 CParticleFilter::prMultinomial,
272 size_t selectedIdx = outIdxs[0];
273 ASSERT_(selectedIdx<m_modes.size());
282 outSample.
x( selMode->
mean.
x() + vec[0] );
283 outSample.
y( selMode->
mean.
y() + vec[1] );
284 outSample.z( selMode->
mean.z() + vec[2] );
307 float minMahalanobisDistToDrop2 =
square(minMahalanobisDistToDrop);
310 this->m_modes.clear();
318 if (
c.get_unsafe(2,2)==0)
333 double a = -0.5*( 3*log(
M_2PI) - log( covInv.det() ) +
334 eta.multiply_HtCH_scalar(
c));
338 auxSOG_Kernel_i = (*it2).val;
339 if (auxSOG_Kernel_i.
cov.get_unsafe(2,2)==0) { auxSOG_Kernel_i.
cov.set_unsafe(2,2,1); is2D=
true; }
340 ASSERT_(auxSOG_Kernel_i.
cov(0,0)>0 && auxSOG_Kernel_i.
cov(1,1)>0 )
344 bool reallyComputeThisOne =
true;
345 if (minMahalanobisDistToDrop>0)
350 float stdX2 = max(auxSOG_Kernel_i.
cov.get_unsafe(0,0) , (*it1).val.cov.get_unsafe(0,0));
351 mahaDist2 =
square( auxSOG_Kernel_i.
mean.
x() - (*it1).val.mean.x() )/stdX2;
353 float stdY2 = max(auxSOG_Kernel_i.
cov.get_unsafe(1,1), (*it1).val.cov.get_unsafe(1,1));
354 mahaDist2 +=
square( auxSOG_Kernel_i.
mean.
y() - (*it1).val.mean.y() )/stdY2;
358 float stdZ2 = max( auxSOG_Kernel_i.
cov.get_unsafe(2,2), (*it1).val.cov.get_unsafe(2,2) );
359 mahaDist2 +=
square( auxSOG_Kernel_i.
mean.z() - (*it1).val.mean.z() )/stdZ2;
362 reallyComputeThisOne = mahaDist2 < minMahalanobisDistToDrop2;
365 if (reallyComputeThisOne)
379 newKernel.
val = auxGaussianProduct;
383 eta_i = covInv_i * eta_i;
387 new_eta_i = new_covInv_i * new_eta_i;
389 double a_i = -0.5*( 3*log(
M_2PI) - log( new_covInv_i.det() ) + (eta_i.adjoint() * auxSOG_Kernel_i.
cov * eta_i)(0,0) );
390 double new_a_i = -0.5*( 3*log(
M_2PI) - log( new_covInv_i.det() ) + (new_eta_i.adjoint() * newKernel.
val.
cov * new_eta_i)(0,0) );
392 newKernel.
log_w = (it1)->log_w + (it2)->log_w +
a + a_i - new_a_i ;
395 if (is2D) newKernel.
val.
cov(2,2)=0;
398 this->m_modes.push_back( newKernel );
419 it->val.cov(0,1) = it->val.cov(1,0);
420 it->val.cov(0,2) = it->val.cov(2,0);
421 it->val.cov(1,2) = it->val.cov(2,1);
434 if (!m_modes.size())
return;
437 double maxW = m_modes[0].log_w;
438 for (it=m_modes.begin();it!=m_modes.end();++it)
439 maxW = max(maxW,it->log_w);
441 for (it=m_modes.begin();it!=m_modes.end();++it)
457 double sumLinearWeights = 0;
458 for (it=m_modes.begin();it!=m_modes.end();++it) sumLinearWeights += exp(it->log_w);
461 for (it=m_modes.begin();it!=m_modes.end();++it)
462 cum+=
square( exp(it->log_w) / sumLinearWeights );
466 else return 1.0/(m_modes.size()*cum);
489 const size_t Nx = (size_t)ceil((x_max-x_min)/resolutionXY);
490 const size_t Ny = (size_t)ceil((y_max-y_min)/resolutionXY);
491 outMatrix.setSize(Ny,Nx);
493 for (
size_t i=0;i<Ny;i++)
495 const float y = y_min + i*resolutionXY;
496 for (
size_t j=0;j<Nx;j++)
498 float x = x_min + j*resolutionXY;
499 outMatrix(i,j) = evaluatePDF(
CPoint3D(
x,
y,
z),sumOverAllZs);
513 bool sumOverAllZs )
const
542 MU(0,0) = it->val.mean.x();
543 MU(1,0) = it->val.mean.y();
545 COV(0,0) = it->val.cov(0,0);
546 COV(1,1) = it->val.cov(1,1);
547 COV(0,1) = COV(1,0) = it->val.cov(0,1);
569 if (it_best==m_modes.end() || it->log_w>it_best->log_w)
572 outVal = it_best->val;
#define CLASS_ID(class_name)
Access to runtime class ID for a defined class name.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
A class used to store a 3D point.
A gaussian distribution for 3D points.
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
void bayesianFusion(const CPointPDFGaussian &p1, const CPointPDFGaussian &p2)
Bayesian fusion of two points gauss.
CPoint3D mean
The mean value.
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x,...
virtual const mrpt::utils::TRuntimeClassId * GetRuntimeClass() const
Returns information about the class of an object in runtime.
Declares a class that represents a Probability Density function (PDF) of a 3D point .
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double &minMahalanobisDistToDrop=0) MRPT_OVERRIDE
Bayesian fusion of two point distributions (product of two distributions->new distribution),...
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPoint3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once.
void evaluatePDFInArea(float x_min, float x_max, float y_min, float y_max, float resolutionXY, float z, mrpt::math::CMatrixD &outMatrix, bool sumOverAllZs=false)
Evaluates the PDF within a rectangular grid and saves the result in a matrix (each row contains value...
void saveToTextFile(const std::string &file) const MRPT_OVERRIDE
Save the density to a text file, with the following format: There is one row per Gaussian "mode",...
CListGaussianModes m_modes
The list of SOG modes.
std::deque< TGaussianMode >::const_iterator const_iterator
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.
void getMean(CPoint3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
double ESS() const
Computes the "Effective sample size" (typical measure for Particle Filters), applied to the weights o...
void normalizeWeights()
Normalize the weights in m_modes such as the maximum log-weight is 0.
void copyFrom(const CPointPDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations)
double evaluatePDF(const CPoint3D &x, bool sumOverAllZs) const
Evaluates the PDF at a given point.
void resize(const size_t N)
Resize the number of SOG modes.
void getMostLikelyMode(CPointPDFGaussian &outVal) const
Return the Gaussian mode with the highest likelihood (or an empty Gaussian if there are no modes in t...
void drawSingleSample(CPoint3D &outSample) const MRPT_OVERRIDE
Draw a sample from the pdf.
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void clear()
Clear all the gaussian modes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
double x() const
Common members of all points & poses classes.
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
void drawGaussianMultivariate(std::vector< T > &out_result, const mrpt::math::CMatrixTemplateNumeric< T > &cov, const std::vector< T > *mean=NULL)
Generate multidimensional random samples according to a given covariance matrix.
virtual void getCovarianceAndMean(mrpt::math::CMatrixFixedNumeric< double, STATE_LEN, STATE_LEN > &cov, TDATA &mean_point) const =0
Returns an estimate of the pose covariance matrix (STATE_LENxSTATE_LEN cov matrix) and the mean,...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
EIGEN_STRONG_INLINE bool empty() const
const Scalar * const_iterator
GLubyte GLubyte GLubyte GLubyte w
GLubyte GLubyte GLubyte a
GLsizei const GLchar ** string
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
double BASE_IMPEXP normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
The namespace for Bayesian filtering algorithm: different particle filters and Kalman filter algorith...
This base provides a set of functions for maths stuff.
CMatrixFixedNumeric< double, 3, 1 > CMatrixDouble31
T square(const T x)
Inline function for the square of a number.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
A namespace of pseudo-random numbers genrators of diferent distributions.
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
unsigned __int32 uint32_t
The struct for each mode:
double log_w
The log-weight.