@@ -16,7 +16,7 @@ Library for the Gauss probability math.
1616Gauss is an experimental Arduino library to approximate the probability that a value is
1717smaller or larger than a given value.
1818These 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 / σ ).
2020If these parameters are not given, 0 and 1 are used by default (normalized Gaussian distribution).
2121
2222The 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
2828
2929#### Accuracy
3030
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.
3334For many applications this accuracy is sufficient.
3435
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) ``` .
3637
38+ Note: 0.1.0 was 32 points 4 decimals. Need to investigate reduction of points.
3739
3840#### Applications
3941
@@ -42,9 +44,20 @@ For many applications this accuracy is sufficient.
4244- compare population data with individual
4345
4446
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+
4557#### Related
4658
4759- https://en.wikipedia.org/wiki/Normal_distribution
60+ - https://sphweb.bumc.bu.edu/otlt/mph-modules/bs/bs704_probability/bs704_probability9.html
4861- https://github.com/RobTillaart/Multimap
4962- https://github.com/RobTillaart/Statistic (more stat links there).
5063
@@ -59,19 +72,32 @@ For many applications this accuracy is sufficient.
5972#### Base
6073
6174- ** 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+
6485
6586#### Probability
6687
88+ Probability functions return NAN if stddev == 0.
89+
6790- ** float P_smaller(float f)** returns probability ** P(x < f)** .
6891Multiply by 100.0 to get the value as a percentage.
92+ A.k.a. ** CDF()** Cumulative Distribution Function.
6993- ** float P_larger(float f)** returns probability ** P(x > f)** .
7094Multiply by 100.0 to get the value as a percentage.
95+ As the distribution is continuous ** P_larger(f) == 1 - P_smaller(f)** .
7196- ** float P_between(float f, float g)** returns probability ** P(f < x < g)** .
7297Multiply by 100.0 to get the value as a percentage.
7398- ** 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+
75101
76102#### Other
77103
@@ -82,43 +108,74 @@ E.g if mean == 50 and stddev == 14, then 71 ==> +1.5 sigma.
82108- ** float bellCurve(float f)** returns probability ** P(x == f)** .
83109
84110
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+
85139## Future
86140
87141#### Must
88142
89143- documentation
90- - mu + sigma character
91- - unit tests
144+
92145
93146#### Should
94147
95- - optimize performance
96- - remove division by stddev
97148- optimize accuracy
98149 - revisit lookup of MultiMap
99150 - (-10 .. 0) might be more accurate (significant digits)?
100151 - double instead of floats? (good table?)
101-
152+ - make use of equidistant \_\_ z \[ ] table
102153
103154
104155#### Could
105156
106- - ** void setMean(float f)**
107- - ** float getMean()**
108- - ** void setStddev(float f)**
109- - ** float getStddev()**
110- - default values for ** begin(0,1)**
111157- add examples
112158 - e.g. temperature (DS18B20 or DHT22)
113159 - 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).
118160- 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()**
120170
121171
122172#### Won't (unless requested)
123173
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+
124181
0 commit comments