Helios++
Helios software for LiDAR simulations
SurfaceInspector::maths::Statistics Class Reference

Class providing common statistics operations. More...

#include <Statistics.hpp>

Inheritance diagram for SurfaceInspector::maths::Statistics:
Collaboration diagram for SurfaceInspector::maths::Statistics:

Static Public Member Functions

template<typename T >
static T mean (vector< T > const &vals)
 Compute the mean of given values. More...
 
template<typename T >
static T variance (vector< T > const &vals)
 Compute the variance of given values, which requires to previously compute the mean. More...
 
template<typename T >
static T variance (vector< T > const &vals, T const mean)
 Compute the variance of given values, considering provided mean. More...
 
template<typename T >
static T stdev (vector< T > const &vals)
 Compute the standard deviation of given values, which requires to previously compute the variance. More...
 
template<typename T >
static T stdev (vector< T > const &vals, T const mean)
 Compute the standard deviation of given values, considering provided mean. More...
 
template<typename T >
static T stdev (T const variance)
 Compute the standard deviation for given variance. More...
 
template<typename T >
static T covariance (vector< T > const &X, vector< T > const &Y, bool besselCorrection=false)
 Compute the covariance between X and Y. More...
 
template<typename T >
static T covariance (vector< T > const &X, vector< T > const &Y, T xMean, T yMean, bool besselCorrection=false)
 Compute the covariance between X and Y, considering provided means. More...
 
template<typename T >
static arma::Mat< T > covarianceMatrix (vector< vector< T >> dataset, bool besselCorrection=false)
 Compute matrix of covariances. More...
 
template<typename T >
static arma::Mat< T > covarianceMatrix (vector< vector< T >> dataset, vector< T > means, bool besselCorrection=false)
 Compute matrix of covariances. More...
 
template<typename T >
static vector< T > quantiles (arma::Col< T > data, size_t nQuantiles=3)
 Compute quantiles. More...
 
template<typename T >
static vector< T > quantiles (vector< T > const &data, size_t nQuantiles=3)
 Like quantiles(armas::vec, size_t) function but receiving data as a standard vector instead of an armadillo vector. More...
 
template<typename T >
static size_t quantileFiltering (vector< T > &values, size_t nQuantiles=3, double filterFactor=1.5)
 Remove those values which are considered outliers. More...
 
template<typename T >
static bool findTrustableMin (vector< T > const &S, size_t const m, T const tau, T &g, size_t *discardsCount=nullptr)
 Obtain the trustable minimum between all elements in given collection \(S\). More...
 
template<typename T >
static bool findTrustableMax (vector< T > const &S, size_t const m, T const tau, T &g, size_t *discardsCount=nullptr)
 Like findTrustableMin but with maximum value instead of minimum. More...
 

Static Protected Member Functions

template<typename T >
static bool _findTrustable (vector< T > const &S, size_t const m, T const tau, IDragger< double, vector< double >> &drg, T &g, size_t *discardsCount=nullptr)
 Common mechanics for find trustable methods. More...
 

Detailed Description

Class providing common statistics operations.

Author
Alberto M. Esmoris Pena
Version
1.0

Member Function Documentation

◆ _findTrustable()

template<typename T >
static bool SurfaceInspector::maths::Statistics::_findTrustable ( vector< T > const &  S,
size_t const  m,
T const  tau,
IDragger< double, vector< double >> &  drg,
T &  g,
size_t *  discardsCount = nullptr 
)
staticprotected

◆ covariance() [1/2]

template<typename T >
static T SurfaceInspector::maths::Statistics::covariance ( vector< T > const &  X,
vector< T > const &  Y,
bool  besselCorrection = false 
)
static

Compute the covariance between X and Y.

\[ \sigma_{x,y} = \frac{1}{n} \sum_{i=1}^{n}{(x_{i} - \mu_{x})(y_{i} - \mu_{y})} \]

Template Parameters
TType of numerical variable
Parameters
XX values to compute its covariance with respect to Y
YY values to compute its covariance with respect to X
besselCorrectionIf true, then bessel correction will be applied and covariance will be computed considering (n-1) instead of n
Returns
Covariance between X and Y

◆ covariance() [2/2]

template<typename T >
static T SurfaceInspector::maths::Statistics::covariance ( vector< T > const &  X,
vector< T > const &  Y,
xMean,
yMean,
bool  besselCorrection = false 
)
static

Compute the covariance between X and Y, considering provided means.

\[ \sigma_{x,y} = \frac{1}{n} \sum_{i=1}^{n}{(x_{i} - \mu_{x})(y_{i} - \mu_{y})} \]

