42 size_t numberParticles,
46 m_particles.resize(numberParticles);
47 for (
auto &it : m_particles)
61 if (m_particles.empty())
67 for (it=m_particles.begin();it!=m_particles.end();it++)
69 const double w = exp(it->log_w);
97 size_t i,
n = m_particles.size();
98 double var_x=0,var_y=0,var_p=0,var_xy=0,var_xp=0,var_yp=0;
100 double lin_w_sum = 0;
102 for (i=0;i<
n;i++) lin_w_sum+= exp( m_particles[i].log_w );
103 if (lin_w_sum==0) lin_w_sum=1;
107 double w = exp( m_particles[i].log_w ) / lin_w_sum;
109 double err_x = m_particles[i].d->x -
mean.x();
110 double err_y = m_particles[i].d->y -
mean.y();
111 double err_phi = m_particles[i].d->z -
mean.z();
116 var_xy+= err_x*err_y*
w;
117 var_xp+= err_x*err_phi*
w;
118 var_yp+= err_y*err_phi*
w;
128 cov(1,0) =
cov(0,1) = var_xy;
129 cov(2,0) =
cov(0,2) = var_xp;
130 cov(1,2) =
cov(2,1) = var_yp;
149 out << it->log_w << it->d->x << it->d->y << it->d->z;
167 in >> it->log_w >> it->d->x >> it->d->y >> it->d->z;
177 if (
this == &o)
return;
193 size_t i,N = m_particles.size();
195 os::fprintf(f,
"%f %f %f %e\n", m_particles[i].d->x,m_particles[i].d->y,m_particles[i].d->z,m_particles[i].log_w);
211 it->d->x, it->d->y, it->d->z,
241 m*=1.0/m_particles.size();
246 var[0]+=
square(it->d->x-m[0]);
247 var[1]+=
square(it->d->y-m[1]);
248 var[2]+=
square(it->d->z-m[2]);
250 var*=1.0/m_particles.size();
258 mu4[0]+=pow(it->d->x-m[0],4.0);
259 mu4[1]+=pow(it->d->y-m[1],4.0);
260 mu4[2]+=pow(it->d->z-m[2],4.0);
262 mu4*=1.0/m_particles.size();
265 kurts.array() = mu4.array() / var.array();
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
void getMean(CPoint3D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) ...
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
void drawSingleSample(CPoint3D &outSample) const MRPT_OVERRIDE
Draw a sample from the pdf.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION(msg)
This file implements several operations that operate element-wise on individual or pairs of container...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
const Scalar * const_iterator
double z
X,Y,Z coordinates.
void copyFrom(const CPointPDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
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...
GLubyte GLubyte GLubyte GLubyte w
T square(const T x)
Inline function for the square of a number.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
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...
This base provides a set of functions for maths stuff.
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), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void setSize(size_t numberParticles, const CPoint3D &defaultValue=CPoint3D(0, 0, 0))
Erase all the previous particles and change the number of particles, with a given initial value...
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
Data within each particle.
CONTAINER::Scalar maximum(const CONTAINER &v)
GLsizei const GLchar ** string
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void clear()
Clear all the particles (free memory)
unsigned __int32 uint32_t
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
double computeKurtosis()
Compute the kurtosis of the distribution.
A probability distribution of a 2D/3D point, represented as a set of random samples (particles)...
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
void saveToTextFile(const std::string &file) const MRPT_OVERRIDE
Save PDF's particles to a text file, where each line is: X Y Z LOG_W.
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.