35 #ifndef mrpt_math_distributions_H 36 #define mrpt_math_distributions_H 67 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
68 inline typename MATRIXLIKE::Scalar
70 const VECTORLIKE1 & x,
71 const VECTORLIKE2 & mu,
72 const MATRIXLIKE & cov_inv,
73 const bool scaled_pdf =
false )
76 typedef typename MATRIXLIKE::Scalar T;
78 ASSERTDEB_(
size_t(cov_inv.getColCount())==
size_t(x.size()) &&
size_t(cov_inv.getColCount())==
size_t(mu.size()))
80 return scaled_pdf ? ret : ret * ::sqrt(cov_inv.det() / ::pow(static_cast<T>(
M_2PI),static_cast<T>(
size(cov_inv,1) )) );
90 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
91 inline typename MATRIXLIKE::Scalar
93 const VECTORLIKE1 & x,
94 const VECTORLIKE2 & mu,
95 const MATRIXLIKE &
cov,
96 const bool scaled_pdf =
false )
103 template <
typename VECTORLIKE,
typename MATRIXLIKE>
104 typename MATRIXLIKE::Scalar
112 static_cast<typename MATRIXLIKE::Scalar>(
M_2PI),
113 static_cast<typename MATRIXLIKE::Scalar>(0.5*
cov.getColCount()))
114 * ::sqrt(
cov.det()));
122 template <
typename VECTORLIKE1,
typename MATRIXLIKE1,
typename VECTORLIKE2,
typename MATRIXLIKE2>
124 const VECTORLIKE1 &mu0,
const MATRIXLIKE1 &cov0,
125 const VECTORLIKE2 &mu1,
const MATRIXLIKE2 &cov1)
128 ASSERT_(
size_t(mu0.size())==
size_t(mu1.size()) &&
size_t(mu0.size())==
size_t(
size(cov0,1)) &&
size_t(mu0.size())==
size_t(
size(cov1,1)) && cov0.isSquare() && cov1.isSquare() )
129 const size_t N = mu0.size();
130 MATRIXLIKE2 cov1_inv;
132 const VECTORLIKE1 mu_difs = mu0-mu1;
133 return 0.5*( log(cov1.det()/cov0.det()) + (cov1_inv*cov0).trace() +
multiply_HCHt_scalar(mu_difs,cov1_inv) - N );
199 double BASE_IMPEXP chi2PDF(
unsigned int degreesOfFreedom,
double arg,
double accuracy = 1e-7);
210 template <
typename CONTAINER>
212 const CONTAINER &data,
213 typename CONTAINER::value_type &out_mean,
214 typename CONTAINER::value_type &out_lower_conf_interval,
215 typename CONTAINER::value_type &out_upper_conf_interval,
216 const double confidenceInterval = 0.1,
217 const size_t histogramNumBins = 1000 )
221 ASSERT_(confidenceInterval>0 && confidenceInterval<1)
223 out_mean =
mean(data);
224 typename CONTAINER::value_type x_min,x_max;
227 const typename CONTAINER::value_type binWidth = (x_max-x_min)/histogramNumBins;
232 Hc*=1.0/Hc.maximum();
238 out_lower_conf_interval = x_min + idx_low * binWidth;
239 out_upper_conf_interval = x_min + idx_high * binWidth;
double BASE_IMPEXP erfc(const double x)
The complementary error function of a Normal distribution.
double BASE_IMPEXP normalQuantile(double p)
Evaluates the Gaussian distribution quantile for the probability value p=[0,1].
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double BASE_IMPEXP normalCDF(double p)
Evaluates the Gaussian cumulative density function.
double BASE_IMPEXP normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
This file implements miscelaneous matrix and matrix/vector operations, plus internal functions in mrp...
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)
double BASE_IMPEXP noncentralChi2CDF(unsigned int degreesOfFreedom, double noncentrality, double arg)
double KLD_Gaussians(const VECTORLIKE1 &mu0, const MATRIXLIKE1 &cov0, const VECTORLIKE2 &mu1, const MATRIXLIKE2 &cov1)
Kullback-Leibler divergence (KLD) between two independent multivariate Gaussians. ...
std::pair< double, double > BASE_IMPEXP noncentralChi2PDF_CDF(unsigned int degreesOfFreedom, double noncentrality, double arg, double eps=1e-7)
Returns the 'exact' PDF (first) and CDF (second) of a Non-central chi-squared probability distributio...
vector_double histogram(const CONTAINER &v, double limit_min, double limit_max, size_t number_bins, bool do_normalization=false, vector_double *out_bin_centers=NULL)
Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the...
double BASE_IMPEXP chi2CDF(unsigned int degreesOfFreedom, double arg)
The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...
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 minimum_maximum(const std::vector< T > &V, T &curMin, T &curMax)
Return the maximum and minimum values of a std::vector.
MATRIXLIKE::Scalar normalPDFInf(const VECTORLIKE1 &x, const VECTORLIKE2 &mu, const MATRIXLIKE &cov_inv, const bool scaled_pdf=false)
Evaluates the multivariate normal (Gaussian) distribution at a given point "x".
void cumsum(const CONTAINER1 &in_data, CONTAINER2 &out_cumsum)
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.
double BASE_IMPEXP chi2inv(double P, unsigned int dim=1)
The "quantile" of the Chi-Square distribution, for dimension "dim" and probability 0<P<1 (the inverse...
size_t size(const MATRIXLIKE &m, int dim)
void confidenceIntervals(const CONTAINER &data, typename CONTAINER::value_type &out_mean, typename CONTAINER::value_type &out_lower_conf_interval, typename CONTAINER::value_type &out_upper_conf_interval, const double confidenceInterval=0.1, const size_t histogramNumBins=1000)
Return the mean and the 10%-90% confidence points (or with any other confidence value) of a set of sa...
double BASE_IMPEXP chi2PDF(unsigned int degreesOfFreedom, double arg, double accuracy=1e-7)
double mean(const CONTAINER &v)
Computes the mean value of a vector.
double BASE_IMPEXP erf(const double x)
The error function of a Normal distribution.
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.