Template Parameters
TType of numerical variable
Parameters
XX values to compute its covariance with respect to Y
YY values to compute its covariance with respect to X
xMeanMean of X
yMeanMean of Y
besselCorrectionIf true, then bessel correction will be applied and covariance will be computed considering (n-1) instead of n
Returns
Covariance between X and Y

◆ covarianceMatrix() [1/2]

template<typename T >
static arma::Mat<T> SurfaceInspector::maths::Statistics::covarianceMatrix ( vector< vector< T >>  dataset,
bool  besselCorrection = false 
)
static

Compute matrix of covariances.

Template Parameters
TType of numerical variable
Parameters
datasetDataset to generate matrix of covariances from. It must be organized so each row (dataset[row]) contains all values for the same variable. For instance, let D be a dataset such that:

\[ D = \left( \begin{array} .x_{1} & x_{2} & x_{3} & x_{4} & x_{5} \\ y_{1} & y_{2} & y_{3} & y_{4} & y_{5} \\ z_{1} & z_{2} & z_{3} & z_{4} & z_{5} \end{array} \right) \]

So row[0] would contain \(\{x_{1},x_{2},x_{3},x_{4},x_{5}\}\), row[1] would contain \(\{y_{1}, y_{2}, y_{3}, y_{4}, y_{5}\}\) and row[2] would contain \(\{z_{1}, z_{2}, z_{3}, z_{4}, z_{5}\}\)
besselCorrectionIf true, then bessel correction will be applied and covariance will be computed considering (n-1) instead of n
Returns
Covariance matrix

◆ covarianceMatrix() [2/2]

template<typename T >
static arma::Mat<T> SurfaceInspector::maths::Statistics::covarianceMatrix ( vector< vector< T >>  dataset,
vector< T >  means,
bool  besselCorrection = false 
)
static

Compute matrix of covariances.

Template Parameters
TType of numerical variable
Parameters
datasetDataset to generate matrix of covariances from. It must be organized so each row (dataset[row]) contains all values for the same variable. For instance, let D be a dataset such that:

\[ D = \left( \begin{array} .x_{1} & x_{2} & x_{3} & x_{4} & x_{5} \\ y_{1} & y_{2} & y_{3} & y_{4} & y_{5} \\ z_{1} & z_{2} & z_{3} & z_{4} & z_{5} \end{array} \right) \]

So row[0] would contain \(\{x_{1},x_{2},x_{3},x_{4},x_{5}\}\), row[1] would contain \(\{y_{1}, y_{2}, y_{3}, y_{4}, y_{5}\}\) and row[2] would contain \(\{z_{1}, z_{2}, z_{3}, z_{4}, z_{5}\}\)
meansThe mean for each variable so means[i] would contain the mean for all values at row dataset[i]
besselCorrectionIf true, then bessel correction will be applied and covariance will be computed considering (n-1) instead of n
Returns
Covariance matrix

◆ findTrustableMax()

template<typename T >
static bool SurfaceInspector::maths::Statistics::findTrustableMax ( vector< T > const &  S,
size_t const  m,
T const  tau,
T &  g,
size_t *  discardsCount = nullptr 
)
static

Like findTrustableMin but with maximum value instead of minimum.

See also
SurfaceInspector::maths::Statistics::findTrustableMin

◆ findTrustableMin()

template<typename T >
static bool SurfaceInspector::maths::Statistics::findTrustableMin ( vector< T > const &  S,
size_t const  m,
T const  tau,
T &  g,
size_t *  discardsCount = nullptr 
)
static

Obtain the trustable minimum between all elements in given collection \(S\).

Let \(S\) be a collection of elements of the same type.

Now, let \(Z = \left\{z_1, \ldots, z_m \right\}\) be the collection of \(m\) lowest elements in ascending order.

From \(Z\), it is possible to define the collection \(\Delta = \left\{\Delta_1, \ldots, \Delta_{m-1} : \Delta_i = z_{i+1} - z_{i}\right\}\)

