Thrill  0.1
PolynomialRegression< Type, WithStore > Class Template Reference

Detailed Description

template<typename Type = double, bool WithStore = false>
class tlx::PolynomialRegression< Type, WithStore >

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.

+ Collaboration diagram for PolynomialRegression< Type, WithStore >:

#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...
 
PolynomialRegressionadd (const Type &x, const Type &y)
 add point. this invalidates cached coefficients until next evaluate() More...
 
const Coefficientscoefficients ()
 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 Pointpoint (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< Pointpoints_
 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...
 

Constructor & Destructor Documentation

◆ PolynomialRegression()

PolynomialRegression ( size_t  order)
inline

start new polynomial regression calculation

Definition at line 37 of file polynomial_regression.hpp.

Member Function Documentation

◆ add()

◆ coefficients()

◆ evaluate()

Type evaluate ( const Type &  x)
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().

◆ fit_coefficients()

void fit_coefficients ( )
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().

◆ point()

const Point& point ( size_t  i)
inline

return a point. Only available if WithStore is true.

Definition at line 78 of file polynomial_regression.hpp.

References PolynomialRegression< Type, WithStore >::points_.

◆ r_square()

◆ size()

size_t size ( ) const
inline

Member Data Documentation

◆ coefficients_

Coefficients coefficients_
protected

◆ order_

size_t order_
protected

◆ points_

std::vector<Point> points_
protected

◆ size_

◆ X_

std::vector<Type> X_
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().

◆ Y_

std::vector<Type> Y_
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().


The documentation for this class was generated from the following file: