blob: 138c1aff556f5d5858b751a0f194499be16c9cd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#pragma once
#include <QQueue>
// Truncated Interquartile mean
// TruncatedIQM keeps an ordered list with the last n (_capacity_)
// input doubles and calculates the mean discarding the lowest 25%
// and the highest 25% values in order to reduce sensitivity to outliers.
//
// http://en.wikipedia.org/wiki/Interquartile_mean
class MovingInterquartileMean {
public:
// Constructs an empty MovingTruncatedIQM.
MovingInterquartileMean(const unsigned int listLength);
virtual ~MovingInterquartileMean();
// Inserts value to the list and returns the new truncated mean.
double insert(double value);
// Empty the list.
void clear();
// Returns the current truncated mean. Input list must not be empty.
double mean();
// Returns how many values have been input.
int size() const;
// Returns the maximum size of the input list.
int listMaxSize() const;
private:
double m_dMean;
int m_iListMaxSize;
// The list keeps input doubles ordered by value.
std::list<double> m_list;
// The queue keeps pointers to doubles in the list ordered
// by the order they were received.
QQueue<std::list<double>::iterator> m_queue;
// sum() checks this to know if it has to recalculate the mean.
bool m_bChanged;
};
|