SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Statistics.hh
Go to the documentation of this file.
1 #ifndef STATISTICS_HH
2 #define STATISTICS_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <vector>
7 #include <string>
8 #include <map>
9 #include <ctime>
10 #include <algorithm>
11 
12 // ROOT includes
13 #include "TMath.h"
14 #include "TF1.h"
15 #include "TRobustEstimator.h"
16 
17 // Other includes
18 #include "Assert.hh"
19 #include "Matrix.hh"
20 
28 namespace Math {
29 
36 double Mean(const std::vector<double>& vx);
37 
45 double MeanError(const std::vector<double>& vx,
46  const std::vector<double>& vex=std::vector<double>());
47 
54 double MeanMError(const std::vector<double>& vex);
55 
62 double MeanSError(const std::vector<double>& vx);
63 
70 double RobustMean(const std::vector<double>& vx);
71 
78 void DecrementMean(const size_t& n,
79  double& mean,
80  const double& x);
81 
88 void IncrementMean(const size_t& n,
89  double& mean,
90  const double& x);
91 
99 double TMean(const std::vector<double>& vx,
100  const double& frac);
101 
109 double TMeanSError(const std::vector<double>& vx,
110  const double& frac);
111 
119 double WMean(const std::vector<double>& vx,
120  const double& frac);
121 
128 double Variance(const std::vector<double>& vx);
129 
137 double VarianceError(const std::vector<double>& vx,
138  const std::vector<double>& vex=std::vector<double>());
139 
147 double VarianceMError(const std::vector<double>& vx,
148  const std::vector<double>& vex=std::vector<double>());
149 
156 double VarianceSError(const std::vector<double>& vx);
157 
164 double RMS(const std::vector<double>& vx);
165 
173 double RMSError(const std::vector<double>& vx,
174  const std::vector<double>& vex=std::vector<double>());
175 
183 double RMSMError(const std::vector<double>& vx,
184  const std::vector<double>& vex);
185 
192 double RMSSError(const std::vector<double>& vx);
193 
201 double WRMS(const std::vector<double>& vx,
202  const double& frac);
203 
211 double Covariance(const std::vector<double>& vx,
212  const std::vector<double>& vy);
213 
223 double CovarianceError(const std::vector<double>& vx,
224  const std::vector<double>& vy,
225  const std::vector<double>& vex=std::vector<double>(),
226  const std::vector<double>& vey=std::vector<double>());
227 
237 double CovarianceMError(const std::vector<double>& vx,
238  const std::vector<double>& vy,
239  const std::vector<double>& vex,
240  const std::vector<double>& vey);
241 
249 double CovarianceSError(const std::vector<double>& vx,
250  const std::vector<double>& vy);
251 
261 void IncrementCovariance(const size_t& n,
262  double& cov,
263  const double& xmean,
264  const double& ymean,
265  const double& x,
266  const double& y);
267 
277 void DecrementCovariance(const size_t& n,
278  double& cov,
279  const double& xmean,
280  const double& ymean,
281  const double& x,
282  const double& y);
283 
291 
300  const double hh=0);
301 
309 void DecrementCovarianceMatrix(const size_t& n,
310  Matrix<double>& covmat,
311  const std::vector<double>& means,
312  const std::vector<double>& v);
313 
321 void IncrementCovarianceMatrix(const size_t& n,
322  Matrix<double>& covmat,
323  const std::vector<double>& means,
324  const std::vector<double>& v);
325 
333 double DeterminantError(const Matrix<double>& mat,
334  const Matrix<double>& mat_error=Matrix<double>());
335 
343 double DeterminantMError(const Matrix<double>& mat,
344  const Matrix<double>& mat_error);
345 
352 double DeterminantSError(const Matrix<double>& mat);
353 
360 double Median(const std::vector<double>& vx);
361 
369 double MedianSError(const size_t n,
370  const double& density);
371 
379 double LWidth(const std::vector<double>& vx,
380  const double& p);
381 
389 double Quantile(const std::vector<double>& vx,
390  const double& alpha);
391 
400 double QuantileSError(const size_t n,
401  const double& alpha,
402  const double& density);
403 
410 double Mode(const std::vector<double>& vx);
411 
418 double Min(const std::vector<double>& vx);
419 
426 double Max(const std::vector<double>& vx);
427 
435 double Mahalanobis(const Matrix<double>& invcov,
436  const Matrix<double>& vec);
437 
445 double MahalanobisSquared(const Matrix<double>& invcov,
446  const Matrix<double>& vec);
447 
455 double GeneralisedDistance(const double& rhoR,
456  const double& rho0);
457 
465 double GeneralisedDistanceSquared(const double& rhoR,
466  const double& rho0);
467 
474 size_t Factorial(const size_t n);
475 
481 template<typename T> void Trim(std::vector<T>& vx,
482  const double& frac);
483 
491 template<typename T> std::vector<T> Trimmed(std::vector<T> vx,
492  const double& frac);
493 
499 template<typename T> void Winsorize(std::vector<T>& vx,
500  const double& frac);
501 
509 template<typename T> std::vector<T> Winsorized(std::vector<T> vx,
510  const double& frac);
511 
519 template<typename I> I RandomElement(I begin,
520  I end);
521 
530 template<typename T> std::vector<T> Resample(const std::vector<T>& vx,
531  size_t m=0,
532  const bool rep=true);
533 
534 #include "Statistics-inl.hh"
535 
536 } // namespace Math
537 
538 #endif
double Quantile(const std::vector< double > &vx, const double &alpha)
Computes the quantile of a variable sample at probability alpha.
Definition: Statistics.cc:437
double MeanMError(const std::vector< double > &vex)
Computes the measurement error on the mean of a variable sample.
Definition: Statistics.cc:27
double Median(const std::vector< double > &vx)
Computes the median of a variable sample.
Definition: Statistics.cc:404
double DeterminantError(const Matrix< double > &mat, const Matrix< double > &mat_error)
Returns the exact error on the determinant of the covariance matrix.
Definition: Statistics.cc:341
double TMeanSError(const std::vector< double > &vx, const double &frac)
Computes the statistical error on the trimmed mean of a variable sample.
Definition: Statistics.cc:60
double QuantileSError(const size_t n, const double &alpha, const double &density)
Computes the statistical error on the quantile of a variable sample at probability alpha...
Definition: Statistics.cc:452
double GeneralisedDistance(const double &rhoR, const double &rho0)
Returns the generalised distance of a point to a distribution.
Definition: Statistics.cc:536
I RandomElement(I begin, I end)
Randomly select a single element from an array.
Definition: Statistics.hh:84
void DecrementCovariance(const size_t &n, double &cov, const double &xmean, const double &ymean, const double &x, const double &y)
Removes an pair of elements from a precomputed covariance.
Definition: Statistics.cc:236
std::vector< T > Resample(const std::vector< T > &vx, size_t m=0, const bool rep=true)
Randomly resample n data points into m data points with or without replacement.
Definition: Statistics.hh:96
double WMean(const std::vector< double > &vx, const double &frac)
Computes the winsorized mean of a variable sample.
Definition: Statistics.cc:67
double LWidth(const std::vector< double > &vx, const double &p)
Computes the Lebesgues width for a given metric (RMS = L2)
Definition: Statistics.cc:423
void Trim(std::vector< T > &vx, const double &frac)
Trim the n% lowest and n% largest values.
Definition: Statistics.hh:2
double Mode(const std::vector< double > &vx)
Computes the most probable value of the variable sample.
Definition: Statistics.cc:460
double RMSError(const std::vector< double > &vx, const std::vector< double > &vex)
Computes the error on the standard deviation of a variable sample.
Definition: Statistics.cc:145
double Max(const std::vector< double > &vx)
Returns the maximum value in the array.
Definition: Statistics.cc:503
double DeterminantSError(const Matrix< double > &mat)
Returns the statistical error on the determinant of the covariance matrix.
Definition: Statistics.cc:394
Matrix< double > RobustCovarianceMatrix(const Matrix< double > &mat, const double hh)
Returns the MCD robust covariance matrix of a multivariate sample.
Definition: Statistics.cc:281
double CovarianceMError(const std::vector< double > &vx, const std::vector< double > &vy, const std::vector< double > &vex, const std::vector< double > &vey)
Computes the measurement error on the covariance of two variable samples.
Definition: Statistics.cc:206
double Mean(const std::vector< double > &vx)
Computes the mean of a variable sample.
Definition: Statistics.cc:5
double Covariance(const std::vector< double > &vx, const std::vector< double > &vy)
Computes the covariance of two variable samples.
Definition: Statistics.cc:176
double Min(const std::vector< double > &vx)
Returns the minimum value in the array.
Definition: Statistics.cc:492
double VarianceMError(const std::vector< double > &vx, const std::vector< double > &vex)
Computes the measurement error on the variance of a variable sample.
Definition: Statistics.cc:117
double CovarianceSError(const std::vector< double > &vx, const std::vector< double > &vy)
Computes the statistical error on the covariance of two variable samples.
Definition: Statistics.cc:228
std::vector< T > Trimmed(std::vector< T > vx, const double &frac)
Trim the n% lowest and n% largest values.
Definition: Statistics.hh:35
double CovarianceError(const std::vector< double > &vx, const std::vector< double > &vy, const std::vector< double > &vex, const std::vector< double > &vey)
Computes the error on the covariance of two variable samples.
Definition: Statistics.cc:191
double RMSSError(const std::vector< double > &vx)
Computes the statistical error on the standard deviation of a variable sample.
Definition: Statistics.cc:163
void IncrementMean(const size_t &n, double &mean, const double &x)
Adds an element to a precomputed mean.
Definition: Statistics.cc:86
std::vector< T > Winsorized(std::vector< T > vx, const double &frac)
Winsorize to keep only a fraction frac of the original sample.
Definition: Statistics.hh:77
double WRMS(const std::vector< double > &vx, const double &frac)
Computes the winsorized standard deviation of a variable sample.
Definition: Statistics.cc:169
double VarianceSError(const std::vector< double > &vx)
Computes the statistical error on the variance of a variable sample.
Definition: Statistics.cc:133
void Winsorize(std::vector< T > &vx, const double &frac)
Winsorize to keep only a fraction frac of the original sample.
Definition: Statistics.hh:42
double RobustMean(const std::vector< double > &vx)
Computes the MCD robust mean of a variable sample.
Definition: Statistics.cc:44
void IncrementCovarianceMatrix(const size_t &n, Matrix< double > &covmat, const std::vector< double > &means, const std::vector< double > &v)
Adds an element array to a precomputed covariance matrix.
Definition: Statistics.cc:325
double MeanError(const std::vector< double > &vx, const std::vector< double > &vex)
Computes the error on the mean of a variable sample.
Definition: Statistics.cc:16
Matrix< double > CovarianceMatrix(const Matrix< double > &mat)
Returns the covariance matrix of a multivariate sample.
Definition: Statistics.cc:265
double MedianSError(const size_t n, const double &density)
Computes the statistical error on the median of a variable sample.
Definition: Statistics.cc:417
double DeterminantMError(const Matrix< double > &mat, const Matrix< double > &mat_error)
Returns the measurement error on the determinant of the covariance matrix.
Definition: Statistics.cc:354
double Mahalanobis(const Matrix< double > &invcov, const Matrix< double > &vec)
Returns the Mahalanobis distance of a point to a distribution.
Definition: Statistics.cc:514
double MeanSError(const std::vector< double > &vx)
Computes the statistical error on the mean of a variable sample.
Definition: Statistics.cc:38
double GeneralisedDistanceSquared(const double &rhoR, const double &rho0)
Returns the squared generalised distance of a point to a distribution.
Definition: Statistics.cc:542
double MahalanobisSquared(const Matrix< double > &invcov, const Matrix< double > &vec)
Returns the squared Mahalanobis distance of a point to a distribution.
Definition: Statistics.cc:519
void IncrementCovariance(const size_t &n, double &cov, const double &xmean, const double &ymean, const double &x, const double &y)
Adds an pair of elements from a precomputed covariance.
Definition: Statistics.cc:251
double TMean(const std::vector< double > &vx, const double &frac)
Computes the trimmed mean of a variable sample.
Definition: Statistics.cc:53
double Variance(const std::vector< double > &vx)
Computes the variance of a variable sample.
Definition: Statistics.cc:93
void DecrementMean(const size_t &n, double &mean, const double &x)
Removes an element from a precomputed mean.
Definition: Statistics.cc:74
double RMS(const std::vector< double > &vx)
Computes the standard deviation of a variable sample.
Definition: Statistics.cc:139
double VarianceError(const std::vector< double > &vx, const std::vector< double > &vex)
Computes the error on the variance of a variable sample.
Definition: Statistics.cc:106
size_t Factorial(const size_t n)
Returns the factorial of the provided integer.
Definition: Statistics.cc:549
double RMSMError(const std::vector< double > &vx, const std::vector< double > &vex)
Computes the measurement error on the standard deviation of a variable sample.
Definition: Statistics.cc:156
void DecrementCovarianceMatrix(const size_t &n, Matrix< double > &covmat, const std::vector< double > &means, const std::vector< double > &v)
Removes an element array from a precomputed covariance matrix.
Definition: Statistics.cc:307