40 m_particles.resize(numberParticles);
41 for (
auto& it : m_particles)
56 if (m_particles.empty())
61 double x = 0,
y = 0,
z = 0;
62 for (it = m_particles.begin(); it != m_particles.end(); it++)
64 const double w = exp(it->log_w);
93 size_t i,
n = m_particles.size();
94 double var_x = 0, var_y = 0, var_p = 0, var_xy = 0, var_xp = 0, var_yp = 0;
98 for (i = 0; i <
n; i++) lin_w_sum += exp(m_particles[i].log_w);
99 if (lin_w_sum == 0) lin_w_sum = 1;
101 for (i = 0; i <
n; i++)
103 double w = exp(m_particles[i].log_w) / lin_w_sum;
105 double err_x = m_particles[i].d->x -
mean.x();
106 double err_y = m_particles[i].d->y -
mean.y();
107 double err_phi = m_particles[i].d->z -
mean.z();
112 var_xy += err_x * err_y *
w;
113 var_xp += err_x * err_phi *
w;
114 var_yp += err_y * err_phi *
w;
124 cov(1, 0) =
cov(0, 1) = var_xy;
125 cov(2, 0) =
cov(0, 2) = var_xp;
126 cov(1, 2) =
cov(2, 1) = var_yp;
139 it != m_particles.end(); ++it)
140 out << it->log_w << it->d->x << it->d->y << it->d->z;
155 it != m_particles.end(); ++it)
156 in >> it->log_w >> it->d->x >> it->d->y >> it->d->z;
166 if (
this == &o)
return;
180 if (!f)
return false;
182 size_t i, N = m_particles.size();
183 for (i = 0; i < N; i++)
185 f,
"%f %f %f %e\n", m_particles[i].d->x, m_particles[i].d->y,
186 m_particles[i].d->z, m_particles[i].log_w);
197 const CPose3D& newReferenceBase)
201 it != m_particles.end(); ++it)
204 it->d->x, it->d->y, it->d->z,
229 it != m_particles.end(); ++it)
235 m *= 1.0 / m_particles.size();
239 it != m_particles.end(); ++it)
241 var[0] +=
square(it->d->x - m[0]);
242 var[1] +=
square(it->d->y - m[1]);
243 var[2] +=
square(it->d->z - m[2]);
245 var *= 1.0 / m_particles.size();
252 it != m_particles.end(); ++it)
254 mu4[0] += pow(it->d->x - m[0], 4.0);
255 mu4[1] += pow(it->d->y - m[1], 4.0);
256 mu4[2] += pow(it->d->z - m[2], 4.0);
258 mu4 *= 1.0 / m_particles.size();
261 kurts.array() = mu4.array() / var.array();
282 const double minMahalanobisDistToDrop)
void drawSingleSample(CPoint3D &outSample) const override
Draw a sample from the pdf.
#define THROW_EXCEPTION(msg)
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
int void 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.
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...
bool saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file, where each line is: X Y Z LOG_W.
GLubyte GLubyte GLubyte GLubyte w
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
Lightweight 3D point (float version).
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double minMahalanobisDistToDrop=0) 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!)
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...
double x
X,Y,Z coordinates.
void getMean(CPoint3D &mean_point) const override
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) ...
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...
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
void copyFrom(const CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, 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...
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
void setSize(size_t numberParticles, const mrpt::math::TPoint3Df &defaultValue=mrpt::math::TPoint3Df{0, 0, 0})
Erase all the previous particles and change the number of particles, with a given initial value...
void clear()
Clear all the particles (free memory)
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
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...
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPoint3D &mean_point) const override
Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once...
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)...
const Scalar * const_iterator
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.