MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mio::Interpol1D Class Reference

Detailed Description

A class to perform basic 1D statistics. Each method is static.

Author
Mathias Bavay
Date
2009-01-20

#include <libinterpol1D.h>

Static Public Member Functions

static double min_element (const std::vector< double > &X)
 
static double max_element (const std::vector< double > &X)
 
static std::vector< double > quantiles (const std::vector< double > &X, const std::vector< double > &quartiles)
 This function returns a vector of quantiles. The vector does not have to be sorted. See https://secure.wikimedia.org/wikipedia/en/wiki/Quartile for more. This code is heavily inspired by Ken Wilder, https://sites.google.com/site/jivsoft/Home/compute-ranks-of-elements-in-a-c&mdash;array-or-vector (quantile method, replacing the nth-element call by direct access to a sorted vector). More...
 
static std::vector< double > derivative (const std::vector< double > &X, const std::vector< double > &Y)
 This function returns the vector of local derivatives, given a vector of abscissae and ordinates. The vectors must be sorted by ascending x. The derivatives will be centered if possible, left or right otherwise or nodata if nothing else can be computed. More...
 
static void sort (std::vector< double > &X, std::vector< double > &Y, const bool &keep_nodata=true)
 This function sort the X and Y vectors by increasing X. The nodata values (both in X and Y) are removed, meaning that the vector length might not be kept. More...
 
