0.3.1 HIstogram

This commit is contained in:
rob tillaart 2021-12-19 13:52:01 +01:00
parent 3373165355
commit 945a64e50b
16 changed files with 64 additions and 60 deletions

View File

@ -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

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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 --

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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"
}

View File

@ -1,5 +1,5 @@
name=Histogram
version=0.3.0
version=0.3.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for creating histograms math.

View File

@ -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.

View File

@ -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);