DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
DGtal::SimpleLinearRegression Class Reference

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

Private Attributes

double myEpsilonZero
 Epsilon zero value. More...
 
unsigned int myN
 Number of samples. More...
 
std::vector< double > myY
 Ordinate values of sample points. More...
 
std::vector< double > myX
 Abscissa values of sample points. More...
 
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

◆ ~SimpleLinearRegression()

DGtal::SimpleLinearRegression::~SimpleLinearRegression ( )

Destructor.

◆ SimpleLinearRegression() [1/2]

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.

◆ SimpleLinearRegression() [2/2]

DGtal::SimpleLinearRegression::SimpleLinearRegression ( const SimpleLinearRegression other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

◆ addSample()

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(), DGtal::OrderedLinearRegression::forwardSLR(), and testSimpleRegression().

◆ addSamples()

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(), DGtal::OrderedLinearRegression::forwardSLR(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().

◆ clear()

void DGtal::SimpleLinearRegression::clear ( )

◆ computeRegression()

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(), DGtal::OrderedLinearRegression::forwardSLR(), testSimpleRegression(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().

◆ epsilonZero()

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

Definition at line 190 of file SimpleLinearRegression.h.

191 {
192 return myEpsilonZero;
193 }
double myEpsilonZero
Epsilon zero value.

References myEpsilonZero.

◆ estimateVariance()

double DGtal::SimpleLinearRegression::estimateVariance ( ) const
Returns
the current estimation of the variance of the Gaussian perturbation (i.e. variance of U).

◆ estimateY()

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.

◆ intercept()

double DGtal::SimpleLinearRegression::intercept ( ) const
Returns
the intercept of the linear regression (B0 in Y=B0+B1*X).

Referenced by testSimpleRegression(), testSimpleRegression2(), and testSimpleRegression3().

◆ isValid()

bool DGtal::SimpleLinearRegression::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ operator=()

SimpleLinearRegression & DGtal::SimpleLinearRegression::operator= ( const SimpleLinearRegression other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

◆ selfDisplay()

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.

◆ setEpsilonZero()

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.

182 {
183 myEpsilonZero = aEpsilonZero;
184 }

References myEpsilonZero.

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

◆ size()

double DGtal::SimpleLinearRegression::size ( ) const
inline
Returns
the number of samples.

Definition at line 199 of file SimpleLinearRegression.h.

200 {
201 return myN;
202 }
unsigned int myN
Number of samples.

References myN.

Referenced by testSimpleRegressionOrdered().

◆ slope()

double DGtal::SimpleLinearRegression::slope ( ) const
Returns
the slope of the linear regression (B1 in Y=B0+B1*X).

Referenced by testSimpleRegression(), testSimpleRegression2(), testSimpleRegression3(), and testSimpleRegressionOrdered().

◆ trustIntervalForY()

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

◆ myB

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.

◆ myD

double DGtal::SimpleLinearRegression::myD
private

Definition at line 245 of file SimpleLinearRegression.h.

◆ myEpsilonZero

double DGtal::SimpleLinearRegression::myEpsilonZero
private

Epsilon zero value.

Definition at line 224 of file SimpleLinearRegression.h.

Referenced by epsilonZero(), and setEpsilonZero().

◆ myN

unsigned int DGtal::SimpleLinearRegression::myN
private

Number of samples.

Definition at line 227 of file SimpleLinearRegression.h.

Referenced by size().

◆ myNormU2

double DGtal::SimpleLinearRegression::myNormU2
private

Definition at line 246 of file SimpleLinearRegression.h.

◆ mySumX

double DGtal::SimpleLinearRegression::mySumX
private

Definition at line 241 of file SimpleLinearRegression.h.

◆ mySumX2

double DGtal::SimpleLinearRegression::mySumX2
private

Definition at line 242 of file SimpleLinearRegression.h.

◆ mySumXY

double DGtal::SimpleLinearRegression::mySumXY
private

Definition at line 244 of file SimpleLinearRegression.h.

◆ mySumY

double DGtal::SimpleLinearRegression::mySumY
private

Definition at line 243 of file SimpleLinearRegression.h.

◆ myU

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

Definition at line 240 of file SimpleLinearRegression.h.

◆ myX

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

Abscissa values of sample points.

Definition at line 233 of file SimpleLinearRegression.h.

◆ myY

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: