9 #ifndef mrpt_math_distributions_H 10 #define mrpt_math_distributions_H 40 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
43 const VECTORLIKE1 &
x,
44 const VECTORLIKE2 & mu,
45 const MATRIXLIKE & cov_inv,
46 const bool scaled_pdf =
false )
51 ASSERTDEB_(
size_t(cov_inv.getColCount())==
size_t(
x.size()) &&
size_t(cov_inv.getColCount())==
size_t(mu.size()))
53 return scaled_pdf ? ret : ret * ::sqrt(cov_inv.det() / ::pow(static_cast<T>(
M_2PI),static_cast<T>(
size(cov_inv,1) )) );
63 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
66 const VECTORLIKE1 &
x,
67 const VECTORLIKE2 & mu,
68 const MATRIXLIKE &
cov,
69 const bool scaled_pdf =
false )
76 template <
typename VECTORLIKE,
typename MATRIXLIKE>
85 static_cast<typename MATRIXLIKE::Scalar>(
M_2PI),
86 static_cast<typename MATRIXLIKE::Scalar>(0.5*
cov.getColCount()))
95 template <
typename VECTORLIKE1,
typename MATRIXLIKE1,
typename VECTORLIKE2,
typename MATRIXLIKE2>
97 const VECTORLIKE1 &mu0,
const MATRIXLIKE1 &cov0,
98 const VECTORLIKE2 &mu1,
const MATRIXLIKE2 &cov1)
101 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() )
102 const size_t N = mu0.size();
103 MATRIXLIKE2 cov1_inv;
105 const VECTORLIKE1 mu_difs = mu0-mu1;
106 return 0.5*( log(cov1.det()/cov0.det()) + (cov1_inv*cov0).trace() +
multiply_HCHt_scalar(mu_difs,cov1_inv) - N );
172 double BASE_IMPEXP chi2PDF(
unsigned int degreesOfFreedom,
double arg,
double accuracy = 1e-7);
183 template <
typename CONTAINER>
185 const CONTAINER &
data,
189 const double confidenceInterval = 0.1,
190 const size_t histogramNumBins = 1000 )
194 ASSERT_(confidenceInterval>0 && confidenceInterval<1)
203 std::vector<double> Hc;
211 out_lower_conf_interval = x_min + idx_low * binWidth;
212 out_upper_conf_interval = x_min + idx_high * binWidth;
double BASE_IMPEXP chi2CDF(unsigned int degreesOfFreedom, double arg)
size_t size(const MATRIXLIKE &m, const int dim)
double BASE_IMPEXP normalCDF(double p)
Evaluates the Gaussian cumulative density function.
std::vector< double > histogram(const CONTAINER &v, double limit_min, double limit_max, size_t number_bins, bool do_normalization=false, std::vector< double > *out_bin_centers=NULL)
Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the...
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)
double KLD_Gaussians(const VECTORLIKE1 &mu0, const MATRIXLIKE1 &cov0, const VECTORLIKE2 &mu1, const MATRIXLIKE2 &cov1)
Kullback-Leibler divergence (KLD) between two independent multivariate Gaussians. ...
double BASE_IMPEXP normalQuantile(double p)
Evaluates the Gaussian distribution quantile for the probability value p=[0,1].
double BASE_IMPEXP erfc(const double x)
The complementary error function of a Normal distribution.
double BASE_IMPEXP erf(const double x)
The error function of a Normal distribution.
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...
CONTAINER::Scalar maximum(const CONTAINER &v)
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...
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...
double mean(const CONTAINER &v)
Computes the mean value of a vector.
CONTAINER::value_type element_t
void confidenceIntervals(const CONTAINER &data, typename mrpt::math::ContainerType< CONTAINER >::element_t &out_mean, typename mrpt::math::ContainerType< CONTAINER >::element_t &out_lower_conf_interval, typename mrpt::math::ContainerType< CONTAINER >::element_t &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 normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
GLsizei GLsizei GLenum GLenum const GLvoid * data
double BASE_IMPEXP chi2PDF(unsigned int degreesOfFreedom, double arg, double accuracy=1e-7)
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
double BASE_IMPEXP noncentralChi2CDF(unsigned int degreesOfFreedom, double noncentrality, double arg)