forked from SofaPirate/Plaquette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovingStats.h
61 lines (51 loc) · 2 KB
/
MovingStats.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* MovingStats.h
*
* Computes floating-point mean and variance statistics over time using an exponential moving average.
* This class computes the following statistics: mean, variance and standard deviation.
*
* (c) 2014 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOVINGSTATS_H_
#define MOVINGSTATS_H_
#include "Stats.h"
#include "MovingAverage.h"
class MovingStats : public Stats {
public:
MovingAverage avg;
float _var;
/**
* Constructs the moving statistics, starting with #startMean# and #startVar# as initial mean and
* variance. The #alphaOrN# argument has two options:
* - if <= 1 then it's used directly as the alpha value
* - if > 1 then it's used as the "number of items that are considered from the past" (*)
* (*) Of course this is an approximation. It actually sets the alpha value to 2 / (n - 1)
*/
MovingStats(float alphaOrN=1);
MovingStats(float alphaOrN, float startMean, float startVar);
virtual ~MovingStats() {}
/// Resets the statistics.
virtual void reset();
/// Resets the statistics.
virtual void reset(float startMean, float startVar);
/// Adds a value to the statistics (returns the mean).
virtual float update(float value);
/// The statistics.
virtual float mean() const { return avg.get(); }
virtual float var() const { return _var; }
virtual bool isStarted() const;
};
#endif /* MOVINGSTATS_H_ */