1.0.7 Statistic

This commit is contained in:
Rob Tillaart 2024-08-23 17:03:24 +02:00
parent 87bbcb00bb
commit 72e9d0d510
7 changed files with 35 additions and 15 deletions

View File

@ -5,10 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.7] - 2024-08-20
- Fix #21, add **getCoefficientOfVariation()**
- update readme.md
- update keywords.txt
## [1.0.6] - 2023-11-22 ## [1.0.6] - 2023-11-22
- update readme.md - update readme.md
## [1.0.5] - 2023-06-29 ## [1.0.5] - 2023-06-29
- fix #18 add **range()** and **middle()** - fix #18 add **range()** and **middle()**
- fast first order functions, based on minimum() and maximum() - fast first order functions, based on minimum() and maximum()

View File

@ -52,6 +52,7 @@ The template version (1.0.0) is created by Glen Cornell (Thanks!).
- https://github.com/RobTillaart/RunningMedian - https://github.com/RobTillaart/RunningMedian
- https://github.com/RobTillaart/statHelpers - combinations & permutations - https://github.com/RobTillaart/statHelpers - combinations & permutations
- https://github.com/RobTillaart/Statistic - https://github.com/RobTillaart/Statistic
- https://github.com/RobTillaart/Student
## Interface ## Interface
@ -90,6 +91,10 @@ These three functions only work if **useStdDev == true** (in the template).
- **typename T pop_stdev()** returns NAN if count == zero. - **typename T pop_stdev()** returns NAN if count == zero.
pop_stdev = population standard deviation, pop_stdev = population standard deviation,
- **typename T unbiased_stdev()** returns NAN if count == zero. - **typename T unbiased_stdev()** returns NAN if count == zero.
- **typename T getCoefficientOfVariation()** returns coefficient of variation.
This is defined as standardDeviation / Average.
It indicates if the distribution is relative small ( < 1) or relative wide ( > 1).
Note it has no meaning when the average is zero (or close to zero).
#### Deprecated methods #### Deprecated methods

View File

@ -4,7 +4,7 @@
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// modified at 0.3 by Gil Ross at physics dot org // modified at 0.3 by Gil Ross at physics dot org
// template version 1.0.0 by Glen Cornell // template version 1.0.0 by Glen Cornell
// VERSION: 1.0.6 // VERSION: 1.0.7
// PURPOSE: Recursive Statistical library for Arduino // PURPOSE: Recursive Statistical library for Arduino
// HISTORY: See CHANGELOG.md // HISTORY: See CHANGELOG.md
// //
@ -37,7 +37,7 @@
// and HAVE_STDCXX_CSTDINT feature macros in your build environment. // and HAVE_STDCXX_CSTDINT feature macros in your build environment.
#define STATISTIC_LIB_VERSION (F("1.0.6")) #define STATISTIC_LIB_VERSION (F("1.0.7"))
#if defined(__AVR__) #if defined(__AVR__)
@ -230,6 +230,14 @@ public:
return std::sqrt( _extra.ssqdif() / (_cnt - 1)); return std::sqrt( _extra.ssqdif() / (_cnt - 1));
} }
value_type getCoefficientOfVariation() const {
if (_sum == 0) return NaN;
value_type temp = pop_stdev(); // as all samples are available
if (temp == NaN) return NaN;
// return standard deviation / average
value_type cv = temp * _cnt / _sum;
return cv;
}
// deprecated methods: // deprecated methods:
Statistic(bool) { Statistic(bool) {

View File

@ -24,20 +24,22 @@ void setup(void)
{ {
myStats.add(i * 0.01 + 1); // add 10 elements myStats.add(i * 0.01 + 1); // add 10 elements
} }
// Serial.print(" Count: "); Serial.print(" Count: ");
// Serial.println(myStats.count()); Serial.println(myStats.count());
// Serial.print(" Min: "); Serial.print(" Min: ");
// Serial.println(myStats.minimum(), 4); Serial.println(myStats.minimum(), 4);
// Serial.print(" Max: "); Serial.print(" Max: ");
// Serial.println(myStats.maximum(), 4); Serial.println(myStats.maximum(), 4);
// Serial.print(" Average: "); Serial.print(" Average: ");
// Serial.println(myStats.average(), 4); Serial.println(myStats.average(), 4);
// Serial.print(" variance: "); Serial.print(" variance: ");
// Serial.println(myStats.variance(), 4); Serial.println(myStats.variance(), 4);
Serial.print(" pop stdev: "); Serial.print(" pop stdev: ");
Serial.println(myStats.pop_stdev(), 4); Serial.println(myStats.pop_stdev(), 4);
Serial.print(" unbias stdev: "); Serial.print(" unbias stdev: ");
Serial.println(myStats.unbiased_stdev(), 4); Serial.println(myStats.unbiased_stdev(), 4);
Serial.print("CoefVariation: ");
Serial.println(myStats.getCoefficientOfVariation(), 4);
} }

View File

@ -17,6 +17,7 @@ average KEYWORD2
variance KEYWORD2 variance KEYWORD2
pop_stdev KEYWORD2 pop_stdev KEYWORD2
unbiased_stdev KEYWORD2 unbiased_stdev KEYWORD2
getCoefficientOfVariation KEYWORD2
range KEYWORD2 range KEYWORD2
middle KEYWORD2 middle KEYWORD2

View File

@ -21,7 +21,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/Statistic.git" "url": "https://github.com/RobTillaart/Statistic.git"
}, },
"version": "1.0.6", "version": "1.0.7",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=Statistic name=Statistic
version=1.0.6 version=1.0.7
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library with basic statistical functions for Arduino. sentence=Library with basic statistical functions for Arduino.