CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Math/Statistics.h
Views: 1401
1
#pragma once
2
3
#include <cmath>
4
5
// Very simple stat for convenience. Keeps track of min, max, smoothed.
6
struct SimpleStat {
7
SimpleStat(const char *name) : name_(name) { Reset(); }
8
9
void Update(double value) {
10
value_ = value;
11
if (min_ == INFINITY) {
12
smoothed_ = value;
13
} else {
14
// TODO: Make factor adjustable?
15
smoothed_ = 0.99 * smoothed_ + 0.01 * value;
16
}
17
if (value < min_) {
18
min_ = value;
19
}
20
if (value > max_) {
21
max_ = value;
22
}
23
}
24
25
void Reset() {
26
value_ = 0.0;
27
smoothed_ = 0.0; // doens't really need init
28
min_ = INFINITY;
29
max_ = -INFINITY;
30
}
31
32
void Format(char *buffer, size_t sz);
33
34
private:
35
SimpleStat() {}
36
const char *name_;
37
38
// These are initialized in Reset().
39
double value_;
40
double min_;
41
double max_;
42
double smoothed_;
43
};
44
45