mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.0 Correlation
This commit is contained in:
parent
4c90b3e839
commit
f8c8180349
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -6,12 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.0] - 2023-01-22
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- commented obsolete functions (not removed yet)
|
||||
- update readme.md
|
||||
- update keywords.txt
|
||||
- fix unit test
|
||||
|
||||
|
||||
## [0.2.3] - 2022-10-30
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
- minor edit unit test
|
||||
|
||||
|
||||
## [0.2.2] - 2022-06-20
|
||||
- optimize getEstimateX() to match getEstimateY();
|
||||
- optimize averaging within calculate.
|
||||
|
@ -1,10 +1,9 @@
|
||||
//
|
||||
// FILE: Correlation.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Arduino Library to determine correlation between X and Y dataset
|
||||
//
|
||||
// HISTORY: see cjhangelog.md
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Correlation.h"
|
||||
@ -243,5 +242,23 @@ float Correlation::getY(uint8_t index)
|
||||
}
|
||||
|
||||
|
||||
float Correlation::getSumXY()
|
||||
{
|
||||
return _sumXiYi;
|
||||
}
|
||||
|
||||
|
||||
float Correlation::getSumX2()
|
||||
{
|
||||
return _sumXi2;
|
||||
}
|
||||
|
||||
|
||||
float Correlation::getSumY2()
|
||||
{
|
||||
return _sumYi2;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,16 +2,15 @@
|
||||
//
|
||||
// FILE: Correlation.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Calculate Correlation from a small dataset.
|
||||
// HISTORY: See Correlation.cpp
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define CORRELATION_LIB_VERSION (F("0.2.3"))
|
||||
#define CORRELATION_LIB_VERSION (F("0.3.0"))
|
||||
|
||||
|
||||
class Correlation
|
||||
@ -74,8 +73,8 @@ public:
|
||||
// get the average values of the datasets (if count > 0)
|
||||
float getAverageX() { return _avgX; }; // will replace getAvgX() in time
|
||||
float getAverageY() { return _avgY; }; // will replace getAvgY() in time
|
||||
float getAvgX() { return _avgX; }; // will be obsolete in future
|
||||
float getAvgY() { return _avgY; }; // will be obsolete in future
|
||||
// float getAvgX() { return _avgX; }; // obsolete in 0.3.0
|
||||
// float getAvgY() { return _avgY; }; // obsolete in 0.3.0
|
||||
|
||||
|
||||
// based on the dataset get the estimated values for X and Y
|
||||
@ -86,6 +85,7 @@ public:
|
||||
|
||||
|
||||
// STATISTICAL
|
||||
// to get bounding box of all x,y pairs.
|
||||
float getMinX(); // idem
|
||||
float getMaxX(); // idem
|
||||
float getMinY(); // idem
|
||||
@ -95,16 +95,16 @@ public:
|
||||
// DEBUGGING - access to internal arrays.
|
||||
bool setXY(uint8_t index, float x, float y); // returns true if succeeded
|
||||
bool setX(uint8_t index, float x); // returns true if succeeded
|
||||
bool setY(uint8_t index, float y); // ss returns true if succeeded
|
||||
bool setY(uint8_t index, float y); // returns true if succeeded
|
||||
float getX(uint8_t index); // idem
|
||||
float getY(uint8_t index); // idem
|
||||
|
||||
float getSumXY() { return _sumXiYi; }; // replaces getSumXiYi()
|
||||
float getSumX2() { return _sumXi2; }; // replaces getSumXi2()
|
||||
float getSumY2() { return _sumYi2; }; // replaces getSumYi2()
|
||||
float getSumXiYi() { return _sumXiYi; }; // obsolete in version 0.3.0
|
||||
float getSumXi2() { return _sumXi2; }; // obsolete in version 0.3.0
|
||||
float getSumYi2() { return _sumYi2; }; // obsolete in version 0.3.0
|
||||
float getSumXY(); // replaces getSumXiYi()
|
||||
float getSumX2(); // replaces getSumXi2()
|
||||
float getSumY2(); // replaces getSumYi2()
|
||||
// float getSumXiYi() { return _sumXiYi; }; // obsolete in version 0.3.0
|
||||
// float getSumXi2() { return _sumXi2; }; // obsolete in version 0.3.0
|
||||
// float getSumYi2() { return _sumYi2; }; // obsolete in version 0.3.0
|
||||
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2022 Rob Tillaart
|
||||
Copyright (c) 2020-2023 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
|
||||
|
@ -29,17 +29,31 @@ This will happen if the **sumXi2** is zero or very small.
|
||||
Use with care.
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/Correlation
|
||||
- https://github.com/RobTillaart/GST - Golden standard test metrics
|
||||
- https://github.com/RobTillaart/RunningAngle
|
||||
- https://github.com/RobTillaart/RunningAverage
|
||||
- https://github.com/RobTillaart/RunningMedian
|
||||
- https://github.com/RobTillaart/statHelpers - combinations & permutations
|
||||
- https://github.com/RobTillaart/Statistic
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "Correlation.h"
|
||||
```
|
||||
|
||||
### Constructor
|
||||
#### Constructor
|
||||
|
||||
- **Correlation(uint8_t size = 20)** allocates the array needed and resets internal admin.
|
||||
Size should be between 1 and 255. Size = 0 will set the size to 20.
|
||||
- **~Correlation()** frees the allocated arrays.
|
||||
|
||||
|
||||
### Base functions
|
||||
#### Base functions
|
||||
|
||||
- **bool add(float x, float y)** adds a pair of **floats** to the internal storage array's.
|
||||
Returns true if the value is added, returns false when internal array is full.
|
||||
@ -76,10 +90,10 @@ quality of the correlation.
|
||||
|
||||
#### Correlation Coefficient R
|
||||
|
||||
Indicative description of the correlation
|
||||
Indicative description of the correlation value.
|
||||
|
||||
| R | correlation |
|
||||
|:-------------:|:--------------|
|
||||
|:--------------:|:--------------|
|
||||
| +1.0 | Perfect |
|
||||
| +0.8 to +1.0 | Very strong |
|
||||
| +0.6 to +0.8 | Strong |
|
||||
@ -94,7 +108,7 @@ Indicative description of the correlation
|
||||
| -1.0 | Perfect |
|
||||
|
||||
|
||||
### Running correlation
|
||||
#### Running correlation
|
||||
|
||||
- **void setRunningCorrelation(bool rc)** sets the internal variable runningMode
|
||||
which allows **add()** to overwrite old elements in the internal arrays.
|
||||
@ -106,7 +120,7 @@ This running correlation allows for more adaptive formula finding e.g. find the
|
||||
relation between temperature and humidity per hour, and how it changes over time.
|
||||
|
||||
|
||||
### Statistical
|
||||
#### Statistical
|
||||
|
||||
These functions give an indication of the "trusted interval" for estimations.
|
||||
The idea is that for **getEstimateX()** the further outside the range defined
|
||||
@ -119,7 +133,7 @@ It also depends on **R** of course. Idem for **getEstimateY()**
|
||||
- **float getMaxY()** idem
|
||||
|
||||
|
||||
### Debugging / educational
|
||||
#### Debugging / educational
|
||||
|
||||
Normally not used. For all these functions index should be < count!
|
||||
|
||||
@ -134,33 +148,35 @@ Returns true if succeeded.
|
||||
- **float getSumY2()** returns sum(Yi \* Yi).
|
||||
|
||||
|
||||
### Obsolete in 0.3.0
|
||||
#### Obsolete since 0.3.0
|
||||
|
||||
To improve readability the following functions are replaced
|
||||
To improve readability the following functions are replaced.
|
||||
|
||||
- **float getAvgX()** returns average X.
|
||||
- **float getAvgY()** returns average Y.
|
||||
- **float getSumXiYi()** returns sum(Xi \* Yi).
|
||||
- **float getSumXi2()** returns sum(Xi \* Xi).
|
||||
- **float getSumYi2()** returns sum(Yi \* Yi).
|
||||
- **float getAvgX()** ==> **getAverageX()**
|
||||
- **float getAvgY()** ==> **getAverageY()**
|
||||
- **float getSumXiYi()** ==> **getSumXY()**
|
||||
- **float getSumXi2()** ==> **getSumX2()**
|
||||
- **float getSumYi2()** ==> **getSumY2()**
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- Template version?
|
||||
The constructor should get a TYPE parameter, as this
|
||||
allows smaller data types to be analysed taking less memory.
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
|
||||
#### Should
|
||||
|
||||
- examples
|
||||
- real world if possible.
|
||||
|
||||
#### Could
|
||||
|
||||
### 0.3.0
|
||||
- Template version?
|
||||
The constructor should get a TYPE parameter, as this
|
||||
allows smaller data types to be analysed taking less memory.
|
||||
- move code from .h to .cpp
|
||||
|
||||
- fix naming in examples as some function names are replaced.
|
||||
- are the getSUmXiYi indeed worse?
|
||||
#### Wont
|
||||
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See example
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-17
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Correlation.h"
|
||||
@ -49,11 +49,11 @@ void setup()
|
||||
Serial.print("Esq:\t");
|
||||
Serial.println(C.getEsquare(), 3);
|
||||
Serial.print("SumXiYi:\t");
|
||||
Serial.println(C.getSumXiYi(), 1);
|
||||
Serial.println(C.getSumXY(), 1);
|
||||
Serial.print("SumXi2:\t\t");
|
||||
Serial.println(C.getSumXi2(), 1);
|
||||
Serial.println(C.getSumX2(), 1);
|
||||
Serial.print("SumYi2:\t\t");
|
||||
Serial.println(C.getSumYi2(), 1);
|
||||
Serial.println(C.getSumY2(), 1);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-17
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
/*
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-17
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Correlation.h"
|
||||
|
@ -3,6 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-18
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
// performance test: only ADD and CALCULATE as these are the most used
|
||||
// and could be optimized in the future
|
||||
|
@ -0,0 +1,43 @@
|
||||
|
||||
correlation_performance.ino
|
||||
|
||||
CORRELATION_LIB_VERSION: 0.3.0
|
||||
ADD
|
||||
12.20
|
||||
|
||||
CALCULATE - needed
|
||||
2768
|
||||
|
||||
CALCULATE - no new values added
|
||||
12
|
||||
|
||||
getEstimateX
|
||||
24
|
||||
|
||||
getEstimateY
|
||||
20
|
||||
|
||||
getMaxX
|
||||
84
|
||||
|
||||
getMinX
|
||||
84
|
||||
|
||||
===================================
|
||||
|
||||
|
||||
ADD - fill arrays again
|
||||
11.80
|
||||
|
||||
disable R2 and E2 math from calculate
|
||||
|
||||
CALCULATE - needed
|
||||
1776
|
||||
|
||||
CALCULATE - no new values added
|
||||
8
|
||||
|
||||
CALCULATE - no new values added but forced
|
||||
1780
|
||||
|
||||
Done...
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-17
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Correlation.h"
|
||||
|
@ -3,8 +3,10 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-18
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
// performance test: only ADD and CALCULATE as these are the most used
|
||||
// performance test:
|
||||
// only ADD and CALCULATE as these are the most used
|
||||
// and could be optimized in the future
|
||||
|
||||
|
||||
@ -49,9 +51,9 @@ void setup()
|
||||
Serial.println(stop - start);
|
||||
Serial.println();
|
||||
|
||||
Serial.println(C.getSumXiYi(), 6);
|
||||
Serial.println(C.getSumXi2(), 6);
|
||||
Serial.println(C.getSumYi2(), 6);
|
||||
Serial.println(C.getSumXY(), 6);
|
||||
Serial.println(C.getSumX2(), 6);
|
||||
Serial.println(C.getSumY2(), 6);
|
||||
Serial.println(C.getRsquare(), 6);
|
||||
Serial.println(C.getR(), 6);
|
||||
Serial.print("A: ");
|
||||
@ -62,8 +64,8 @@ void setup()
|
||||
|
||||
|
||||
start = micros();
|
||||
float COV = C.getSumXiYi() / ((C.count() - 1));
|
||||
float R = C.getSumXiYi() / sqrt(C.getSumXi2() * C.getSumYi2());
|
||||
float COV = C.getSumXY() / ((C.count() - 1));
|
||||
float R = C.getSumXY() / sqrt(C.getSumX2() * C.getSumY2());
|
||||
stop = micros();
|
||||
Serial.println(stop - start);
|
||||
Serial.print("COV: ");
|
||||
@ -94,9 +96,9 @@ void test()
|
||||
C.calculate();
|
||||
|
||||
Serial.println("---------------");
|
||||
Serial.println(C.getSumXiYi(), 6);
|
||||
Serial.println(C.getSumXi2(), 6);
|
||||
Serial.println(C.getSumYi2(), 6);
|
||||
Serial.println(C.getSumXY(), 6);
|
||||
Serial.println(C.getSumX2(), 6);
|
||||
Serial.println(C.getSumY2(), 6);
|
||||
Serial.println(C.getRsquare(), 6);
|
||||
Serial.println(C.getR(), 6);
|
||||
Serial.print("A: ");
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-05-18
|
||||
// PUPROSE: demo of the Correlation Library
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/Correlation
|
||||
|
||||
|
||||
#include "Correlation.h"
|
||||
|
@ -46,15 +46,6 @@ getSumX2 KEYWORD2
|
||||
getSumY2 KEYWORD2
|
||||
|
||||
|
||||
### remove 0.3.0
|
||||
|
||||
getAvgX KEYWORD2
|
||||
getAvgY KEYWORD2
|
||||
getSumXiYi KEYWORD2
|
||||
getSumXi2 KEYWORD2
|
||||
getSumYi2 KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
CORRELATION_LIB_VERSION LITERAL1
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Correlation.git"
|
||||
},
|
||||
"version": "0.2.3",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Correlation
|
||||
version=0.2.3
|
||||
version=0.3.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library to determine correlation between X and Y dataset
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-12-03
|
||||
// PURPOSE: unit tests for the Correlation library
|
||||
// https://github.com/RobTillaart/
|
||||
// https://github.com/RobTillaart/Correlation
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
@ -27,12 +27,12 @@
|
||||
#include "Correlation.h"
|
||||
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "CORRELATION_LIB_VERSION: %s\n", (char *) CORRELATION_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
@ -115,8 +115,8 @@ unittest(test_get_statistics)
|
||||
C.add(6, 15);
|
||||
C.calculate();
|
||||
|
||||
assertEqualFloat(4, C.getAvgX(), 0.0001);
|
||||
assertEqualFloat(11, C.getAvgY(), 0.0001);
|
||||
assertEqualFloat(4, C.getAverageX(), 0.0001);
|
||||
assertEqualFloat(11, C.getAverageY(), 0.0001);
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ unittest(test_estimate)
|
||||
{
|
||||
fprintf(stderr, "%d\t%f\n", i, C.getEstimateX(i));
|
||||
}
|
||||
fprintf(stderr, "estimate X\n");
|
||||
fprintf(stderr, "estimate Y\n");
|
||||
for (int i = 15; i < 20; i++)
|
||||
{
|
||||
fprintf(stderr, "%d\t%f\n", i, C.getEstimateY(i));
|
||||
@ -152,11 +152,13 @@ unittest(test_calculate)
|
||||
|
||||
assertFalse(C.calculate());
|
||||
assertFalse(C.calculate(true));
|
||||
|
||||
C.add(2, 7);
|
||||
C.add(3, 9);
|
||||
C.add(4, 10);
|
||||
C.add(5, 14);
|
||||
C.add(6, 15);
|
||||
|
||||
assertTrue(C.calculate());
|
||||
assertTrue(C.calculate(true));
|
||||
}
|
||||
@ -182,4 +184,5 @@ unittest(test_calculate_flags)
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
// --END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user