static void equalBin (const unsigned int k, std::vector< double > &X, std::vector< double > &Y)
 data binning method This bins the data into k classes of equal width (see https://en.wikipedia.org/wiki/Data_binning) More...
 
static void equalCountBin (const unsigned int k, std::vector< double > &X, std::vector< double > &Y)
 data binning method This bins the data into k classes of equal number of elements (see https://en.wikipedia.org/wiki/Data_binning). The number of elements per classes is adjusted in order to reduce unevenness between casses: for example when distributing 100 elements in 8 classes, this will generate 4 classes of 13 elements and 4 classes of 12 elements. More...
 
static double weightedMean (const double &d1, const double &d2, const double &weight=1.)
 This function returns the weighted aritmetic mean of two numbers. A weight of 0 returns d1, a weight of 1 returns d2, a weight of 0.5 returns a centered mean. See https://secure.wikimedia.org/wikipedia/en/wiki/Weighted_mean for more... More...
 
static double weightedMean (const std::vector< double > &vecData, const std::vector< double > &weight)
 This function returns the weighted aritmetic mean of a vector. See https://secure.wikimedia.org/wikipedia/en/wiki/Weighted_mean for more... More...
 
static double arithmeticMean (const std::vector< double > &vecData)
 
static double getMedian (const std::vector< double > &vecData, const bool &keep_nodata=true)
 
static double getMedianAverageDeviation (std::vector< double > vecData, const bool &keep_nodata=true)
 
static double variance (const std::vector< double > &X)
 Compute the variance of a vector of data It is computed using a compensated variance algorithm, (see https://secure.wikimedia.org/wikipedia/en/wiki/Algorithms_for_calculating_variance) in order to be more robust to small variations around the mean. More...
 
static double std_dev (const std::vector< double > &X)
 
static double covariance (const std::vector< double > &z1, const std::vector< double > &z2)
 
static double corr (const std::vector< double > &z1, const std::vector< double > &z2)
 Computes the Pearson product-moment correlation coefficient This should be equivalent to the default R "corr" method. More...
 
static void LinRegression (const std::vector< double > &X, const std::vector< double > &Y, double &a, double &b, double &r, std::string &mesg, const bool &fixed_rate=false)
 Computes the linear regression coefficients fitting the points given as X and Y in two vectors the linear regression has the form Y = aX + b with a regression coefficient r (it is nodata safe) More...
 
static void NoisyLinRegression (const std::vector< double > &in_X, const std::vector< double > &in_Y, double &A, double &B, double &R, std::string &mesg, const bool &fixed_rate=false)
 Computes the linear regression coefficients fitting the points given as X and Y in two vectors the linear regression has the form Y = aX + b with a regression coefficient r. If the regression coefficient is not good enough, tries to remove bad points (up to 15% of the initial data set can be removed, keeping at least 4 points) More...
 
static void twoLinRegression (const std::vector< double > &in_X, const std::vector< double > &in_Y, const double &bilin_inflection, std::vector< double > &coeffs)
 Computes the bi-linear regression coefficients fitting the points given as X and Y in two vectors We consider that the regression can be made with 2 linear segments with a fixed inflection point. It relies on Interpol1D::NoisyLinRegression. More...
 
static void LogRegression (const std::vector< double > &X, const std::vector< double > &Y, double &a, double &b, double &r, std::string &mesg)
 Computes the Log regression coefficients fitting the points given as X and Y in two vectors the log regression has the form Y = a*ln(X) + b with a regression coefficient r (it is nodata safe) More...
 
static void ExpRegression (const std::vector< double > &X, const std::vector< double > &Y, double &a, double &b, double &r, std::string &mesg)
 Computes the power regression coefficients fitting the points given as X and Y in two vectors the power regression has the form Y = b*X^a with a regression coefficient r (it is nodata safe) More...
 

Member Function Documentation

double mio::Interpol1D::arithmeticMean ( const std::vector< double > &  vecData)
static
double mio::Interpol1D::corr ( const std::vector< double > &  X,
const std::vector< double > &  Y 
)
static

Computes the Pearson product-moment correlation coefficient This should be equivalent to the default R "corr" method.

Parameters
Xfirst vector of data
Ysecond vector of data
Returns
correlation coefficient
double mio::Interpol1D::covariance ( const std::vector< double > &  z1,
const std::vector< double > &  z2 
)
static
std::vector< double > mio::Interpol1D::derivative ( const std::vector< double > &  X,
const std::vector< double > &  Y 
)
static

This function returns the vector of local derivatives, given a vector of abscissae and ordinates. The vectors must be sorted by ascending x. The derivatives will be centered if possible, left or right otherwise or nodata if nothing else can be computed.

Parameters
Xvector of abscissae
Yvector of ordinates
Returns
vector of local derivatives
void mio::Interpol1D::equalBin ( const unsigned int  k,
std::vector< double > &  X,
std::vector< double > &  Y 
)
static

data binning method This bins the data into k classes of equal width (see https://en.wikipedia.org/wiki/Data_binning)

Parameters
knumber of classes
Xvector of abscissae
Yvector of ordinates
void mio::Interpol1D::equalCountBin ( const unsigned int  k,
std::vector< double > &  X,
std::vector< double > &  Y 
)
static

data binning method This bins the data into k classes of equal number of elements (see https://en.wikipedia.org/wiki/Data_binning). The number of elements per classes is adjusted in order to reduce unevenness between casses: for example when distributing 100 elements in 8 classes, this will generate 4 classes of 13 elements and 4 classes of 12 elements.

Parameters
knumber of classes
Xvector of abscissae
Yvector of ordinates
void mio::Interpol1D::ExpRegression ( const std::vector< double > &  X,
const std::vector< double > &  Y,
double &  a,
double &  b,
double &  r,
std::string &  mesg 
)
static

Computes the power regression coefficients fitting the points given as X and Y in two vectors the power regression has the form Y = b*X^a with a regression coefficient r (it is nodata safe)

Parameters
Xvector of X coordinates
Yvector of Y coordinates (same order as X)
aslope of the regression
borigin of the regression
rregression coefficient
mesginformation message if something fishy is detected
double mio::Interpol1D::getMedian ( const std::vector< double > &  vecData,
const bool &  keep_nodata = true 
)
static
double mio::Interpol1D::getMedianAverageDeviation ( std::vector< double >  vecData,
const bool &  keep_nodata = true 
)
static
void mio::Interpol1D::LinRegression ( const std::vector< double > &  X,
const std::vector< double > &  Y,
double &  a,
double &  b,
double &  r,
std::string &  mesg,
const bool &  fixed_rate = false 
)
static

Computes the linear regression coefficients fitting the points given as X and Y in two vectors the linear regression has the form Y = aX + b with a regression coefficient r (it is nodata safe)

Parameters
Xvector of X coordinates
Yvector of Y coordinates (same order as X)
aslope of the linear regression
borigin of the linear regression
rabsolute value of linear regression coefficient
mesginformation message if something fishy is detected
fixed_rateforce the lapse rate? (default=false)
void mio::Interpol1D::LogRegression ( const std::vector< double > &  X,
const std::vector< double > &  Y,
double &  a,
double &  b,
double &  r,
std::string &  mesg 
)
static

Computes the Log regression coefficients fitting the points given as X and Y in two vectors the log regression has the form Y = a*ln(X) + b with a regression coefficient r (it is nodata safe)

Parameters
Xvector of X coordinates
Yvector of Y coordinates (same order as X)
aslope of the regression
borigin of the regression
rregression coefficient
mesginformation message if something fishy is detected
double mio::Interpol1D::max_element ( const std::vector< double > &  X)
static
double mio::Interpol1D::min_element ( const std::vector< double > &  X)
static
void mio::Interpol1D::NoisyLinRegression ( const std::vector< double > &  in_X,
const std::vector< double > &  in_Y,
double &  A,
double &  B,
double &  R,
std::string &  mesg,
const bool &  fixed_rate = false 
)
static

Computes the linear regression coefficients fitting the points given as X and Y in two vectors the linear regression has the form Y = aX + b with a regression coefficient r. If the regression coefficient is not good enough, tries to remove bad points (up to 15% of the initial data set can be removed, keeping at least 4 points)

Parameters
in_Xvector of X coordinates
in_Yvector of Y coordinates (same order as X)
Aslope of the linear regression
Borigin of the linear regression
Rlinear regression coefficient
mesginformation message if something fishy is detected
fixed_rateforce the lapse rate? (default=false)
std::vector< double > mio::Interpol1D::quantiles ( const std::vector< double > &  X,
const std::vector< double > &  quartiles 
)
static

This function returns a vector of quantiles. The vector does not have to be sorted. See https://secure.wikimedia.org/wikipedia/en/wiki/Quartile for more. This code is heavily inspired by Ken Wilder, https://sites.google.com/site/jivsoft/Home/compute-ranks-of-elements-in-a-c&mdash;array-or-vector (quantile method, replacing the nth-element call by direct access to a sorted vector).

Parameters
Xvector to classify
quartilesvector of quartiles, between 0 and 1
Returns
vector of ordinates of the quantiles
void mio::Interpol1D::sort ( std::vector< double > &  X,
std::vector< double > &  Y,
const bool &  keep_nodata = true 
)
static

This function sort the X and Y vectors by increasing X. The nodata values (both in X and Y) are removed, meaning that the vector length might not be kept.

Parameters
Xvector of abscissae
Yvector of ordinates
keep_nodatashould nodata values be kept? (default=true)
double mio::Interpol1D::std_dev ( const std::vector< double > &  X)
static
void mio::Interpol1D::twoLinRegression ( const std::vector< double > &  in_X,
const std::vector< double > &  in_Y,
const double &  bilin_inflection,
std::vector< double > &  coeffs 
)
static

Computes the bi-linear regression coefficients fitting the points given as X and Y in two vectors We consider that the regression can be made with 2 linear segments with a fixed inflection point. It relies on Interpol1D::NoisyLinRegression.

Parameters
in_Xvector of X coordinates
in_Yvector of Y coordinates (same order as X)
bilin_inflectioninflection point absissa
coeffsa,b,r coefficients in a vector
double mio::Interpol1D::variance ( const std::vector< double > &  X)
static

Compute the variance of a vector of data It is computed using a compensated variance algorithm, (see https://secure.wikimedia.org/wikipedia/en/wiki/Algorithms_for_calculating_variance) in order to be more robust to small variations around the mean.

Parameters
Xvector of data
Returns
variance or IOUtils::nodata
double mio::Interpol1D::weightedMean ( const double &  d1,
const double &  d2,
const double &  weight = 1. 
)
static

This function returns the weighted aritmetic mean of two numbers. A weight of 0 returns d1, a weight of 1 returns d2, a weight of 0.5 returns a centered mean. See https://secure.wikimedia.org/wikipedia/en/wiki/Weighted_mean for more...

Parameters
d1first value
d2second value
weightweight to apply to the mean
Returns
weighted aritmetic mean
double mio::Interpol1D::weightedMean ( const std::vector< double > &  vecData,
const std::vector< double > &  weight 
)
static

This function returns the weighted aritmetic mean of a vector. See https://secure.wikimedia.org/wikipedia/en/wiki/Weighted_mean for more...

Parameters
vecDatavector of values
weightweights to apply to the mean
Returns
weighted aritmetic mean

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