iLand
statdata.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU 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** This program 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 General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef STATDATA_H
20#define STATDATA_H
21
27{
28public:
30 StatData(QVector<double> &data);
31 void setData(QVector<double> &data) { mData=data; calculate(); }
32 void calculate();
33 // getters
34 double sum() const { return mSum; }
35 double mean() const { return mMean; }
36 double min() const { return mMin; }
37 double max() const { return mMax; }
38 double median() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mMedian; }
39 double percentile25() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mP25; }
40 double percentile75() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mP75; }
41 double percentile(const int percent) const;
42 double standardDev() const { if (mSD==std::numeric_limits<double>::max()) calculateSD(); return mSD; }
43 // additional functions
44 static QVector<int> calculateRanks(const QVector<double> &data, bool descending=false);
45 static void normalize(QVector<double> &data, double targetSum);
46private:
47 double calculateSD() const;
48 mutable QVector<double> mData; // mutable to allow late calculation of percentiles (e.g. a call to "median()".)
49 double mSum;
50 double mMean;
51 double mMin;
52 double mMax;
53 mutable double mP25;
54 mutable double mP75;
55 mutable double mMedian;
56 mutable double mSD; // standard deviation
57 void calculatePercentiles() const;
58};
59
60
61#endif // STATDATA_H
StatData.
Definition: statdata.h:27
static void normalize(QVector< double > &data, double targetSum)
normalize, i.e. the sum of all items after processing is targetSum
Definition: statdata.cpp:163
static QVector< int > calculateRanks(const QVector< double > &data, bool descending=false)
rank data.
Definition: statdata.cpp:135
double sum() const
sum of values
Definition: statdata.h:34
double standardDev() const
get the standard deviation (of the population)
Definition: statdata.h:42
double median() const
2nd quartil = median
Definition: statdata.h:38
void setData(QVector< double > &data)
Definition: statdata.h:31
StatData()
Definition: statdata.h:29
double percentile25() const
1st quartil
Definition: statdata.h:39
void calculate()
Definition: statdata.cpp:36
double min() const
minimum value
Definition: statdata.h:36
double percentile(const int percent) const
get value of a given percentile (0..100)
Definition: statdata.cpp:80
double percentile75() const
3rd quartil
Definition: statdata.h:40
double mean() const
arithmetic mean
Definition: statdata.h:35
double max() const
maximum value
Definition: statdata.h:37