tlx
|
Calculate the regression polynomial \( a_0+a_1x^1+a_2x^2+\cdots+a_nx^n \) from a list of 2D points. More...
#include <polynomial_regression.hpp>
Classes | |
struct | Coefficients |
polynomial stored as the coefficients of \( a_0+a_1 x^1+a_2 x^2+\cdots+a_n x^n \) More... | |
struct | Point |
2D point More... | |
Public Member Functions | |
PolynomialRegression (size_t order) | |
start new polynomial regression calculation More... | |
size_t | size () const |
number of points More... | |
PolynomialRegression & | add (const Type &x, const Type &y) |
add point. this invalidates cached coefficients until next evaluate() More... | |
const Point & | point (size_t i) |
return a point. Only available if WithStore is true. More... | |
Type | r_square () |
get r^2. Only available if WithStore is true. More... | |
Type | evaluate (const Type &x) |
returns value of y predicted by the polynomial for a given value of x More... | |
const Coefficients & | coefficients () |
return coefficients vector More... | |
Protected Member Functions | |
void | fit_coefficients () |
polynomial regression by inverting a Vandermonde matrix. More... | |
Protected Attributes | |
size_t | order_ |
polynomial order More... | |
std::vector< Point > | points_ |
list of stored points if WithStore, else empty. More... | |
size_t | size_ |
number of points added More... | |
std::vector< Type > | X_ |
X_ = vector that stores values of sigma(x_i^2n) More... | |
std::vector< Type > | Y_ |
Y_ = vector to store values of sigma(x_i^order * y_i) More... | |
Coefficients | coefficients_ |
cached coefficients More... | |
Calculate the regression polynomial \( a_0+a_1x^1+a_2x^2+\cdots+a_nx^n \) from a list of 2D points.
See also https://en.wikipedia.org/wiki/Polynomial_regression
If WithStore is false, then the sums are aggregated directly such that the class retains O(1) size independent of the number of points. if WithStore is true then the points are stored in a vector and can be retrieved.
Definition at line 41 of file polynomial_regression.hpp.
|
inline |
start new polynomial regression calculation
Definition at line 45 of file polynomial_regression.hpp.
|
inline |
add point. this invalidates cached coefficients until next evaluate()
Definition at line 60 of file polynomial_regression.hpp.
|
inline |
return coefficients vector
Definition at line 135 of file polynomial_regression.hpp.
|
inline |
returns value of y predicted by the polynomial for a given value of x
Definition at line 130 of file polynomial_regression.hpp.
|
inlineprotected |
polynomial regression by inverting a Vandermonde matrix.
Definition at line 162 of file polynomial_regression.hpp.
|
inline |
return a point. Only available if WithStore is true.
Definition at line 86 of file polynomial_regression.hpp.
|
inline |
get r^2. Only available if WithStore is true.
mean value of y
Definition at line 104 of file polynomial_regression.hpp.
|
inline |
number of points
Definition at line 50 of file polynomial_regression.hpp.
|
protected |
cached coefficients
Definition at line 159 of file polynomial_regression.hpp.
|
protected |
polynomial order
Definition at line 144 of file polynomial_regression.hpp.
|
protected |
list of stored points if WithStore, else empty.
Definition at line 147 of file polynomial_regression.hpp.
|
protected |
number of points added
Definition at line 150 of file polynomial_regression.hpp.
|
protected |
X_ = vector that stores values of sigma(x_i^2n)
Definition at line 153 of file polynomial_regression.hpp.
|
protected |
Y_ = vector to store values of sigma(x_i^order * y_i)
Definition at line 156 of file polynomial_regression.hpp.