diff --git a/libraries/Histogram/LICENSE b/libraries/Histogram/LICENSE index b4d74e37..afbcf592 100644 --- a/libraries/Histogram/LICENSE +++ b/libraries/Histogram/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012-2021 Rob Tillaart +Copyright (c) 2012-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/Histogram/examples/hist_find_performance/hist_find_performance.ino b/libraries/Histogram/examples/hist_find_performance/hist_find_performance.ino index 602188c5..26989164 100644 --- a/libraries/Histogram/examples/hist_find_performance/hist_find_performance.ino +++ b/libraries/Histogram/examples/hist_find_performance/hist_find_performance.ino @@ -1,11 +1,9 @@ // // FILE: hist_find_performance.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // DATE: 2021-11-03 -// // PUPROSE: indication histogram find performance -// + #include "histogram.h" @@ -73,9 +71,11 @@ void setup() Serial.println(); } + void loop() { } // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test/hist_test.ino b/libraries/Histogram/examples/hist_test/hist_test.ino index 128b1a21..8e00a4ab 100644 --- a/libraries/Histogram/examples/hist_test/hist_test.ino +++ b/libraries/Histogram/examples/hist_test/hist_test.ino @@ -1,18 +1,16 @@ // // FILE: hist_test.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // DATE: 2012-12-23 -// // PUPROSE: test histogram frequency -// + #include "histogram.h" // float b[] = { 0, 100, 200, 300, 325, 350, 375, 400, 500, 600, 700, 800, 900, 1000 }; // boundaries does not need to be equally distributed. -float b[] = { +float b[] = { 0, 100, 200, 300, 325, 350, 375 }; Histogram hist(7, b); @@ -20,6 +18,7 @@ Histogram hist(7, b); uint32_t lastTime = 0; const uint32_t threshold = 25; // milliseconds, for updating display + void setup() { Serial.begin(115200); @@ -32,27 +31,28 @@ void setup() for (int i = 0; i < hist.size()-1; i++) { - Serial.print("\t"); - Serial.print(b[i], 2); + Serial.print("\t"); + Serial.print(b[i], 2); } Serial.println(); for (int i = 0; i < hist.size()-1; i++) { - Serial.print("\t"); - Serial.print(hist.find(b[i])); + Serial.print("\t"); + Serial.print(hist.find(b[i])); } Serial.println(); } + void loop() { // choose a "generator" for histogram data // int x = analogRead(A0); - + int x = random(600) - 50; // below lower limit - - // int x = random(25); + + // int x = random(25); // x = x*x; @@ -61,7 +61,7 @@ void loop() // Serial.println(hist.find(x)); hist.add(x); - // update output + // update output uint32_t now = millis(); if (now - lastTime > threshold) { @@ -71,8 +71,8 @@ void loop() { Serial.print("\t"); // gives percentage per bucket - // Serial.print(hist.bucket(i)); - Serial.print(hist.frequency(i), 2); + // Serial.print(hist.bucket(i)); + Serial.print(hist.frequency(i), 2); } // quartiles // to get at least 25% of the values you must count all values < hist.VAL(0.25); @@ -93,3 +93,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_big/hist_test_big.ino b/libraries/Histogram/examples/hist_test_big/hist_test_big.ino index 5838f982..76aad889 100644 --- a/libraries/Histogram/examples/hist_test_big/hist_test_big.ino +++ b/libraries/Histogram/examples/hist_test_big/hist_test_big.ino @@ -1,13 +1,12 @@ // // FILE: hist_test_big.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // DATE: 2012-12-23 -// // PUPROSE: demo histogram frequency // run on ESP32 - // view in Serial plotter to graph distribution + #include "histogram.h" float b[200]; // MIGHT NOT WORK ON AVR !! @@ -17,6 +16,7 @@ Histogram hist(200, b); uint32_t lastTime = 0; const uint32_t threshold = 1000; // milliseconds, for updating display + void setup() { Serial.begin(115200); @@ -64,3 +64,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_cdf/hist_test_cdf.ino b/libraries/Histogram/examples/hist_test_cdf/hist_test_cdf.ino index 7f4351ea..f25304fd 100644 --- a/libraries/Histogram/examples/hist_test_cdf/hist_test_cdf.ino +++ b/libraries/Histogram/examples/hist_test_cdf/hist_test_cdf.ino @@ -1,11 +1,8 @@ // // FILE: hist_test_cdf.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // DATE: 2012-11-10 -// // PUPROSE: test histogram library -// #include "histogram.h" @@ -46,3 +43,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_graph/hist_test_graph.ino b/libraries/Histogram/examples/hist_test_graph/hist_test_graph.ino index b1f54010..1653f9d2 100644 --- a/libraries/Histogram/examples/hist_test_graph/hist_test_graph.ino +++ b/libraries/Histogram/examples/hist_test_graph/hist_test_graph.ino @@ -1,11 +1,8 @@ // // FILE: hist_test_graph.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // DATE: 2017-07-16 -// // PUPROSE: test histogram frequency -// #include "histogram.h" @@ -67,3 +64,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_level/hist_test_level.ino b/libraries/Histogram/examples/hist_test_level/hist_test_level.ino index 3ac9e18f..bb307fe4 100644 --- a/libraries/Histogram/examples/hist_test_level/hist_test_level.ino +++ b/libraries/Histogram/examples/hist_test_level/hist_test_level.ino @@ -1,11 +1,9 @@ // // FILE: hist_test_level.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // DATE: 2021-11-04 -// // PUPROSE: test histogram -// + #include "histogram.h" @@ -17,6 +15,7 @@ Histogram hist(100, b); uint32_t lastTime = 0; const uint32_t threshold = 25; // milliseconds, for updating display + void setup() { Serial.begin(115200); @@ -91,12 +90,13 @@ void setup() Serial.println(); Serial.println("done..."); - } + void loop() { } // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_pmf/hist_test_pmf.ino b/libraries/Histogram/examples/hist_test_pmf/hist_test_pmf.ino index 50983bb1..8a1766f7 100644 --- a/libraries/Histogram/examples/hist_test_pmf/hist_test_pmf.ino +++ b/libraries/Histogram/examples/hist_test_pmf/hist_test_pmf.ino @@ -3,9 +3,8 @@ // AUTHOR: Rob Tillaart // VERSION: 0.1.1 // DATE: 2012-11-10 -// // PUPROSE: test histogram library -// + #include "histogram.h" @@ -47,3 +46,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/examples/hist_test_val/hist_test_val.ino b/libraries/Histogram/examples/hist_test_val/hist_test_val.ino index 8ef66644..8c0f1033 100644 --- a/libraries/Histogram/examples/hist_test_val/hist_test_val.ino +++ b/libraries/Histogram/examples/hist_test_val/hist_test_val.ino @@ -1,11 +1,9 @@ // // FILE: hist_test_val.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // DATE: 2012-11-11 -// // PUPROSE: test histogram library -// + #include "histogram.h" @@ -36,10 +34,10 @@ void loop() float f = 0.5; Serial.print(f, 2); Serial.print(" : "); - + Serial.print(hist.VAL(f), 2); Serial.print("\t"); - + float sum = 0; uint16_t i = 0; for (i = 0; i < hist.size(); i++) @@ -59,3 +57,4 @@ void loop() // -- END OF FILE -- + diff --git a/libraries/Histogram/histogram.cpp b/libraries/Histogram/histogram.cpp index b23c3939..a5f1803b 100644 --- a/libraries/Histogram/histogram.cpp +++ b/libraries/Histogram/histogram.cpp @@ -1,7 +1,7 @@ // // FILE: Histogram.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.0 +// VERSION: 0.3.1 // PURPOSE: Histogram library for Arduino // DATE: 2012-11-10 // @@ -22,6 +22,8 @@ // add countAbove(), countLevel(), countBelow(). // add setBucket(), // change length to uint16_t ==> 65534 +// 0.3.1 2021-12-19 update library.json, license, minor edits + #include "histogram.h" diff --git a/libraries/Histogram/histogram.h b/libraries/Histogram/histogram.h index 88adb8a1..140bea8d 100644 --- a/libraries/Histogram/histogram.h +++ b/libraries/Histogram/histogram.h @@ -2,7 +2,7 @@ // // FILE: Histogram.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.0 +// VERSION: 0.3.1 // PURPOSE: Histogram library for Arduino // DATE: 2012-11-10 // @@ -10,7 +10,7 @@ #include "Arduino.h" -#define HISTOGRAM_LIB_VERSION (F("0.3.0")) +#define HISTOGRAM_LIB_VERSION (F("0.3.1")) class Histogram diff --git a/libraries/Histogram/keywords.txt b/libraries/Histogram/keywords.txt index 5de5aa40..5e05997c 100644 --- a/libraries/Histogram/keywords.txt +++ b/libraries/Histogram/keywords.txt @@ -1,10 +1,12 @@ # Syntax Colouring Map For Histogram + # Data types (KEYWORD1) Histogram KEYWORD1 Histogram8 KEYWORD1 Histogram16 KEYWORD1 + # Methods and Functions (KEYWORD2) clear KEYWORD2 setBucket KEYWORD2 diff --git a/libraries/Histogram/library.json b/libraries/Histogram/library.json index 027c2f8b..ec9dba14 100644 --- a/libraries/Histogram/library.json +++ b/libraries/Histogram/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/Histogram.git" }, - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "histogram.h" } diff --git a/libraries/Histogram/library.properties b/libraries/Histogram/library.properties index 2b70222b..f4a8e293 100644 --- a/libraries/Histogram/library.properties +++ b/libraries/Histogram/library.properties @@ -1,5 +1,5 @@ name=Histogram -version=0.3.0 +version=0.3.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for creating histograms math. diff --git a/libraries/Histogram/readme.md b/libraries/Histogram/readme.md index f62f05bf..a527caca 100644 --- a/libraries/Histogram/readme.md +++ b/libraries/Histogram/readme.md @@ -23,7 +23,7 @@ If you need more quantitative analysis, you might need the statistics library, - https://github.com/RobTillaart/Statistic -#### working +#### Working When the class is initialized an array of the boundaries to define the borders of the buckets is passed to the constructor. This array should be declared global as the @@ -48,19 +48,19 @@ The **frequency()** function may be removed to reduce footprint as it can be cal with the formula **(1.0 \* bucket(i))/count()**. -#### experimental: Histogram8 Histogram16 +#### Experimental: Histogram8 Histogram16 Histogram8 and Histogram16 are classes with same interface but smaller buckets. Histogram can count to ±2^31 while often ±2^15 or even ±2^7 is sufficient. Saves memory. -| class name | length | count/bucket | maxmem | -|:------------|-------:|-------------:|-------:| -| Histogram | 65534 | ±2147483647 | 260 KB | -| Histogram8 | 65534 | ±127 | 65 KB | -| Histogram16 | 65534 | ±32767 | 130 KB | +| class name | length | count/bucket | max memory | +|:------------|-------:|-------------:|-----------:| +| Histogram | 65534 | ±2147483647 | 260 KB | +| Histogram8 | 65534 | ±127 | 65 KB | +| Histogram16 | 65534 | ±32767 | 130 KB | The difference is the **\_data** array, to reduce the memory footprint. -Note: Maxmem is without the boundary array. +Note: max memory is without the boundary array. Performance optimizations are possible too however not essential for the experimental version. @@ -71,7 +71,8 @@ the experimental version. ### Constructor -- **Histogram(uint16_t length, float \*bounds)** constructor, get an array of boundary values and array length. Length should be less than 65534. +- **Histogram(uint16_t length, float \*bounds)** constructor, get an array of boundary values and array length. +Length should be less than 65534. - **~Histogram()** destructor. @@ -120,7 +121,9 @@ See examples ## Future -- performance - **find()** the right bucket. Binary search is faster - need testing. +- performance - **find()** the right bucket. + - Binary search is faster + - need testing. - improve accuracy - linear interpolation for **PMF()**, **CDF()** and **VAL()** - performance - merge loops in **PMF()** - performance - reverse loops - compare to zero. diff --git a/libraries/Histogram/test/unit_test_001.cpp b/libraries/Histogram/test/unit_test_001.cpp index 0f77bff9..ad992f8c 100644 --- a/libraries/Histogram/test/unit_test_001.cpp +++ b/libraries/Histogram/test/unit_test_001.cpp @@ -31,6 +31,7 @@ unittest_setup() { + fprintf(stderr, "HISTOGRAM_LIB_VERSION: %s\n", (char *) HISTOGRAM_LIB_VERSION); } unittest_teardown() @@ -40,13 +41,11 @@ unittest_teardown() unittest(test_constructor) { - fprintf(stderr, "VERSION: %s\n", HISTOGRAM_LIB_VERSION); - float diceValues[] = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5 }; Histogram hist(6, diceValues); assertEqual(7, hist.size()); assertEqual(0, hist.count()); - + for (int i = 0; i < 7; i++) { fprintf(stderr, "%d\t", i); @@ -66,20 +65,20 @@ unittest(test_dice) { hist.add( d % 7 ); // simulate dice } - + assertEqual(7, hist.size()); assertEqual(70, hist.count()); - + for (int i = 0; i < 7; i++) { fprintf(stderr, "%d\t", i); assertEqual(10, hist.bucket(i)); } - + hist.clear(); assertEqual(7, hist.size()); assertEqual(0, hist.count()); - + for (int i = 0; i < 7; i++) { fprintf(stderr, "%d\t", i);