For each \(\Delta_i \in \Delta\), if \(\Delta_i > \tau\) then remove \(R=\{z_j : j \leq i\}\) from \(Z\), while adding \(A=\{z_j : i < j \leq i+|R|\}\) (where \(|R|\) is the number of removed elements). This means the updated \(Z\) collection can be defined as \(Z' = Z \setminus R + A = \{z_1', \ldots, z_m'\}\). In consequence, the updated \(\Delta\) collection can be expressed as \(\Delta' = \{\Delta_1', \ldots, \Delta_{m-1}' : \Delta_i' = z_{i+1}' - z_i'\}\).

Aforementioned process must be repeated until \(|\Delta| = m-1\) and \(\forall \Delta_i \in \Delta,\, \Delta_{i} \leq \tau\) (where \(|\Delta|\) is the number of elements in \(\Delta\) collection). Whenever this cannot be satisfied, the trustable minimum is considered to be undefined and \(g=0\) by default. Otherwise, the trustable minimum is defined as \(g=\min(Z)\) where \(Z\) is the collection of trustable lowest elements obtained through previously defined iterative process.

PARTICULAR CASE \(m=1\)

If \(m=1\) then the trustable minimum of the collection will be the minimum of the collection itself. This happens because \(m=1\) implies no checks will be done.

Template Parameters
TNumerical type for \(S\) collection elements
Parameters
[in]SCollection \(S\) of elements implemented as vector
[in]mNumber of \(m\) values involved in trustability analysis
[in]tauDifferential threshold \(\tau\) defining trustability
[out]gMinimum trustable element in \(S\)
[out]discardsCountIf it is a not null pointer, then number of checks leading to a discard is stored here
Returns
True if trustable minimum was found (defined), false otherwise (undefined)
See also
SurfaceInspector::maths::Statistics::findTrustableMax

◆ mean()

template<typename T >
static T SurfaceInspector::maths::Statistics::mean ( vector< T > const &  vals)
static

Compute the mean of given values.

Template Parameters
TType of numerical variable
Parameters
valsValues to compute its mean
Returns
Mean of given values

◆ quantileFiltering()

template<typename T >
static size_t SurfaceInspector::maths::Statistics::quantileFiltering ( vector< T > &  values,
size_t  nQuantiles = 3,
double  filterFactor = 1.5 
)
static

Remove those values which are considered outliers.

Let \(\overline{V}\) be the vector of values, \(k\) be the filtering factor and assume \(\Delta = Q_{n}-Q_{1}\) as the difference between last and first quantile. When 3 quantiles are used, quartiles are used hence \(\Delta = Q_{3} - Q_{1}\) which would be the classical/standard quantile filtering method. Below expression defines when a value from \(\overline{V}\) will also be in filtered vector \(\overline{F}\):

\[ \forall v \in \overline{V} ,\, v \in [Q_{1}-k\Delta, Q_{n}+k\Delta] \Rightarrow v \in \overline{F} \]

Template Parameters
TNumerical type for values vector
Parameters
valuesVector of values to be filtered
filterFactorFactor defining filtering boundaries
Returns
Amount of filtered values

◆ quantiles() [1/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Statistics::quantiles ( arma::Col< T >  data,
size_t  nQuantiles = 3 
)
static

Compute quantiles.

Template Parameters
TType of numerical variable
Parameters
dataVector containing data to generate quantiles from
nQuantilesNumber of quantiles to obtain. For instance, 3 would imply obtaining the 3 quartiles, while 99 would lead to obtain the 99 percentiles
Returns
Vector containing obtained quantiles

◆ quantiles() [2/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Statistics::quantiles ( vector< T > const &  data,
size_t  nQuantiles = 3 
)
static

Like quantiles(armas::vec, size_t) function but receiving data as a standard vector instead of an armadillo vector.

See also
Statistics::quantiles(arma::vec, size_t)

◆ stdev() [1/3]

template<typename T >
static T SurfaceInspector::maths::Statistics::stdev ( T const  variance)
inlinestatic

Compute the standard deviation for given variance.

Template Parameters
TType of numerical variable
Parameters
varianceVariance used to compute standard deviation
Returns
Standard deviation of given variance

◆ stdev() [2/3]

template<typename T >
static T SurfaceInspector::maths::Statistics::stdev ( vector< T > const &  vals)
static

Compute the standard deviation of given values, which requires to previously compute the variance.

Template Parameters
TType of numerical variable
Parameters
valsValues to compute its standard deviation
Returns
Standard deviation of given values

◆ stdev() [3/3]

template<typename T >
static T SurfaceInspector::maths::Statistics::stdev ( vector< T > const &  vals,
T const  mean 
)
static

Compute the standard deviation of given values, considering provided mean.

Template Parameters
TType of numerical variable
Parameters
valsValues to compute its standard deviation
meanMean of values
Returns
Standard deviation of given values

◆ variance() [1/2]

template<typename T >
static T SurfaceInspector::maths::Statistics::variance ( vector< T > const &  vals)
static

Compute the variance of given values, which requires to previously compute the mean.

Template Parameters
TType of numerical variable
Parameters
valsValues to compute its variance
Returns
Variance of given values

◆ variance() [2/2]

template<typename T >
static T SurfaceInspector::maths::Statistics::variance ( vector< T > const &  vals,
T const  mean 
)
static

Compute the variance of given values, considering provided mean.

Template Parameters
TType of numerical variable
Parameters
valsValues to compute its variance
meanMean of values
Returns
Variance of given values

The documentation for this class was generated from the following file: