Thrill
0.1
|
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 33 of file polynomial_regression.hpp.
#include <polynomial_regression.hpp>
Classes | |
struct | Coefficients |
struct | Point |
2D point More... | |
Public Member Functions | |
PolynomialRegression (size_t order) | |
start new polynomial regression calculation More... | |
PolynomialRegression & | add (const Type &x, const Type &y) |
add point. this invalidates cached coefficients until next evaluate() More... | |
const Coefficients & | coefficients () |
return coefficients vector More... | |
Type | evaluate (const Type &x) |
returns value of y predicted by the polynomial for a given value of x 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... | |
size_t | size () const |
number of points More... | |
Protected Member Functions | |
void | fit_coefficients () |
polynomial regression by inverting a Vandermonde matrix. More... | |
Protected Attributes | |
Coefficients | coefficients_ |
cached coefficients More... | |
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... | |
|
inline |
start new polynomial regression calculation
Definition at line 37 of file polynomial_regression.hpp.
|
inline |
add point. this invalidates cached coefficients until next evaluate()
Definition at line 52 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::coefficients_, PolynomialRegression< Type, WithStore >::order_, PolynomialRegression< Type, WithStore >::points_, PolynomialRegression< Type, WithStore >::size_, PolynomialRegression< Type, WithStore >::Point::x, PolynomialRegression< Type, WithStore >::X_, PolynomialRegression< Type, WithStore >::Point::y, and PolynomialRegression< Type, WithStore >::Y_.
|
inline |
return coefficients vector
Definition at line 127 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::coefficients_, and PolynomialRegression< Type, WithStore >::fit_coefficients().
Referenced by PolynomialRegression< Type, WithStore >::evaluate().
|
inline |
returns value of y predicted by the polynomial for a given value of x
Definition at line 122 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::coefficients(), and PolynomialRegression< Type, WithStore >::Coefficients::evaluate().
Referenced by PolynomialRegression< Type, WithStore >::r_square().
|
inlineprotected |
polynomial regression by inverting a Vandermonde matrix.
Definition at line 154 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::order_, and tlx::swap().
Referenced by PolynomialRegression< Type, WithStore >::coefficients().
|
inline |
return a point. Only available if WithStore is true.
Definition at line 78 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::points_.
|
inline |
get r^2. Only available if WithStore is true.
mean value of y
Definition at line 96 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::evaluate(), PolynomialRegression< Type, WithStore >::points_, PolynomialRegression< Type, WithStore >::size_, PolynomialRegression< Type, WithStore >::Point::y, and PolynomialRegression< Type, WithStore >::Y_.
|
inline |
number of points
Definition at line 42 of file polynomial_regression.hpp.
References PolynomialRegression< Type, WithStore >::size_.
Referenced by PolynomialRegression< Type, WithStore >::Coefficients::evaluate().
|
protected |
cached coefficients
Definition at line 151 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add(), and PolynomialRegression< Type, WithStore >::coefficients().
|
protected |
polynomial order
Definition at line 136 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add(), and PolynomialRegression< Type, WithStore >::fit_coefficients().
|
protected |
list of stored points if WithStore, else empty.
Definition at line 139 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add(), PolynomialRegression< Type, WithStore >::point(), and PolynomialRegression< Type, WithStore >::r_square().
|
protected |
number of points added
Definition at line 142 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add(), PolynomialRegression< Type, WithStore >::r_square(), and PolynomialRegression< Type, WithStore >::size().
|
protected |
X_ = vector that stores values of sigma(x_i^2n)
Definition at line 145 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add().
|
protected |
Y_ = vector to store values of sigma(x_i^order * y_i)
Definition at line 148 of file polynomial_regression.hpp.
Referenced by PolynomialRegression< Type, WithStore >::add(), and PolynomialRegression< Type, WithStore >::r_square().