walberla::math::Sample Class Reference

Detailed Description

Class describing a statistical sample.

#include <Sample.h>

+ Inheritance diagram for walberla::math::Sample:

Public Member Functions

void merge (const Sample &other)
 
template<typename T >
iterator castToRealAndInsert (const T &val)
 
template<typename T >
iterator castToRealAndInsert (const_iterator position, const T &val)
 
template<class InputIterator >
void castToRealAndInsert (InputIterator first, InputIterator last)
 
void mpiAllGather ()
 Combines the samples from all processes and stores the result on each process. More...
 
void mpiGather (int rank)
 Combines the samples from all processes and stores the result on process 'rank'. More...
 
void mpiGatherRoot ()
 Combines the samples from all processes and stores the result on the root process. More...
 
real_t sum () const
 
real_t min () const
 
real_t max () const
 
real_t range () const
 
real_t mean () const
 
real_t median () const
 Calculates the median of the sample. More...
 
real_t variance () const
 
real_t stdDeviation () const
 
real_t relativeStdDeviation () const
 Calculates the relative standard deviation of the sample. More...
 
real_t mad () const
 Calculates the median absolute deviation (MAD) of the sample. More...
 
real_t giniCoefficient () const
 Calculates the Gini coefficient of the sample. More...
 
real_t cummulativeDistributionFunction (const real_t x) const
 
real_t quantile (const real_t p) const
 Calculates a quantile of the sample. More...
 
std::string format (const std::string &formatString=DEFAULT_FORMAT_STRING) const
 Generates a string with attributes of the sample. More...
 

Private Member Functions

real_t variance (real_t mean) const
 Calculates the variance of the sample. More...
 

Static Private Attributes

static const std::string DEFAULT_FORMAT_STRING
 

Member Function Documentation

◆ castToRealAndInsert() [1/3]

template<typename T >
Sample::iterator walberla::math::Sample::castToRealAndInsert ( const T &  val)

◆ castToRealAndInsert() [2/3]

template<typename T >
Sample::iterator walberla::math::Sample::castToRealAndInsert ( const_iterator  position,
const T &  val 
)

◆ castToRealAndInsert() [3/3]

template<class InputIterator >
void walberla::math::Sample::castToRealAndInsert ( InputIterator  first,
InputIterator  last 
)

◆ cummulativeDistributionFunction()

real_t walberla::math::Sample::cummulativeDistributionFunction ( const real_t  x) const
inline

◆ format()

std::string walberla::math::Sample::format ( const std::string &  formatString = DEFAULT_FORMAT_STRING) const

Generates a string with attributes of the sample.

The following patters are replaced in the format string:

min by min() max by max() sum by sum() mean by mean() med by median() var by variance() stddev by stdDeviation() relstddev by relativeStdDeviation() mad by mad() size by size()

Returns
The formatted string.

◆ giniCoefficient()

real_t walberla::math::Sample::giniCoefficient ( ) const

Calculates the Gini coefficient of the sample.

http://en.wikipedia.org/w/index.php?title=Gini_coefficient&oldid=608263369

Precondition
size() > 1
mean() > 0
Returns
Gini coefficient.

◆ mad()

real_t walberla::math::Sample::mad ( ) const

Calculates the median absolute deviation (MAD) of the sample.

MAD is a robust alternative to the standard deviation.

See http://en.wikipedia.org/w/index.php?title=Median_absolute_deviation&oldid=608254065

Returns
The MAD.

◆ max()

real_t walberla::math::Sample::max ( ) const
inline

◆ mean()

real_t walberla::math::Sample::mean ( ) const
inline

◆ median()

real_t walberla::math::Sample::median ( ) const

Calculates the median of the sample.

In case of size() being an even number, the average of the two central elements is returned.

Returns
The median.

◆ merge()

void walberla::math::Sample::merge ( const Sample other)
inline

◆ min()

real_t walberla::math::Sample::min ( ) const
inline

◆ mpiAllGather()

void walberla::math::Sample::mpiAllGather ( )

Combines the samples from all processes and stores the result on each process.

Note that this is a collective MPI operation. It has to be called by all processes!

◆ mpiGather()

void walberla::math::Sample::mpiGather ( int  rank)

Combines the samples from all processes and stores the result on process 'rank'.

Note that this is a collective MPI operation. It has to be called by all processes!

Parameters
rankThe rank of the process the combined sample is stored on.

◆ mpiGatherRoot()

void walberla::math::Sample::mpiGatherRoot ( )

Combines the samples from all processes and stores the result on the root process.

Note that this is a collective MPI operation. It has to be called by all processes!

◆ quantile()

real_t walberla::math::Sample::quantile ( const real_t  p) const

Calculates a quantile of the sample.

To understand how the quantiles are calculated please see http://tinyurl.com/d8vm37f. Quantiles are rounded outwards.

Returns
The quantile.

◆ range()

real_t walberla::math::Sample::range ( ) const
inline

◆ relativeStdDeviation()

real_t walberla::math::Sample::relativeStdDeviation ( ) const

Calculates the relative standard deviation of the sample.

Equals stdDeviation / mean()

Returns
The standard deviation of the sample.

◆ stdDeviation()

real_t walberla::math::Sample::stdDeviation ( ) const
inline

◆ sum()

real_t walberla::math::Sample::sum ( ) const
inline

◆ variance() [1/2]

real_t walberla::math::Sample::variance ( ) const
inline

◆ variance() [2/2]

real_t walberla::math::Sample::variance ( real_t  theMean) const
private

Calculates the variance of the sample.

The variance calculated here is the uncorrected variance. See: http://en.wikipedia.org/w/index.php?title=Bessel%27s_correction&oldid=526066331

Parameters
theMeanthe mean()
Returns
The uncorrected variance.

Member Data Documentation

◆ DEFAULT_FORMAT_STRING

const std::string walberla::math::Sample::DEFAULT_FORMAT_STRING
staticprivate
Initial value:
= "Sample has %size values in [%min, %max], "
"sum = %sum, mean = %mean, med = %med, "
"stddev = %stddev (relative: %relstddev), mad = %mad"

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