Plaquette
 
Loading...
Searching...
No Matches
MovingStats.h
1/*
2 * MovingStats.h
3 *
4 * Computes floating-point mean and variance statistics over time using an exponential moving average.
5 * This class computes the following statistics: mean, variance and standard deviation.
6 *
7 * (c) 2014 Sofian Audry -- info(@)sofianaudry(.)com
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef MOVINGSTATS_H_
24#define MOVINGSTATS_H_
25
26#include "MovingAverage.h"
27
28namespace pq {
29
31public:
32 // Moving average over values (ie. mean).
33 MovingAverage _mean;
34
35 // Moving average of squared values.
36 MovingAverage _mean2;
37
40
41 virtual ~MovingStats() {}
42
44 virtual void reset();
45
47 virtual void reset(float initMean, float initStdDev);
48
50 virtual float update(float value, float alpha);
51
53 virtual float mean() const { return _mean.constGet(); }
54
56 virtual float meanSquared() const { return _mean2.constGet(); }
57
59 virtual float var() const { return (_mean2.constGet() - sq(mean())); }
60
62 virtual float stdDev() const;
63
65 virtual float normalize(float value) const;
66
68 virtual float normalize(float value, float mean, float stdDev) const;
69
76 virtual bool isOutlier(float value, float nStdDev=1.5f) const;
77
84 virtual bool isLowOutlier(float value, float nStdDev=1.5f) const;
85
92 virtual bool isHighOutlier(float value, float nStdDev=1.5f) const;
93
96 virtual float stddev() const { return stdDev(); }
97};
98
99} // namespace pq
100
101#endif /* MOVINGSTATS_H_ */
An exponential moving average class.
Definition MovingAverage.h:34
Definition MovingStats.h:30
virtual float normalize(float value) const
Returns the normalized value according N(0, 1).
Definition MovingStats.cpp:65
virtual float stdDev() const
Returns the standard deviation of the samples.
Definition MovingStats.cpp:55
virtual float meanSquared() const
Return an exponential moving variance of the squared samples.
Definition MovingStats.h:56
virtual bool isOutlier(float value, float nStdDev=1.5f) const
Returns true if the value is considered an outlier.
Definition MovingStats.cpp:80
virtual bool isHighOutlier(float value, float nStdDev=1.5f) const
Returns true if the value is considered a high outlier (above average).
Definition MovingStats.cpp:89
virtual void reset()
Resets the statistics.
Definition MovingStats.cpp:34
virtual float var() const
Returns an exponential moving variance of the samples.
Definition MovingStats.h:59
virtual float update(float value, float alpha)
Adds a value to the statistics (returns the mean).
Definition MovingStats.cpp:44
MovingStats()
Default constructor (infinite time window).
Definition MovingStats.cpp:32
virtual float mean() const
Returns an exponential moving average of the samples.
Definition MovingStats.h:53
virtual bool isLowOutlier(float value, float nStdDev=1.5f) const
Returns true if the value is considered a low outlier (below average).
Definition MovingStats.cpp:85
virtual float stddev() const
Definition MovingStats.h:96