WSL/SLF GitLab Repository

libinterpol1D.h 3.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LIBINTERPOL1D_H__
#define __LIBINTERPOL1D_H__

#include <meteoio/IOExceptions.h>
22
#include <meteoio/IOUtils.h>
23
24
25
26
27
28

#include <vector>
#include <algorithm>

namespace mio {

29
30
31
32
33
34
35
36
37
/**
 * @class Interpol1D
 * @brief A class to perform basic 1D statistics.
 * Each method is static
 *
 * @ingroup stats
 * @author Mathias Bavay
 * @date   2009-01-20
 */
38
39
class Interpol1D {
 	public:
40
		static std::vector<double> quantiles(const std::vector<double>& X, const std::vector<double>& quartiles);
41
42
		static std::vector<double> derivative(const std::vector<double>& X, const std::vector<double>& Y);
		static void sort(std::vector<double>& X, std::vector<double>& Y);
43
44
		static double weightedMean(const double& d1, const double& d2, const double& weight=1.);
		static double weightedMean(const std::vector<double>& vecData, const std::vector<double>& weight);
45
46
47
		static double arithmeticMean(const std::vector<double>& vecData);
		static double getMedian(const std::vector<double>& vecData);
		static double getMedianAverageDeviation(const std::vector<double>& vecData);
48
49
50
51
		static double variance(const std::vector<double>& X);
		static double std_dev(const std::vector<double>& X);
		static double covariance(const std::vector<double>& z1, const std::vector<double>& z2);

52
		static void LinRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::ostringstream& mesg, const bool& fixed_rate=false);
53
54
		static void NoisyLinRegression(const std::vector<double>& in_X, const std::vector<double>& in_Y, double& A, double& B, double& R, std::ostringstream& mesg, const bool& fixed_rate=false);
		static void twoLinRegression(const std::vector<double>& in_X, const std::vector<double>& in_Y, const double& bilin_inflection, std::vector<double>& coeffs);
55
56
		static void LogRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::ostringstream& mesg);
		static void ExpRegression(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::ostringstream& mesg);
57
58

	private:
59
		static bool ptOK(const double& x, const double& y);
60
		static void LinRegressionFixedRate(const std::vector<double>& X, const std::vector<double>& Y, double& a, double& b, double& r, std::ostringstream& mesg);
61
		static bool pair_comparator(const std::pair<double, double>& l, const std::pair<double, double>& r);
62
		static double pt_line_distance(const double& x, const double& y, const double& a, const double& b);
63
};
64

65
66
67
} //end namespace

#endif