https://github.com/arkhipenko/runninglinreg
Implementation of dynamic mean squared error linear regression f(t)
https://github.com/arkhipenko/runninglinreg
Last synced: 6 months ago
JSON representation
Implementation of dynamic mean squared error linear regression f(t)
- Host: GitHub
- URL: https://github.com/arkhipenko/runninglinreg
- Owner: arkhipenko
- License: bsd-3-clause
- Created: 2022-06-08T03:05:41.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-08T11:26:31.000Z (about 4 years ago)
- Last Synced: 2024-11-22T21:31:47.320Z (over 1 year ago)
- Language: C++
- Size: 4.88 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Running Linreg
### Implementation of dynamic MSE linear regression f(t)
##### Version 1.0.0
### Description
`Running Linreg` (or Linear Regression) implements dynamic (and fast) recalculated mean squared error linear regression f(t) based on a pre-defined number of points.
Each time a new point is added to the set, the **slope** and **intercept** values are recalculated based on the added point values **only.**
### Detailed explanation
Imagine you are calculating the closest linear representation of a time series array of 200 points. As you continue measuring, new points are added on the right side, and every time a point is added on the right beyond initial 200, another point is dropped on the left. Thus you maintain a Running Array of measurement points, and linear regression characteristics of a line closely approximating the time-series. As only two points are changing at every measurement (the left-most is dropped and the right-most is added), the library does not need to recalculate slope/intercept based on all 200 points, just the effect of those two, hence the speed.
### Usage:
Construct the `RunningLinreg` object giving it a pointer to a `std::queue` object to hold `point_t` objects and anticipated size of the time-series array
```c++
RunningLinreg(std::queue* points, size_t n);
```
Use this method to add a point to the set:
```c++
addPoint(point_t point);
```
Then query recalculated **slope** and **intercept** values using methods:
```c++
double slope();
double intercept();
```
Methods
```c++
double count();
int16_t status();
```
could be used to query total number of points already added, and if errors were encountered by the last method call.
The point definition is:
```c++
typedef struct {
double t;
double value;
} point_t;
```
and a list of error codes is below:
```c++
#define LINREG_OK 0
#define LINREG_ERR (-1) // general error
#define LINREG_NUL (-2) // points pointer is NULL
#define LINREG_DEN (-3) // denominator is zero
```
### Practical applications
- Peak detection
- PID control
**Enjoy!**
###### Changelog:
v1.0.0:
- 2022-06-08 - initial release