@@ -16,7 +16,7 @@ Library for the Gauss probability math.
16
16
Gauss is an experimental Arduino library to approximate the probability that a value is
17
17
smaller or larger than a given value.
18
18
These under the premises of a Gaussian distribution with parameters ** mean** and ** stddev**
19
- (a.k.a. average / mu and standard deviation / sigma).
19
+ (a.k.a. average / mu / µ and standard deviation / sigma / σ ).
20
20
If these parameters are not given, 0 and 1 are used by default (normalized Gaussian distribution).
21
21
22
22
The values are approximated with ** MultiMap()** using a 32 points interpolated lookup.
@@ -28,12 +28,14 @@ Return values are given as floats, if one needs percentages, just multiply by 10
28
28
29
29
#### Accuracy
30
30
31
- The lookup table used has 32 points with 4 significant digits.
32
- Do not expect a higher accuracy / precision.
31
+ The lookup table has 34 points with 8 decimals.
32
+ This matches the precision of float data type.
33
+ Do not expect a very high accuracy / precision as interpolation is linear.
33
34
For many applications this accuracy is sufficient.
34
35
35
- (links to a table with more significant digits is welcome) .
36
+ Values of the table are calculated with ``` NORM.DIST(mean, stddev, x, true) ``` .
36
37
38
+ Note: 0.1.0 was 32 points 4 decimals. Need to investigate reduction of points.
37
39
38
40
#### Applications
39
41
@@ -42,9 +44,20 @@ For many applications this accuracy is sufficient.
42
44
- compare population data with individual
43
45
44
46
47
+ #### Character
48
+
49
+ | parameter | name | ALT-code | char |
50
+ | :-----------:| :------:| :----------:| :-----:|
51
+ | mean | mu | ALT-230 | µ |
52
+ | stddev | sigma | ALT-229 | σ |
53
+
54
+ - https://altcodesguru.com/greek-alt-codes.html
55
+
56
+
45
57
#### Related
46
58
47
59
- https://en.wikipedia.org/wiki/Normal_distribution
60
+ - https://sphweb.bumc.bu.edu/otlt/mph-modules/bs/bs704_probability/bs704_probability9.html
48
61
- https://github.com/RobTillaart/Multimap
49
62
- https://github.com/RobTillaart/Statistic (more stat links there).
50
63
@@ -59,19 +72,32 @@ For many applications this accuracy is sufficient.
59
72
#### Base
60
73
61
74
- ** Gauss()** constructor. Uses mean = 0 and stddev = 1 by default.
62
- - ** bool begin(float mean, float stddev)** set the mean and stddev.
63
- Returns true on success. If needed stddev is made positive.
75
+ - ** bool begin(float mean = 0, float stddev = 1)** set the mean and stddev.
76
+ Returns true if stddev > 0 which should be so.
77
+ Returns false if stddev <= 0, which could be a user choice.
78
+ Note that if ``` stddev == 0 ``` , probabilities cannot be calculated
79
+ as the distribution is not Gaussian.
80
+ The default values (0,1) gives the normalized Gaussian distribution.
81
+ ** begin()** can be called at any time to change the mean or stddev.
82
+ - ** float getMean()** returns current mean.
83
+ - ** float getStddev()** returns current stddev.
84
+
64
85
65
86
#### Probability
66
87
88
+ Probability functions return NAN if stddev == 0.
89
+
67
90
- ** float P_smaller(float f)** returns probability ** P(x < f)** .
68
91
Multiply by 100.0 to get the value as a percentage.
92
+ A.k.a. ** CDF()** Cumulative Distribution Function.
69
93
- ** float P_larger(float f)** returns probability ** P(x > f)** .
70
94
Multiply by 100.0 to get the value as a percentage.
95
+ As the distribution is continuous ** P_larger(f) == 1 - P_smaller(f)** .
71
96
- ** float P_between(float f, float g)** returns probability ** P(f < x < g)** .
72
97
Multiply by 100.0 to get the value as a percentage.
73
98
- ** float P_equal(float f)** returns probability ** P(x == f)** .
74
- This is the bell curve formula.
99
+ This uses the bell curve formula.
100
+
75
101
76
102
#### Other
77
103
@@ -82,43 +108,74 @@ E.g if mean == 50 and stddev == 14, then 71 ==> +1.5 sigma.
82
108
- ** float bellCurve(float f)** returns probability ** P(x == f)** .
83
109
84
110
111
+ ## Performance
112
+
113
+ Indicative numbers for 1000 calls, timing in micros.
114
+
115
+ Arduino UNO, 16 MHz, IDE 1.8.19
116
+
117
+ | function | 0.1.0 | 0.1.1 | notes |
118
+ | :--------------| :--------:| :--------:| :--------|
119
+ | P_smaller | 375396 | 365964 |
120
+ | P_larger | 384368 | 375032 |
121
+ | P_between | 265624 | 269176 |
122
+ | normalize | 44172 | 23024 |
123
+ | bellCurve | 255728 | 205460 |
124
+ | approx.bell | 764028 | 719184 | see examples
125
+
126
+
127
+ ESP32, 240 MHz, IDE 1.8.19
128
+
129
+ | function | 0.1.0 | 0.1.1 | notes |
130
+ | :--------------| :--------:| :--------:| :--------|
131
+ | P_smaller | - | 4046 |
132
+ | P_larger | - | 4043 |
133
+ | P_between | - | 3023 |
134
+ | normalize | - | 592 |
135
+ | bellCurve | - | 13522 |
136
+ | approx.bell | - | 7300 |
137
+
138
+
85
139
## Future
86
140
87
141
#### Must
88
142
89
143
- documentation
90
- - mu + sigma character
91
- - unit tests
144
+
92
145
93
146
#### Should
94
147
95
- - optimize performance
96
- - remove division by stddev
97
148
- optimize accuracy
98
149
- revisit lookup of MultiMap
99
150
- (-10 .. 0) might be more accurate (significant digits)?
100
151
- double instead of floats? (good table?)
101
-
152
+ - make use of equidistant \_\_ z \[ ] table
102
153
103
154
104
155
#### Could
105
156
106
- - ** void setMean(float f)**
107
- - ** float getMean()**
108
- - ** void setStddev(float f)**
109
- - ** float getStddev()**
110
- - default values for ** begin(0,1)**
111
157
- add examples
112
158
- e.g. temperature (DS18B20 or DHT22)
113
159
- e.g. loadcell (HX711)
114
- - does the stddev needs to be positive,
115
- - what happens if negative values are allowed?
116
- - equality test Gauss objects
117
- - move code to .cpp file? (rather small lib).
118
160
- embed MultiMap hardcoded instead of library dependency
119
- - ** bellCurve()** => ** Z()** ?
161
+ - add unit tests
162
+ - remove ** \_ stddev** as ** \_ reciprokeSD** holds same information.
163
+ - reverse normalization
164
+ - G(100,25) which value has stddev 0.735?
165
+ - ** VAL(probability = 0.75)** ==> 134 whatever
166
+ - Returns the value of the distribution for which the ** CDF()** is at least probability.
167
+ - Inverse of ** P_smaller()**
168
+ - ** float P_outside(float f, float g)** returns probability ** P(x < f) + P(g < x)** .
169
+ - assuming no overlap. Use ** P_outside() = 1 - P_between()**
120
170
121
171
122
172
#### Won't (unless requested)
123
173
174
+ - equality test Gauss objects
175
+ - does the stddev needs to be positive? Yes.
176
+ - what happens if negative values are allowed? P curve is reversed.
177
+ - move code to .cpp file? (rather small lib).
178
+ - ** void setMean(float f)** can be done with begin()
179
+ - ** void setStddev(float f)** can be done with begin()
180
+
124
181
0 commit comments