0.2.3 Correlation

This commit is contained in:
rob tillaart 2022-10-30 18:12:10 +01:00
parent 1ca93bdfa0
commit 3e787c524d
7 changed files with 105 additions and 57 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,6 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

View File

@ -0,0 +1,49 @@
# Change Log Correlation
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [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.
- prepare renaming (5) functions in 0.3.0
## [0.2.1] - 2021-12-14
- update library.json
- update license
- minor edits
## [0.2.0] - 2021-08-26
- Add flags to skip Rsquared and Esquared calculation
- will improve performance calculate
- fixed sign of R correlation coefficient
----
## [0.1.4] - 2021-08-26
- improve performance calculate
## [0.1.3] - 2021-01-16
- add size in constructor,
- add statistical + debug functions
## [0.1.2] - 2020-12-17
- add Arduino-CI + unit tests
- add size()
- add getAvgX() + getAvgY()
## [0.1.1] - 2020-06-05
- fix library.json
## [0.1.0] - 2020-05-17
- initial version

View File

@ -1,27 +1,10 @@
//
// FILE: Correlation.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: Arduino Library to determine correlation between X and Y dataset
//
// HISTORY:
//
// 0.2.2 2022-06-20 optimize getEstimateX() to match getEstimateY();
// optimize averaging within calculate.
// prepare renaming (5) functions in 0.3.0
// 0.2.1 2021-12-14 update library.json, license, minor edits
// 0.2.0 2021-08-26 Add flags to skip Rsquared and Esquared calculation
// will improve performance calculate
// fixed sign of R correlation coefficient
//
// 0.1.4 2021-08-26 improve performance calculate
// 0.1.3 2021-01-16 add size in constructor,
// add statistical + debug functions
// 0.1.2 2020-12-17 add Arduino-CI + unit tests
// + size() + getAvgX() + getAvgY()
// 0.1.1 2020-06-05 fix library.json
// 0.1.0 2020-05-17 initial version
// HISTORY: see cjhangelog.md
#include "Correlation.h"
@ -89,7 +72,7 @@ bool Correlation::calculate(bool forced)
// CALC AVERAGE X, AVERAGE Y
float avgx = 0;
float avgy = 0;
float div_count = 1.0 / _count; // speed up averaging
float div_count = 1.0 / _count; // speed up averaging
for (uint8_t i = 0; i < _count; i++)
{
avgx += _x[i];

View File

@ -2,7 +2,7 @@
//
// FILE: Correlation.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: Calculate Correlation from a small dataset.
// HISTORY: See Correlation.cpp
//
@ -11,93 +11,93 @@
#include "Arduino.h"
#define CORRELATION_LIB_VERSION (F("0.2.2"))
#define CORRELATION_LIB_VERSION (F("0.2.3"))
class Correlation
{
public:
Correlation(uint8_t size = 20); // WARNING calculate memory usage !!
Correlation(uint8_t size = 20); // WARNING calculate memory usage !!
~Correlation();
// returns true if the pair of values is added to internal array.
// returns false when internal array is full.
// returns true if the pair of values is added to internal array.
// returns false when internal array is full.
bool add(float x, float y);
// administrative functions
// administrative functions
uint8_t count() { return _count; };
uint8_t size() { return _size; };
void clear();
// in running mode, adding new pair of values will replace old ones
// this constantly adapts the regression parameters A and B (iff calculate is called)
// in running mode, adding new pair of values will replace old ones
// this constantly adapts the regression parameters A and B (iff calculate is called)
void setRunningCorrelation(bool rc) { _runningMode = rc; };
bool getRunningCorrelation() { return _runningMode; };
// worker, to calculate the correlation parameters.
// MUST be called before retrieving the parameters
// worker, to calculate the correlation parameters.
// MUST be called before retrieving the parameters
// A, B, R, Rsquared, Esquared, avgX and avgY
//
// parameter forced overrules the _needRecalculate flag.
// forced is default false to maintain backwards compatibility
// parameter forced overrules the _needRecalculate flag.
// forced is default false to maintain backwards compatibility
//
// returns false if contains no elements ==> count() == 0
// returns false if contains no elements ==> count() == 0
bool calculate(bool forced = false);
// enables / disables R, Rsquared and Esquared calculation
// This can be used to speed up the calculate function if
// these values are not used in your project.
// enables / disables R, Rsquared and Esquared calculation
// This can be used to speed up the calculate function if
// these values are not used in your project.
void setR2Calculation(bool doR2) { _doR2 = doR2; };
bool getR2Calculation() { return _doR2; };
void setE2Calculation(bool doE2) { _doE2 = doE2; };
bool getE2Calculation() { return _doE2; };
// Y = A + B * X
// note if no elements are added or calculate is not called
// Y = A + B * X
// note if no elements are added or calculate is not called
// the values for A and B are 0
float getA() { return _a; };
float getB() { return _b; };
// getR() returns correlation coefficient (0.2.0 fixed sign)
// getR() returns correlation coefficient (0.2.0 fixed sign)
float getR() { return _r; };
float getRsquare() { return _r * _r; };
// returns sum of the errors squared == indication of 'spread'
// the smaller this value the more the points are on/near one line.
// returns sum of the errors squared == indication of 'spread'
// the smaller this value the more the points are on/near one line.
float getEsquare() { return _sumErrorSquare; };
// get the average values of the datasets (if count > 0)
// 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
// based on the dataset get the estimated values for X and Y
// it uses the last calculated A and B
// library does not return a confidence interval for these values.
// based on the dataset get the estimated values for X and Y
// it uses the last calculated A and B
// library does not return a confidence interval for these values.
float getEstimateY(float x);
float getEstimateX(float y);
// STATISTICAL
// STATISTICAL
float getMinX(); // idem
float getMaxX(); // idem
float getMinY(); // idem
float getMaxY(); // idem
// 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); // returns true if succeeded
float getX(uint8_t index); // idem
float getY(uint8_t index); // idem
// 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
float getX(uint8_t index); // idem
float getY(uint8_t index); // idem
float getSumXY() { return _sumXiYi; }; // replaces getSumXiYi()
float getSumX2() { return _sumXi2; }; // replaces getSumXi2()

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Correlation.git"
},
"version": "0.2.2",
"version": "0.2.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=Correlation
version=0.2.2
version=0.2.3
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

View File

@ -30,6 +30,7 @@
unittest_setup()
{
fprintf(stderr, "CORRELATION_LIB_VERSION: %s\n", (char *) CORRELATION_LIB_VERSION);
}
unittest_teardown()
@ -39,8 +40,6 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "CORRELATION_LIB_VERSION: %s\n", (char *) CORRELATION_LIB_VERSION);
Correlation C;
assertEqual(0, C.count());
assertEqual(20, C.size());