Main MRPT website > C++ reference for MRPT 1.9.9
data_utils.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 |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef MRPT_DATA_UTILS_MATH_H
10 #define MRPT_DATA_UTILS_MATH_H
11 
12 #include <mrpt/utils/utils_defs.h>
13 #include <mrpt/math/wrap2pi.h>
15 #include <mrpt/math/ops_matrices.h>
16 
17 namespace mrpt
18 {
19 /** This base provides a set of functions for maths stuff. \ingroup
20  * mrpt_base_grp
21  */
22 namespace math
23 {
24 /** \addtogroup stats_grp
25  * @{
26  */
27 
28 /** @name Probability density distributions (pdf) distance metrics
29 @{ */
30 
31 /** Computes the squared mahalanobis distance of a vector X given the mean MU
32  * and the covariance *inverse* COV_inv
33  * \f[ d^2 = (X-MU)^\top \Sigma^{-1} (X-MU) \f]
34  */
35 template <class VECTORLIKE1, class VECTORLIKE2, class MAT>
37  const VECTORLIKE1& X, const VECTORLIKE2& MU, const MAT& COV)
38 {
40 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
41  ASSERT_(!X.empty());
42  ASSERT_(X.size() == MU.size());
43  ASSERT_(X.size() == size(COV, 1) && COV.isSquare());
44 #endif
45  const size_t N = X.size();
46  Eigen::Matrix<typename MAT::Scalar, Eigen::Dynamic, 1> X_MU(N);
47  for (size_t i = 0; i < N; i++) X_MU[i] = X[i] - MU[i];
48  const Eigen::Matrix<typename MAT::Scalar, Eigen::Dynamic, 1> z =
49  COV.llt().solve(X_MU);
50  return z.dot(z);
51  MRPT_END
52 }
53 
54 /** Computes the mahalanobis distance of a vector X given the mean MU and the
55  * covariance *inverse* COV_inv
56  * \f[ d = \sqrt{ (X-MU)^\top \Sigma^{-1} (X-MU) } \f]
57  */
58 template <class VECTORLIKE1, class VECTORLIKE2, class MAT>
60  const VECTORLIKE1& X, const VECTORLIKE2& MU, const MAT& COV)
61 {
62  return std::sqrt(mahalanobisDistance2(X, MU, COV));
63 }
64 
65 /** Computes the squared mahalanobis distance between two *non-independent*
66  * Gaussians, given the two covariance matrices and the vector with the
67  * difference of their means.
68  * \f[ d^2 = \Delta_\mu^\top (\Sigma_1 + \Sigma_2 - 2 \Sigma_12 )^{-1}
69  * \Delta_\mu \f]
70  */
71 template <class VECTORLIKE, class MAT1, class MAT2, class MAT3>
73  const VECTORLIKE& mean_diffs, const MAT1& COV1, const MAT2& COV2,
74  const MAT3& CROSS_COV12)
75 {
77 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
78  ASSERT_(!mean_diffs.empty());
79  ASSERT_(mean_diffs.size() == size(COV1, 1));
80  ASSERT_(COV1.isSquare() && COV2.isSquare());
81  ASSERT_(size(COV1, 1) == size(COV2, 1));
82 #endif
83  MAT1 COV = COV1;
84  COV += COV2;
85  COV.substract_An(CROSS_COV12, 2);
86  MAT1 COV_inv;
87  COV.inv_fast(COV_inv);
88  return multiply_HCHt_scalar(mean_diffs, COV_inv);
89  MRPT_END
90 }
91 
92 /** Computes the mahalanobis distance between two *non-independent* Gaussians
93  * (or independent if CROSS_COV12=nullptr), given the two covariance matrices
94  * and the vector with the difference of their means.
95  * \f[ d = \sqrt{ \Delta_\mu^\top (\Sigma_1 + \Sigma_2 - 2 \Sigma_12 )^{-1}
96  * \Delta_\mu } \f]
97  */
98 template <class VECTORLIKE, class MAT1, class MAT2, class MAT3>
100  const VECTORLIKE& mean_diffs, const MAT1& COV1, const MAT2& COV2,
101  const MAT3& CROSS_COV12)
102 {
103  return std::sqrt(mahalanobisDistance(mean_diffs, COV1, COV2, CROSS_COV12));
104 }
105 
106 /** Computes the squared mahalanobis distance between a point and a Gaussian,
107  * given the covariance matrix and the vector with the difference between the
108  * mean and the point.
109  * \f[ d^2 = \Delta_\mu^\top \Sigma^{-1} \Delta_\mu \f]
110  */
111 template <class VECTORLIKE, class MATRIXLIKE>
113  const VECTORLIKE& delta_mu, const MATRIXLIKE& cov)
114 {
115  ASSERTDEB_(cov.isSquare())
116  ASSERTDEB_(size_t(cov.getColCount()) == size_t(delta_mu.size()))
117  return multiply_HCHt_scalar(delta_mu, cov.inverse());
118 }
119 
120 /** Computes the mahalanobis distance between a point and a Gaussian, given the
121  * covariance matrix and the vector with the difference between the mean and the
122  * point.
123  * \f[ d^2 = \sqrt( \Delta_\mu^\top \Sigma^{-1} \Delta_\mu ) \f]
124  */
125 template <class VECTORLIKE, class MATRIXLIKE>
127  const VECTORLIKE& delta_mu, const MATRIXLIKE& cov)
128 {
129  return std::sqrt(mahalanobisDistance2(delta_mu, cov));
130 }
131 
132 /** Computes the integral of the product of two Gaussians, with means separated
133  * by "mean_diffs" and covariances "COV1" and "COV2".
134  * \f[ D = \frac{1}{(2 \pi)^{0.5 N} \sqrt{} } \exp( \Delta_\mu^\top
135  * (\Sigma_1 + \Sigma_2 - 2 \Sigma_12)^{-1} \Delta_\mu) \f]
136  */
137 template <typename T>
139  const std::vector<T>& mean_diffs, const CMatrixTemplateNumeric<T>& COV1,
140  const CMatrixTemplateNumeric<T>& COV2)
141 {
142  const size_t vector_dim = mean_diffs.size();
143  ASSERT_(vector_dim >= 1)
144 
145  CMatrixTemplateNumeric<T> C = COV1;
146  C += COV2; // Sum of covs:
147  const T cov_det = C.det();
149  C.inv_fast(C_inv);
150 
151  return std::pow(M_2PI, -0.5 * vector_dim) * (1.0 / std::sqrt(cov_det)) *
152  exp(-0.5 * mean_diffs.multiply_HCHt_scalar(C_inv));
153 }
154 
155 /** Computes the integral of the product of two Gaussians, with means separated
156  * by "mean_diffs" and covariances "COV1" and "COV2".
157  * \f[ D = \frac{1}{(2 \pi)^{0.5 N} \sqrt{} } \exp( \Delta_\mu^\top
158  * (\Sigma_1 + \Sigma_2)^{-1} \Delta_\mu) \f]
159  */
160 template <typename T, size_t DIM>
162  const std::vector<T>& mean_diffs,
165 {
166  ASSERT_(mean_diffs.size() == DIM);
167 
169  C += COV2; // Sum of covs:
170  const T cov_det = C.det();
172  C.inv_fast(C_inv);
173 
174  return std::pow(M_2PI, -0.5 * DIM) * (1.0 / std::sqrt(cov_det)) *
175  exp(-0.5 * mean_diffs.multiply_HCHt_scalar(C_inv));
176 }
177 
178 /** Computes both, the integral of the product of two Gaussians and their square
179  * Mahalanobis distance.
180  * \sa productIntegralTwoGaussians, mahalanobisDistance2
181  */
182 template <typename T, class VECLIKE, class MATLIKE1, class MATLIKE2>
184  const VECLIKE& mean_diffs, const MATLIKE1& COV1, const MATLIKE2& COV2,
185  T& maha2_out, T& intprod_out, const MATLIKE1* CROSS_COV12 = nullptr)
186 {
187  const size_t vector_dim = mean_diffs.size();
188  ASSERT_(vector_dim >= 1)
189 
190  MATLIKE1 C = COV1;
191  C += COV2; // Sum of covs:
192  if (CROSS_COV12)
193  {
194  C -= *CROSS_COV12;
195  C -= *CROSS_COV12;
196  }
197  const T cov_det = C.det();
198  MATLIKE1 C_inv;
199  C.inv_fast(C_inv);
200 
201  maha2_out = mean_diffs.multiply_HCHt_scalar(C_inv);
202  intprod_out = std::pow(M_2PI, -0.5 * vector_dim) *
203  (1.0 / std::sqrt(cov_det)) * exp(-0.5 * maha2_out);
204 }
205 
206 /** Computes both, the logarithm of the PDF and the square Mahalanobis distance
207  * between a point (given by its difference wrt the mean) and a Gaussian.
208  * \sa productIntegralTwoGaussians, mahalanobisDistance2, normalPDF,
209  * mahalanobisDistance2AndPDF
210  */
211 template <typename T, class VECLIKE, class MATRIXLIKE>
213  const VECLIKE& diff_mean, const MATRIXLIKE& cov, T& maha2_out,
214  T& log_pdf_out)
215 {
216  MRPT_START
217  ASSERTDEB_(cov.isSquare())
218  ASSERTDEB_(size_t(cov.getColCount()) == size_t(diff_mean.size()))
219  MATRIXLIKE C_inv;
220  cov.inv(C_inv);
221  maha2_out = multiply_HCHt_scalar(diff_mean, C_inv);
222  log_pdf_out = static_cast<typename MATRIXLIKE::Scalar>(-0.5) *
223  (maha2_out +
224  static_cast<typename MATRIXLIKE::Scalar>(cov.getColCount()) *
225  ::log(static_cast<typename MATRIXLIKE::Scalar>(M_2PI)) +
226  ::log(cov.det()));
227  MRPT_END
228 }
229 
230 /** Computes both, the PDF and the square Mahalanobis distance between a point
231  * (given by its difference wrt the mean) and a Gaussian.
232  * \sa productIntegralTwoGaussians, mahalanobisDistance2, normalPDF
233  */
234 template <typename T, class VECLIKE, class MATRIXLIKE>
236  const VECLIKE& diff_mean, const MATRIXLIKE& cov, T& maha2_out, T& pdf_out)
237 {
238  mahalanobisDistance2AndLogPDF(diff_mean, cov, maha2_out, pdf_out);
239  pdf_out = std::exp(pdf_out); // log to linear
240 }
241 
242 /** Computes covariances and mean of any vector of containers, given optional
243  * weights for the different samples.
244  * \param elements Any kind of vector of vectors/arrays, eg.
245  * std::vector<mrpt::math::CVectorDouble>, with all the input samples, each
246  * sample in a "row".
247  * \param covariances Output estimated covariance; it can be a fixed/dynamic
248  * matrix or a matrixview.
249  * \param means Output estimated mean; it can be CVectorDouble/CArrayDouble,
250  * etc...
251  * \param weights_mean If !=nullptr, it must point to a vector of
252  * size()==number of elements, with normalized weights to take into account for
253  * the mean.
254  * \param weights_cov If !=nullptr, it must point to a vector of size()==number
255  * of elements, with normalized weights to take into account for the covariance.
256  * \param elem_do_wrap2pi If !=nullptr; it must point to an array of "bool" of
257  * size()==dimension of each element, stating if it's needed to do a wrap to
258  * [-pi,pi] to each dimension.
259  * \sa This method is used in mrpt::math::unscented_transform_gaussian
260  * \ingroup stats_grp
261  */
262 template<class VECTOR_OF_VECTORS, class MATRIXLIKE,class VECTORLIKE,class VECTORLIKE2,class VECTORLIKE3>
263  inline void covariancesAndMeanWeighted( // Done inline to speed-up the special case expanded in covariancesAndMean() below.
264  const VECTOR_OF_VECTORS &elements,
265  MATRIXLIKE &covariances,
266  VECTORLIKE &means,
267  const VECTORLIKE2 *weights_mean,
268  const VECTORLIKE3 *weights_cov,
269  const bool *elem_do_wrap2pi = nullptr
270  )
271 {
272  ASSERTMSG_(
273  elements.size() != 0,
274  "No samples provided, so there is no way to deduce the output size.")
275  typedef typename MATRIXLIKE::Scalar T;
276  const size_t DIM = elements[0].size();
277  means.resize(DIM);
278  covariances.setSize(DIM, DIM);
279  const size_t nElms = elements.size();
280  const T NORM = 1.0 / nElms;
281  if (weights_mean)
282  {
283  ASSERTDEB_(size_t(weights_mean->size()) == size_t(nElms))
284  }
285  // The mean goes first:
286  for (size_t i = 0; i < DIM; i++)
287  {
288  T accum = 0;
289  if (!elem_do_wrap2pi || !elem_do_wrap2pi[i])
290  { // i'th dimension is a "normal", real number:
291  if (weights_mean)
292  {
293  for (size_t j = 0; j < nElms; j++)
294  accum += (*weights_mean)[j] * elements[j][i];
295  }
296  else
297  {
298  for (size_t j = 0; j < nElms; j++) accum += elements[j][i];
299  accum *= NORM;
300  }
301  }
302  else
303  { // i'th dimension is a circle in [-pi,pi]: we need a little trick
304  // here:
305  double accum_L = 0, accum_R = 0;
306  double Waccum_L = 0, Waccum_R = 0;
307  for (size_t j = 0; j < nElms; j++)
308  {
309  double ang = elements[j][i];
310  const double w =
311  weights_mean != nullptr ? (*weights_mean)[j] : NORM;
312  if (fabs(ang) > 0.5 * M_PI)
313  { // LEFT HALF: 0,2pi
314  if (ang < 0) ang = (M_2PI + ang);
315  accum_L += ang * w;
316  Waccum_L += w;
317  }
318  else
319  { // RIGHT HALF: -pi,pi
320  accum_R += ang * w;
321  Waccum_R += w;
322  }
323  }
324  if (Waccum_L > 0) accum_L /= Waccum_L; // [0,2pi]
325  if (Waccum_R > 0) accum_R /= Waccum_R; // [-pi,pi]
326  if (accum_L > M_PI)
327  accum_L -= M_2PI; // Left side to [-pi,pi] again:
328  accum =
329  (accum_L * Waccum_L +
330  accum_R * Waccum_R); // The overall result:
331  }
332  means[i] = accum;
333  }
334  // Now the covariance:
335  for (size_t i = 0; i < DIM; i++)
336  for (size_t j = 0; j <= i; j++) // Only 1/2 of the matrix
337  {
338  typename MATRIXLIKE::Scalar elem = 0;
339  if (weights_cov)
340  {
341  ASSERTDEB_(size_t(weights_cov->size()) == size_t(nElms))
342  for (size_t k = 0; k < nElms; k++)
343  {
344  const T Ai = (elements[k][i] - means[i]);
345  const T Aj = (elements[k][j] - means[j]);
346  if (!elem_do_wrap2pi || !elem_do_wrap2pi[i])
347  elem += (*weights_cov)[k] * Ai * Aj;
348  else
349  elem += (*weights_cov)[k] * mrpt::math::wrapToPi(Ai) *
351  }
352  }
353  else
354  {
355  for (size_t k = 0; k < nElms; k++)
356  {
357  const T Ai = (elements[k][i] - means[i]);
358  const T Aj = (elements[k][j] - means[j]);
359  if (!elem_do_wrap2pi || !elem_do_wrap2pi[i])
360  elem += Ai * Aj;
361  else
362  elem +=
364  }
365  elem *= NORM;
366  }
367  covariances.get_unsafe(i, j) = elem;
368  if (i != j) covariances.get_unsafe(j, i) = elem;
369  }
370 }
371 
372 /** Computes covariances and mean of any vector of containers.
373  * \param elements Any kind of vector of vectors/arrays, eg.
374  * std::vector<mrpt::math::CVectorDouble>, with all the input samples, each
375  * sample in a "row".
376  * \param covariances Output estimated covariance; it can be a fixed/dynamic
377  * matrix or a matrixview.
378  * \param means Output estimated mean; it can be CVectorDouble/CArrayDouble,
379  * etc...
380  * \param elem_do_wrap2pi If !=nullptr; it must point to an array of "bool" of
381  * size()==dimension of each element, stating if it's needed to do a wrap to
382  * [-pi,pi] to each dimension.
383  * \ingroup stats_grp
384  */
385 template <class VECTOR_OF_VECTORS, class MATRIXLIKE, class VECTORLIKE>
387  const VECTOR_OF_VECTORS& elements, MATRIXLIKE& covariances,
388  VECTORLIKE& means, const bool* elem_do_wrap2pi = nullptr)
389 { // The function below is inline-expanded here:
390  covariancesAndMeanWeighted<VECTOR_OF_VECTORS, MATRIXLIKE, VECTORLIKE,
392  elements, covariances, means, nullptr, nullptr, elem_do_wrap2pi);
393 }
394 
395 /** Computes the weighted histogram for a vector of values and their
396  * corresponding weights.
397  * \param values [IN] The N values
398  * \param weights [IN] The weights for the corresponding N values (don't need
399  * to be normalized)
400  * \param binWidth [IN] The desired width of the bins
401  * \param out_binCenters [OUT] The centers of the M bins generated to cover
402  * from the minimum to the maximum value of "values" with the given "binWidth"
403  * \param out_binValues [OUT] The ratio of values at each given bin, such as
404  * the whole vector sums up the unity.
405  * \sa weightedHistogramLog
406  */
407 template <class VECTORLIKE1, class VECTORLIKE2>
409  const VECTORLIKE1& values, const VECTORLIKE1& weights, float binWidth,
410  VECTORLIKE2& out_binCenters, VECTORLIKE2& out_binValues)
411 {
412  MRPT_START
414 
415  ASSERT_(values.size() == weights.size());
416  ASSERT_(binWidth > 0);
417  TNum minBin = minimum(values);
418  unsigned int nBins =
419  static_cast<unsigned>(ceil((maximum(values) - minBin) / binWidth));
420 
421  // Generate bin center and border values:
422  out_binCenters.resize(nBins);
423  out_binValues.clear();
424  out_binValues.resize(nBins, 0);
425  TNum halfBin = TNum(0.5) * binWidth;
426  ;
427  VECTORLIKE2 binBorders(nBins + 1, minBin - halfBin);
428  for (unsigned int i = 0; i < nBins; i++)
429  {
430  binBorders[i + 1] = binBorders[i] + binWidth;
431  out_binCenters[i] = binBorders[i] + halfBin;
432  }
433 
434  // Compute the histogram:
435  TNum totalSum = 0;
436  typename VECTORLIKE1::const_iterator itVal, itW;
437  for (itVal = values.begin(), itW = weights.begin(); itVal != values.end();
438  ++itVal, ++itW)
439  {
440  int idx = round(((*itVal) - minBin) / binWidth);
441  if (idx >= int(nBins)) idx = nBins - 1;
442  ASSERTDEB_(idx >= 0);
443  out_binValues[idx] += *itW;
444  totalSum += *itW;
445  }
446 
447  if (totalSum) out_binValues /= totalSum;
448 
449  MRPT_END
450 }
451 
452 /** Computes the weighted histogram for a vector of values and their
453  * corresponding log-weights.
454  * \param values [IN] The N values
455  * \param weights [IN] The log-weights for the corresponding N values (don't
456  * need to be normalized)
457  * \param binWidth [IN] The desired width of the bins
458  * \param out_binCenters [OUT] The centers of the M bins generated to cover
459  * from the minimum to the maximum value of "values" with the given "binWidth"
460  * \param out_binValues [OUT] The ratio of values at each given bin, such as
461  * the whole vector sums up the unity.
462  * \sa weightedHistogram
463  */
464 template <class VECTORLIKE1, class VECTORLIKE2>
466  const VECTORLIKE1& values, const VECTORLIKE1& log_weights, float binWidth,
467  VECTORLIKE2& out_binCenters, VECTORLIKE2& out_binValues)
468 {
469  MRPT_START
471 
472  ASSERT_(values.size() == log_weights.size());
473  ASSERT_(binWidth > 0);
474  TNum minBin = minimum(values);
475  unsigned int nBins =
476  static_cast<unsigned>(ceil((maximum(values) - minBin) / binWidth));
477 
478  // Generate bin center and border values:
479  out_binCenters.resize(nBins);
480  out_binValues.clear();
481  out_binValues.resize(nBins, 0);
482  TNum halfBin = TNum(0.5) * binWidth;
483  ;
484  VECTORLIKE2 binBorders(nBins + 1, minBin - halfBin);
485  for (unsigned int i = 0; i < nBins; i++)
486  {
487  binBorders[i + 1] = binBorders[i] + binWidth;
488  out_binCenters[i] = binBorders[i] + halfBin;
489  }
490 
491  // Compute the histogram:
492  const TNum max_log_weight = maximum(log_weights);
493  TNum totalSum = 0;
494  typename VECTORLIKE1::const_iterator itVal, itW;
495  for (itVal = values.begin(), itW = log_weights.begin();
496  itVal != values.end(); ++itVal, ++itW)
497  {
498  int idx = round(((*itVal) - minBin) / binWidth);
499  if (idx >= int(nBins)) idx = nBins - 1;
500  ASSERTDEB_(idx >= 0);
501  const TNum w = exp(*itW - max_log_weight);
502  out_binValues[idx] += w;
503  totalSum += w;
504  }
505 
506  if (totalSum) out_binValues /= totalSum;
507 
508  MRPT_END
509 }
510 
511 /** A numerically-stable method to compute average likelihood values with
512  * strongly different ranges (unweighted likelihoods: compute the arithmetic
513  * mean).
514  * This method implements this equation:
515  *
516  * \f[ return = - \log N + \log \sum_{i=1}^N e^{ll_i-ll_{max}} + ll_{max} \f]
517  *
518  * See also the <a
519  * href="http://www.mrpt.org/Averaging_Log-Likelihood_Values:Numerical_Stability">tutorial
520  * page</a>.
521  * \ingroup stats_grp
522  */
523 double averageLogLikelihood(const CVectorDouble& logLikelihoods);
524 
525 /** Computes the average of a sequence of angles in radians taking into account
526  * the correct wrapping in the range \f$ ]-\pi,\pi [ \f$, for example, the mean
527  * of (2,-2) is \f$ \pi \f$, not 0.
528  * \ingroup stats_grp
529  */
530 double averageWrap2Pi(const CVectorDouble& angles);
531 
532 /** A numerically-stable method to average likelihood values with strongly
533  * different ranges (weighted likelihoods).
534  * This method implements this equation:
535  *
536  * \f[ return = \log \left( \frac{1}{\sum_i e^{lw_i}} \sum_i e^{lw_i}
537  * e^{ll_i} \right) \f]
538  *
539  * See also the <a
540  * href="http://www.mrpt.org/Averaging_Log-Likelihood_Values:Numerical_Stability">tutorial
541  * page</a>.
542  * \ingroup stats_grp
543  */
544 double averageLogLikelihood(
545  const CVectorDouble& logWeights, const CVectorDouble& logLikelihoods);
546 
547 /** @} */ // end of grouping container_ops_grp
548 
549 } // End of MATH namespace
550 } // End of namespace
551 
552 #endif
void mahalanobisDistance2AndPDF(const VECLIKE &diff_mean, const MATRIXLIKE &cov, T &maha2_out, T &pdf_out)
Computes both, the PDF and the square Mahalanobis distance between a point (given by its difference w...
Definition: data_utils.h:235
double averageWrap2Pi(const CVectorDouble &angles)
Computes the average of a sequence of angles in radians taking into account the correct wrapping in t...
Definition: math.cpp:1799
const GLbyte * weights
Definition: glext.h:4450
GLdouble GLdouble z
Definition: glext.h:3872
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:3582
size_t size(const MATRIXLIKE &m, const int dim)
Definition: bits.h:41
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
MAT_C::Scalar multiply_HCHt_scalar(const VECTOR_H &H, const MAT_C &C)
r (a scalar) = H * C * H^t (with a vector H and a symmetric matrix C)
Definition: ops_matrices.h:69
#define M_PI
Definition: bits.h:92
const Scalar * const_iterator
Definition: eigen_plugins.h:27
void productIntegralAndMahalanobisTwoGaussians(const VECLIKE &mean_diffs, const MATLIKE1 &COV1, const MATLIKE2 &COV2, T &maha2_out, T &intprod_out, const MATLIKE1 *CROSS_COV12=nullptr)
Computes both, the integral of the product of two Gaussians and their square Mahalanobis distance...
Definition: data_utils.h:183
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
#define M_2PI
Definition: mrpt_macros.h:437
CONTAINER::Scalar minimum(const CONTAINER &v)
A numeric matrix of compile-time fixed size.
void mahalanobisDistance2AndLogPDF(const VECLIKE &diff_mean, const MATRIXLIKE &cov, T &maha2_out, T &log_pdf_out)
Computes both, the logarithm of the PDF and the square Mahalanobis distance between a point (given by...
Definition: data_utils.h:212
#define MRPT_END
void covariancesAndMean(const VECTOR_OF_VECTORS &elements, MATRIXLIKE &covariances, VECTORLIKE &means, const bool *elem_do_wrap2pi=nullptr)
Computes covariances and mean of any vector of containers.
Definition: data_utils.h:386
double averageLogLikelihood(const CVectorDouble &logLikelihoods)
A numerically-stable method to compute average likelihood values with strongly different ranges (unwe...
Definition: math.cpp:1777
CONTAINER::Scalar maximum(const CONTAINER &v)
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
Definition: wrap2pi.h:53
MAT::Scalar mahalanobisDistance2(const VECTORLIKE1 &X, const VECTORLIKE2 &MU, const MAT &COV)
Computes the squared mahalanobis distance of a vector X given the mean MU and the covariance inverse ...
Definition: data_utils.h:36
void weightedHistogram(const VECTORLIKE1 &values, const VECTORLIKE1 &weights, float binWidth, VECTORLIKE2 &out_binCenters, VECTORLIKE2 &out_binValues)
Computes the weighted histogram for a vector of values and their corresponding weights.
Definition: data_utils.h:408
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
void covariancesAndMeanWeighted(const VECTOR_OF_VECTORS &elements, MATRIXLIKE &covariances, VECTORLIKE &means, const VECTORLIKE2 *weights_mean, const VECTORLIKE3 *weights_cov, const bool *elem_do_wrap2pi=nullptr)
Computes covariances and mean of any vector of containers, given optional weights for the different s...
Definition: data_utils.h:263
VECTORLIKE1::Scalar mahalanobisDistance(const VECTORLIKE1 &X, const VECTORLIKE2 &MU, const MAT &COV)
Computes the mahalanobis distance of a vector X given the mean MU and the covariance inverse COV_inv ...
Definition: data_utils.h:59
T productIntegralTwoGaussians(const std::vector< T > &mean_diffs, const CMatrixTemplateNumeric< T > &COV1, const CMatrixTemplateNumeric< T > &COV2)
Computes the integral of the product of two Gaussians, with means separated by "mean_diffs" and covar...
Definition: data_utils.h:138
#define ASSERT_(f)
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:25
CONTAINER::value_type element_t
Definition: math_frwds.h:103
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:148
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:44
void weightedHistogramLog(const VECTORLIKE1 &values, const VECTORLIKE1 &log_weights, float binWidth, VECTORLIKE2 &out_binCenters, VECTORLIKE2 &out_binValues)
Computes the weighted histogram for a vector of values and their corresponding log-weights.
Definition: data_utils.h:465
#define ASSERTMSG_(f, __ERROR_MSG)
double Scalar
Definition: KmUtils.h:44



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019