38 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
40 const VECTORLIKE1&
x,
const VECTORLIKE2& mu,
const MATRIXLIKE& cov_inv,
41 const bool scaled_pdf =
false)
47 size_t(cov_inv.cols()) ==
size_t(
x.size()) &&
48 size_t(cov_inv.cols()) ==
size_t(mu.size()));
50 static_cast<T>(-0.5) *
55 cov_inv.det() / ::pow(
56 static_cast<T>(
M_2PI),
57 static_cast<T>(cov_inv.rows())));
70 template <
class VECTORLIKE1,
class VECTORLIKE2,
class MATRIXLIKE>
72 const VECTORLIKE1&
x,
const VECTORLIKE2& mu,
const MATRIXLIKE&
cov,
73 const bool scaled_pdf =
false)
81 template <
typename VECTORLIKE,
typename MATRIXLIKE>
83 const VECTORLIKE& d,
const MATRIXLIKE&
cov)
89 static_cast<typename MATRIXLIKE::Scalar>(-0.5) *
92 static_cast<typename MATRIXLIKE::Scalar>(
M_2PI),
93 static_cast<typename MATRIXLIKE::Scalar>(0.5 *
cov.cols())) *
105 template <
typename VECTORLIKE1,
typename MATRIXLIKE1,
typename VECTORLIKE2,
106 typename MATRIXLIKE2>
108 const VECTORLIKE1& mu0,
const MATRIXLIKE1& cov0,
const VECTORLIKE2& mu1,
109 const MATRIXLIKE2& cov1)
113 size_t(mu0.size()) ==
size_t(mu1.size()) &&
114 size_t(mu0.size()) ==
size_t(cov0.rows()) &&
115 size_t(mu0.size()) ==
size_t(cov1.cols()) && cov0.isSquare() &&
117 const size_t N = mu0.size();
118 MATRIXLIKE2 cov1_inv;
120 const VECTORLIKE1 mu_difs = mu0 - mu1;
121 return 0.5 * (log(cov1.det() / cov0.det()) + (cov1_inv * cov0).trace() +
147 double chi2inv(
double P,
unsigned int dim = 1);
170 unsigned int degreesOfFreedom,
double noncentrality,
double arg);
185 double chi2CDF(
unsigned int degreesOfFreedom,
double arg);
198 unsigned int degreesOfFreedom,
double arg,
double accuracy = 1e-7);
205 unsigned int degreesOfFreedom,
double noncentrality,
double arg,
215 template <
typename CONTAINER>
217 const CONTAINER&
data,
220 out_lower_conf_interval,
222 out_upper_conf_interval,
223 const double confidenceInterval = 0.1,
const size_t histogramNumBins = 1000)
228 ASSERT_(confidenceInterval > 0 && confidenceInterval < 1);
235 (x_max - x_min) / histogramNumBins;
237 const std::vector<double> H =
239 std::vector<double> Hc;
244 std::lower_bound(Hc.begin(), Hc.end(), confidenceInterval);
247 std::upper_bound(Hc.begin(), Hc.end(), 1 - confidenceInterval);
251 out_lower_conf_interval = x_min + idx_low * binWidth;
252 out_upper_conf_interval = x_min + idx_high * binWidth;
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].
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
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...
double chi2PDF(unsigned int degreesOfFreedom, double arg, double accuracy=1e-7)
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)
double chi2CDF(unsigned int degreesOfFreedom, double arg)
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...
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
typename CONTAINER::value_type element_t
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.
double noncentralChi2CDF(unsigned int degreesOfFreedom, double noncentrality, double arg)
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 distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.