MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
libinterpol1D.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef LIBINTERPOL1D_H
19 #define LIBINTERPOL1D_H
20 
21 #include <vector>
22 #include <string>
23 
24 namespace mio {
25 
35 class Interpol1D {
36  public:
37  static double min_element(const std::vector<double>& X);
38  static double max_element(const std::vector<double>& X);
39  static std::vector<double> quantiles(const std::vector<double>& X, const std::vector<double>& quartiles);
40  static std::vector<double> derivative(const std::vector<double>& X, const std::vector<double>& Y);
41  static void sort(std::vector<double>& X, std::vector<double>& Y, const bool& keep_nodata=true);
42  static void equalBin(const unsigned int k, std::vector<double> &X, std::vector<double> &Y);
43  static void equalCountBin(const unsigned int k, std::vector<double> &X, std::vector<double> &Y);
44  static double weightedMean(const double& d1, const double& d2, const double& weight=1.);
45  static double weightedMean(const std::vector<double>& vecData, const std::vector<double>& weight);
46  static double arithmeticMean(const std::vector<double>& vecData);
47  static double getMedian(const std::vector<double>& vecData, const bool& keep_nodata=true);
48  static double getMedianAverageDeviation(std::vector<double> vecData, const bool& keep_nodata=true);
49  static double variance(const std::vector<double>& X);
50  static double std_dev(const std::vector<double>& X);
51  static double covariance(const std::vector<double>& z1, const std::vector<double>& z2);
52  static double corr(const std::vector<double>& z1, const std::vector<double>& z2);
53 
54  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);
55  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);
56  static void twoLinRegression(const std::vector<double>& in_X, const std::vector<double>& in_Y, const double& bilin_inflection, std::vector<double>& coeffs);
57  static void LogRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
58  static void ExpRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
59 
60  private:
61  static double getMedianCore(std::vector<double> vecData);
62  static bool ptOK(const double& x, const double& y);
63  static void LinRegressionFixedRate(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
64  static bool pair_comparator(const std::pair<double, double>& l, const std::pair<double, double>& r);
65  static double pt_line_distance(const double& x, const double& y, const double& a, const double& b);
66 };
67 
68 } //end namespace
69 
70 #endif
static double variance(const std::vector< double > &X)
Compute the variance of a vector of data It is computed using a compensated variance algorithm...
Definition: libinterpol1D.cc:453
static double std_dev(const std::vector< double > &X)
Definition: libinterpol1D.cc:483
static double arithmeticMean(const std::vector< double > &vecData)
Definition: libinterpol1D.cc:361
static double min_element(const std::vector< double > &X)
Definition: libinterpol1D.cc:32
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...
Definition: libinterpol1D.cc:318
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 li...
Definition: libinterpol1D.cc:683
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 li...
Definition: libinterpol1D.cc:561
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 ...
Definition: libinterpol1D.cc:519
A class to perform basic 1D statistics. Each method is static.
Definition: libinterpol1D.h:35
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 remov...
Definition: libinterpol1D.cc:281
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...
Definition: libinterpol1D.cc:122
static double getMedian(const std::vector< double > &vecData, const bool &keep_nodata=true)
Definition: libinterpol1D.cc:404
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 r...
Definition: libinterpol1D.cc:778
static double getMedianAverageDeviation(std::vector< double > vecData, const bool &keep_nodata=true)
Definition: libinterpol1D.cc:424
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).
Definition: libinterpol1D.cc:65
static double max_element(const std::vector< double > &X)
Definition: libinterpol1D.cc:44
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...
Definition: libinterpol1D.cc:225
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 pow...
Definition: libinterpol1D.cc:800
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 ...
Definition: libinterpol1D.cc:735
static double covariance(const std::vector< double > &z1, const std::vector< double > &z2)
Definition: libinterpol1D.cc:489
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)
Definition: libinterpol1D.cc:181