MeteoIODoc 2.11.0
libinterpol1D.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef LIBINTERPOL1D_H
20#define LIBINTERPOL1D_H
21
22#include <vector>
23#include <string>
24
25namespace mio {
26
37 public:
38 static double min_element(const std::vector<double>& X);
39 static double max_element(const std::vector<double>& X);
40 static std::vector<double> quantiles(const std::vector<double>& X, const std::vector<double>& quartiles);
41 static std::vector<double> quantiles_core(std::vector<double> X, const std::vector<double>& quartiles);
42 static std::vector<double> derivative(const std::vector<double>& X, const std::vector<double>& Y);
43 static void sort(std::vector<double>& X, std::vector<double>& Y, const bool& keep_nodata=true);
44 static void equalBin(const unsigned int k, std::vector<double> &X, std::vector<double> &Y);
45 static void equalCountBin(const unsigned int k, std::vector<double> &X, std::vector<double> &Y);
46 static double weightedMean(const double& d1, const double& d2, const double& weight=1.);
47 static double weightedMean(const std::vector<double>& vecData, const std::vector<double>& weight);
48 static double arithmeticMean(const std::vector<double>& vecData);
49 static double getMedian(const std::vector<double>& vecData, const bool& keep_nodata=true);
50 static double getMedianAverageDeviation(std::vector<double> vecData, const bool& keep_nodata=true);
51 static double variance(const std::vector<double>& X);
52 static double std_dev(const std::vector<double>& X);
53 static double covariance(const std::vector<double>& z1, const std::vector<double>& z2);
54 static double corr(const std::vector<double>& z1, const std::vector<double>& z2);
55 static double Pearson(const std::vector<double>& X, const std::vector<double>& Y);
56 static double R2(const std::vector<double>& obs, const std::vector<double>& sim);
57 static double NashSuttcliffe(const std::vector<double>& obs, const std::vector<double>& sim);
58 static double getBoxMuller();
59
60 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);
61 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);
62 static void twoLinRegression(const std::vector<double>& in_X, const std::vector<double>& in_Y, const double& bilin_inflection, std::vector<double>& coeffs);
63 static void LogRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
64 static void ExpRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
65
66 private:
67 static double getMedianCore(std::vector<double> vecData);
68 static bool ptOK(const double& x, const double& y);
69 static void LinRegressionFixedRate(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::string& mesg);
70 static bool pair_comparator(const std::pair<double, double>& l, const std::pair<double, double>& r);
71 static double pt_line_distance(const double& x, const double& y, const double& a, const double& b);
72};
73
74} //end namespace
75
76#endif
A class to perform basic 1D statistics. Each method is static.
Definition: libinterpol1D.h:36
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:904
static std::vector< double > quantiles_core(std::vector< double > X, const std::vector< double > &quartiles)
This function returns a vector of quantiles, but does not filter out nodata values!...
Definition: libinterpol1D.cc:92
static double covariance(const std::vector< double > &z1, const std::vector< double > &z2)
Definition: libinterpol1D.cc:506
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:242
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:536
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....
Definition: libinterpol1D.cc:67
static double getBoxMuller()
Box–Muller method for normally distributed random numbers.
Definition: libinterpol1D.cc:652
static double weightedMean(const double &d1, const double &d2, const double &weight=1.)
This function returns the weighted arithmetic mean of two numbers. A weight of 0 returns d1,...
Definition: libinterpol1D.cc:335
static double arithmeticMean(const std::vector< double > &vecData)
Definition: libinterpol1D.cc:378
static double NashSuttcliffe(const std::vector< double > &obs, const std::vector< double > &sim)
Computes the Nash-Suttcliffe correlation coefficient for two vectors It is assumed that the same indi...
Definition: libinterpol1D.cc:623
static double std_dev(const std::vector< double > &X)
Definition: libinterpol1D.cc:500
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:809
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....
Definition: libinterpol1D.cc:198
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:687
static double getMedianAverageDeviation(std::vector< double > vecData, const bool &keep_nodata=true)
Definition: libinterpol1D.cc:441
static double min_element(const std::vector< double > &X)
Definition: libinterpol1D.cc:34
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:470
static double Pearson(const std::vector< double > &X, const std::vector< double > &Y)
Computes the Pearson product-moment correlation coefficient in a more numerically efficient manner th...
Definition: libinterpol1D.cc:556
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:926
static void sort(std::vector< double > &X, std::vector< double > &Y, const bool &keep_nodata=true)
This function sorts the X and Y vectors by increasing X. The nodata values (both in X and Y) are remo...
Definition: libinterpol1D.cc:294
static double R2(const std::vector< double > &obs, const std::vector< double > &sim)
Computes the R2 coefficient of determination See https://en.wikipedia.org/wiki/Coefficient_of_determi...
Definition: libinterpol1D.cc:592
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:861
static double max_element(const std::vector< double > &X)
Definition: libinterpol1D.cc:46
static double getMedian(const std::vector< double > &vecData, const bool &keep_nodata=true)
Definition: libinterpol1D.cc:421
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:139
Definition: Config.cc:31