9 #ifndef mrpt_math_distributions_H 10 #define mrpt_math_distributions_H 45 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
47 const VECTORLIKE1&
x,
const VECTORLIKE2& mu,
const MATRIXLIKE& cov_inv,
48 const bool scaled_pdf =
false)
54 size_t(cov_inv.getColCount()) ==
size_t(
x.size()) &&
55 size_t(cov_inv.getColCount()) ==
size_t(mu.size()))
57 static_cast<T>(-0.5) *
59 return scaled_pdf ? ret : ret * ::sqrt(
62 static_cast<T>(
M_2PI),
63 static_cast<T>(
size(cov_inv, 1))));
76 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
78 const VECTORLIKE1&
x,
const VECTORLIKE2& mu,
const MATRIXLIKE&
cov,
79 const bool scaled_pdf =
false)
87 template <
typename VECTORLIKE,
typename MATRIXLIKE>
89 const VECTORLIKE& d,
const MATRIXLIKE&
cov)
95 static_cast<typename MATRIXLIKE::Scalar>(-0.5) *
98 static_cast<typename MATRIXLIKE::Scalar>(
M_2PI),
99 static_cast<typename MATRIXLIKE::Scalar>(
100 0.5 *
cov.getColCount())) *
112 template <
typename VECTORLIKE1,
typename MATRIXLIKE1,
typename VECTORLIKE2,
113 typename MATRIXLIKE2>
115 const VECTORLIKE1& mu0,
const MATRIXLIKE1& cov0,
const VECTORLIKE2& mu1,
116 const MATRIXLIKE2& cov1)
120 size_t(mu0.size()) ==
size_t(mu1.size()) &&
121 size_t(mu0.size()) ==
size_t(
size(cov0, 1)) &&
122 size_t(mu0.size()) ==
size_t(
size(cov1, 1)) && cov0.isSquare() &&
124 const size_t N = mu0.size();
125 MATRIXLIKE2 cov1_inv;
127 const VECTORLIKE1 mu_difs = mu0 - mu1;
128 return 0.5 * (log(cov1.det() / cov0.det()) + (cov1_inv * cov0).trace() +
154 double chi2inv(
double P,
unsigned int dim = 1);
177 unsigned int degreesOfFreedom,
double noncentrality,
double arg);
192 double chi2CDF(
unsigned int degreesOfFreedom,
double arg);
205 unsigned int degreesOfFreedom,
double arg,
double accuracy = 1e-7);
212 unsigned int degreesOfFreedom,
double noncentrality,
double arg,
222 template <
typename CONTAINER>
224 const CONTAINER&
data,
227 out_lower_conf_interval,
229 out_upper_conf_interval,
230 const double confidenceInterval = 0.1,
const size_t histogramNumBins = 1000)
235 ASSERT_(confidenceInterval > 0 && confidenceInterval < 1)
242 (x_max - x_min) / histogramNumBins;
244 const std::vector<double> H =
246 std::vector<double> Hc;
251 std::lower_bound(Hc.begin(), Hc.end(), confidenceInterval);
254 std::upper_bound(Hc.begin(), Hc.end(), 1 - confidenceInterval);
258 out_lower_conf_interval = x_min + idx_low * binWidth;
259 out_upper_conf_interval = x_min + idx_high * binWidth;
double chi2CDF(unsigned int degreesOfFreedom, double arg)
size_t size(const MATRIXLIKE &m, const int dim)
double normalCDF(double p)
Evaluates the Gaussian cumulative density function.
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 normalQuantile(double p)
Evaluates the Gaussian distribution quantile for the probability value p=[0,1].
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 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 > 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...
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=nullptr)
Computes the normalized or normal histogram of a sequence of numbers given the number of bins and the...
double mean(const CONTAINER &v)
Computes the mean value of a vector.
CONTAINER::value_type element_t
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 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 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 chi2PDF(unsigned int degreesOfFreedom, double arg, double accuracy=1e-7)
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
double noncentralChi2CDF(unsigned int degreesOfFreedom, double noncentrality, double arg)