DGtal 1.4.0
|
Description of class 'SimpleLinearRegression'. More...
#include <DGtal/math/SimpleLinearRegression.h>
Public Member Functions | |
~SimpleLinearRegression () | |
SimpleLinearRegression (double eps_zero=1e-8) | |
void | clear () |
template<class XIterator , class YIterator > | |
void | addSamples (XIterator begin_x, XIterator end_x, YIterator begin_y) |
void | addSample (const double x, const double y) |
bool | computeRegression () |
double | slope () const |
double | intercept () const |
double | estimateY (double x) const |
double | estimateVariance () const |
std::pair< double, double > | trustIntervalForY (const double x, const double a) const |
void | setEpsilonZero (const double aEpsilonZero) |
double | epsilonZero () const |
double | size () const |
void | selfDisplay (std::ostream &that_stream) const |
bool | isValid () const |
Private Member Functions | |
SimpleLinearRegression (const SimpleLinearRegression &other) | |
SimpleLinearRegression & | operator= (const SimpleLinearRegression &other) |
Private Attributes | |
double | myEpsilonZero |
Epsilon zero value. | |
unsigned int | myN |
Number of samples. | |
std::vector< double > | myY |
Ordinate values of sample points. | |
std::vector< double > | myX |
Abscissa values of sample points. | |
double | myB [2] |
std::vector< double > | myU |
double | mySumX |
double | mySumX2 |
double | mySumY |
double | mySumXY |
double | myD |
double | myNormU2 |
Description of class 'SimpleLinearRegression'.
Aim: Represents a simple linear regression model with 1 regressor constant and 1 variable regressor and n data: Y = X B + U, where U follows Gaussian law N(0, sigma^2 I_n). Y, U are n-vectors, B is a 2-vector, X is the nx2-matrix [(1 x1) ... (1 xn) ] with rank 2.
This class can compute the linear regression coefficients and also performs some tests to check if the data corresponds to a linear model.
Definition at line 73 of file SimpleLinearRegression.h.
DGtal::SimpleLinearRegression::~SimpleLinearRegression | ( | ) |
Destructor.
DGtal::SimpleLinearRegression::SimpleLinearRegression | ( | double | eps_zero = 1e-8 | ) |
Constructor. The object is empty (and invalid for regression).
eps_zero | the value below which the absolute value of the determinant is considered null. |
|
private |
Copy constructor.
other | the object to clone. Forbidden by default. |
void DGtal::SimpleLinearRegression::addSample | ( | const double | x, |
const double | y ) |
Adds the sample (y,x). Does not compute immediately the regression. See 'computeRegression' for computing the regression with the current samples.
x | the x data. |
y | the y data. |
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), DGtal::OrderedLinearRegression::forwardSLR(), and testSimpleRegression().
void DGtal::SimpleLinearRegression::addSamples | ( | XIterator | begin_x, |
XIterator | end_x, | ||
YIterator | begin_y ) |
Adds the samples (y,x). Does not compute immediately the regression. See 'computeRegression' for computing the regression with the current samples.
begin_x | an iterator on the first x-data |
end_x | an iterator after the last x-data |
begin_y | an iterator on the first y-data |
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), DGtal::OrderedLinearRegression::forwardSLR(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().
void DGtal::SimpleLinearRegression::clear | ( | ) |
Clear all datas.
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().
bool DGtal::SimpleLinearRegression::computeRegression | ( | ) |
Computes the regression of the current parameters.
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), DGtal::OrderedLinearRegression::forwardSLR(), testSimpleRegression(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().
|
inline |
Definition at line 190 of file SimpleLinearRegression.h.
References myEpsilonZero.
double DGtal::SimpleLinearRegression::estimateVariance | ( | ) | const |
double DGtal::SimpleLinearRegression::estimateY | ( | double | x | ) | const |
Given a new x, predicts its y (hat{y}) according to the linear regression model.
x | any value. |
double DGtal::SimpleLinearRegression::intercept | ( | ) | const |
Referenced by testSimpleRegression(), testSimpleRegression2(), and testSimpleRegression3().
bool DGtal::SimpleLinearRegression::isValid | ( | ) | const |
Checks the validity/consistency of the object.
|
private |
Assignment.
other | the object to copy. |
void DGtal::SimpleLinearRegression::selfDisplay | ( | std::ostream & | that_stream | ) | const |
Writes/Displays the object on an output stream.
that_stream | the output stream where the object is written. |
|
inline |
Set the epsilon zero value, value below which the absolute value of the determinant is considered null.
aEpsilonZero | the epsilon zero value. |
Definition at line 181 of file SimpleLinearRegression.h.
References myEpsilonZero.
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().
|
inline |
Definition at line 199 of file SimpleLinearRegression.h.
References myN.
Referenced by testSimpleRegressionOrdered().
double DGtal::SimpleLinearRegression::slope | ( | ) | const |
Referenced by testSimpleRegression(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().
std::pair< double, double > DGtal::SimpleLinearRegression::trustIntervalForY | ( | const double | x, |
const double | a ) const |
Given a test confidence value (1-[a]), return the expected interval of value for Y, given a new [x], so that the model is still linear. One may thus check if a new pair (y,x) is still in the current linear model or not.
x | any x value. |
a | the expected confidence value for the test (a=0.05 means 95% of confidence). |
Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().
|
private |
Linear regression line parameters [0] is the intercept and [1] the slope.
Definition at line 237 of file SimpleLinearRegression.h.
|
private |
Definition at line 245 of file SimpleLinearRegression.h.
|
private |
Epsilon zero value.
Definition at line 224 of file SimpleLinearRegression.h.
Referenced by epsilonZero(), and setEpsilonZero().
|
private |
|
private |
Definition at line 246 of file SimpleLinearRegression.h.
|
private |
Definition at line 241 of file SimpleLinearRegression.h.
|
private |
Definition at line 242 of file SimpleLinearRegression.h.
|
private |
Definition at line 244 of file SimpleLinearRegression.h.
|
private |
Definition at line 243 of file SimpleLinearRegression.h.
|
private |
Definition at line 240 of file SimpleLinearRegression.h.
|
private |
Abscissa values of sample points.
Definition at line 233 of file SimpleLinearRegression.h.
|
private |
Ordinate values of sample points.
Definition at line 230 of file SimpleLinearRegression.h.