DGtal  0.9.4beta
Public Member Functions | Private Member Functions | Private Attributes
DGtal::SimpleLinearRegression Class Reference

#include <DGtal/math/SimpleLinearRegression.h>

Collaboration diagram for DGtal::SimpleLinearRegression:
[legend]

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)
 
SimpleLinearRegressionoperator= (const SimpleLinearRegression &other)
 

Private Attributes

double myEpsilonZero
 
unsigned int myN
 
std::vector< double > myY
 
std::vector< double > myX
 
double myB [2]
 
std::vector< double > myU
 
double mySumX
 
double mySumX2
 
double mySumY
 
double mySumXY
 
double myD
 
double myNormU2
 

Detailed Description

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.

Note
backport from ImaGene.

Definition at line 73 of file SimpleLinearRegression.h.

Constructor & Destructor Documentation

DGtal::SimpleLinearRegression::~SimpleLinearRegression ( )

Destructor.

DGtal::SimpleLinearRegression::SimpleLinearRegression ( double  eps_zero = 1e-8)

Constructor. The object is empty (and invalid for regression).

Parameters
eps_zerothe value below which the absolute value of the determinant is considered null.
DGtal::SimpleLinearRegression::SimpleLinearRegression ( const SimpleLinearRegression other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

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.

Parameters
xthe x data.
ythe y data.
See also
computeRegression

Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().

template<class XIterator , class YIterator >
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.

Parameters
begin_xan iterator on the first x-data
end_xan iterator after the last x-data
begin_yan iterator on the first y-data
See also
computeRegression

Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().

void DGtal::SimpleLinearRegression::clear ( )
bool DGtal::SimpleLinearRegression::computeRegression ( )

Computes the regression of the current parameters.

Returns
'true' if the regression was valid (non null number of samples, rank of X is 2), 'false' otherwise.

Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().

double DGtal::SimpleLinearRegression::epsilonZero ( ) const
inline
Returns
the epsilon zero value.

Definition at line 190 of file SimpleLinearRegression.h.

References myEpsilonZero.

191  {
192  return myEpsilonZero;
193  }
double myEpsilonZero
Epsilon zero value.
double DGtal::SimpleLinearRegression::estimateVariance ( ) const
Returns
the current estimation of the variance of the Gaussian perturbation (i.e. variance of U).
double DGtal::SimpleLinearRegression::estimateY ( double  x) const

Given a new x, predicts its y (hat{y}) according to the linear regression model.

Parameters
xany value.
Returns
the estimated y value, ie hat{y} = B0 + B1*x.
double DGtal::SimpleLinearRegression::intercept ( ) const
Returns
the intercept of the linear regression (B0 in Y=B0+B1*X).
bool DGtal::SimpleLinearRegression::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
SimpleLinearRegression& DGtal::SimpleLinearRegression::operator= ( const SimpleLinearRegression other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.
void DGtal::SimpleLinearRegression::selfDisplay ( std::ostream &  that_stream) const

Writes/Displays the object on an output stream.

Parameters
that_streamthe output stream where the object is written.
void DGtal::SimpleLinearRegression::setEpsilonZero ( const double  aEpsilonZero)
inline

Set the epsilon zero value, value below which the absolute value of the determinant is considered null.

Parameters
aEpsilonZerothe epsilon zero value.

Definition at line 181 of file SimpleLinearRegression.h.

References myEpsilonZero.

Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().

182  {
183  myEpsilonZero = aEpsilonZero;
184  }
double myEpsilonZero
Epsilon zero value.
double DGtal::SimpleLinearRegression::size ( ) const
inline
Returns
the number of samples.

Definition at line 199 of file SimpleLinearRegression.h.

References myN.

200  {
201  return myN;
202  }
unsigned int myN
Number of samples.
double DGtal::SimpleLinearRegression::slope ( ) const
Returns
the slope of the linear regression (B1 in Y=B0+B1*X).
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.

Parameters
xany x value.
athe expected confidence value for the test (a=0.05 means 95% of confidence).
Returns
the expected interval [min_y, max_y] such that any value y within confirms the current linear model.

Referenced by DGtal::OrderedLinearRegression::backwardSLR(), and DGtal::OrderedLinearRegression::forwardSLR().

Field Documentation

double DGtal::SimpleLinearRegression::myB[2]
private

Linear regression line parameters [0] is the intercept and [1] the slope.

Definition at line 237 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::myD
private

Definition at line 245 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::myEpsilonZero
private

Epsilon zero value.

Definition at line 224 of file SimpleLinearRegression.h.

Referenced by epsilonZero(), and setEpsilonZero().

unsigned int DGtal::SimpleLinearRegression::myN
private

Number of samples.

Definition at line 227 of file SimpleLinearRegression.h.

Referenced by size().

double DGtal::SimpleLinearRegression::myNormU2
private

Definition at line 246 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::mySumX
private

Definition at line 241 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::mySumX2
private

Definition at line 242 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::mySumXY
private

Definition at line 244 of file SimpleLinearRegression.h.

double DGtal::SimpleLinearRegression::mySumY
private

Definition at line 243 of file SimpleLinearRegression.h.

std::vector<double> DGtal::SimpleLinearRegression::myU
private

Definition at line 240 of file SimpleLinearRegression.h.

std::vector<double> DGtal::SimpleLinearRegression::myX
private

Abscissa values of sample points.

Definition at line 233 of file SimpleLinearRegression.h.

std::vector<double> DGtal::SimpleLinearRegression::myY
private

Ordinate values of sample points.

Definition at line 230 of file SimpleLinearRegression.h.


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