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

Description of class 'OrderedLinearRegression'. More...

#include <DGtal/math/OrderedLinearRegression.h>

Public Member Functions

 ~OrderedLinearRegression ()
 
 OrderedLinearRegression (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)
 
void forwardSLR (SimpleLinearRegression &linearModel, const unsigned int n=4, const double alpha=0.01) const
 
void backwardSLR (SimpleLinearRegression &linearModel, const unsigned int n=4, const double alpha=0.01) const
 
void selfDisplay (std::ostream &that_stream) const
 
bool isValid () const
 

Private Member Functions

 OrderedLinearRegression (const OrderedLinearRegression &other)
 
OrderedLinearRegressionoperator= (const OrderedLinearRegression &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...
 

Detailed Description

Description of class 'OrderedLinearRegression'.

Aim: Utility based on SimpleLinearRegression to compute regression on ordered data. Hence, we can obtain linear fitting with interval trust from the left to the right (resp. from the right to the left) of the data.

Note
backport from ImaGene.

Definition at line 65 of file OrderedLinearRegression.h.

Constructor & Destructor Documentation

◆ ~OrderedLinearRegression()

DGtal::OrderedLinearRegression::~OrderedLinearRegression ( )
inline

Destructor.

Definition at line 73 of file OrderedLinearRegression.h.

74 {}

◆ OrderedLinearRegression() [1/2]

DGtal::OrderedLinearRegression::OrderedLinearRegression ( double  eps_zero = 1e-8)
inline

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

Parameters
[in]eps_zerothe value below which the absolute value of the determinant is considered null.

Definition at line 83 of file OrderedLinearRegression.h.

83 :
84 myEpsilonZero(eps_zero),
85 myN(0)
86 {}
double myEpsilonZero
Epsilon zero value.
unsigned int myN
Number of samples.

◆ OrderedLinearRegression() [2/2]

DGtal::OrderedLinearRegression::OrderedLinearRegression ( const OrderedLinearRegression other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

◆ addSample()

void DGtal::OrderedLinearRegression::addSample ( const double  x,
const double  y 
)
inline

Adds the sample (x,y). Does not compute immediately the regression but copies the data. See 'forwardSLR' or 'backwardSLR' for computing the regression with the current samples.

Parameters
[in]xthe x data.
[in]ythe y data.
See also
forwardSLR backwardSLR

Definition at line 131 of file OrderedLinearRegression.h.

132 {
133 myX.push_back( x );
134 myY.push_back( y );
135 ++myN;
136 }
std::vector< double > myX
Abscissa values of sample points.
std::vector< double > myY
Ordinate values of sample points.

References myN, myX, and myY.

Referenced by addSamples().

◆ addSamples()

template<class XIterator , class YIterator >
void DGtal::OrderedLinearRegression::addSamples ( XIterator  begin_x,
XIterator  end_x,
YIterator  begin_y 
)
inline

Adds the samples (x,y). Does not compute immediately the regression but copies the data. See 'forwardSLR' or 'backwardSLR' for computing the regression with the current samples.

Parameters
[in]begin_xan iterator on the first x-data
[in]end_xan iterator after the last x-data
[in]begin_yan iterator on the first y-data
See also
forwardSLR backwardSLR

Definition at line 111 of file OrderedLinearRegression.h.

112 {
113 for ( ; begin_x != end_x; ++begin_x, ++begin_y )
114 {
115 addSample( *begin_x, *begin_y );
116 }
117 }
void addSample(const double x, const double y)

References addSample().

Referenced by testSimpleRegressionOrdered().

◆ backwardSLR()

void DGtal::OrderedLinearRegression::backwardSLR ( SimpleLinearRegression linearModel,
const unsigned int  n = 4,
const double  alpha = 0.01 
) const
inline

Returns the slope of the last straight part of the data. The straightness is evaluated through a statistic test based on a simple linear regression (SLR) model. It requires two parameters: n is the minimum number of samples to fit a linear model, 1-[ alpha] is the proportion of accepted linear model of the test (99%, alpha=0.01, means that 99% of all linear model with a Gaussian noise are accepted).

Parameters
[in]nthe minimum number of samples greater than 3 (default value is 4).
[in]alphais the proportion of rejected linear model (the ones with big variance, default value is 0.01).
[out]linearModelthe SLR instance of the last straight part of the data.

Definition at line 200 of file OrderedLinearRegression.h.

203 {
204 linearModel.setEpsilonZero(myEpsilonZero);
205 linearModel.clear();
206 std::vector<double>::const_reverse_iterator itx = myX.rbegin();
207 std::vector<double>::const_reverse_iterator itxe = myX.rend();
208 std::vector<double>::const_reverse_iterator ity = myY.rbegin();
209 linearModel.addSamples( itx, itx + n, ity );
210 linearModel.computeRegression();
211 itx += n;
212 ity += n;
213 unsigned int l = myX.size() - n + 1;
214 for ( ; itx != itxe; ++itx, ++ity, --l )
215 {
216 std::pair<double,double> ic;
217 ic = linearModel.trustIntervalForY( *itx, alpha );
218 if ( ( *ity < ic.first ) || ( *ity > ic.second ) )
219 break;
220 linearModel.addSample( *itx, *ity );
221 linearModel.computeRegression();
222 }
223 }

References DGtal::SimpleLinearRegression::addSample(), DGtal::SimpleLinearRegression::addSamples(), DGtal::SimpleLinearRegression::clear(), DGtal::SimpleLinearRegression::computeRegression(), myEpsilonZero, myX, myY, DGtal::SimpleLinearRegression::setEpsilonZero(), and DGtal::SimpleLinearRegression::trustIntervalForY().

Referenced by testSimpleRegressionOrdered().

◆ clear()

void DGtal::OrderedLinearRegression::clear ( )
inline

Clears the data.

Definition at line 91 of file OrderedLinearRegression.h.

92 {
93 myX.clear();
94 myY.clear();
95 myN = 0;
96 }

References myN, myX, and myY.

◆ forwardSLR()

void DGtal::OrderedLinearRegression::forwardSLR ( SimpleLinearRegression linearModel,
const unsigned int  n = 4,
const double  alpha = 0.01 
) const
inline

Returns the slope of the first straight part of the data. The straightness is evaluated through a statistic test based on a simple linear regression (SLR) model. It requires two parameters: n is the minimum number of samples to fit a linear model, 1-[ alpha] is the proportion of accepted linear model of the test (99%, alpha=0.01, means that 99% of all linear model with a Gaussian noise are accepted).

Parameters
[in]nthe minimum number of samples greater than 3 (default value is 4).
[in]alphais the proportion of rejected linear model (the ones with big variance, default value is 0.01).
[out]linearModelthe SLR instance of the first straight part of the data.

Definition at line 157 of file OrderedLinearRegression.h.

160 {
161 linearModel.setEpsilonZero(myEpsilonZero);
162 linearModel.clear();
163 std::vector<double>::const_iterator itx = myX.begin();
164 std::vector<double>::const_iterator itxe = myX.end();
165 std::vector<double>::const_iterator ity = myY.begin();
166 linearModel.addSamples( itx, itx + n, ity );
167 linearModel.computeRegression();
168 itx += n;
169 ity += n;
170 unsigned int l = myX.size() - n + 1;
171 for ( ; itx != itxe; ++itx, ++ity, --l )
172 {
173 std::pair<double,double> ic;
174 ic = linearModel.trustIntervalForY( *itx, alpha );
175 if ( ( *ity < ic.first ) || ( *ity > ic.second ) )
176 break;
177 linearModel.addSample( *itx, *ity );
178 linearModel.computeRegression();
179 }
180 }

References DGtal::SimpleLinearRegression::addSample(), DGtal::SimpleLinearRegression::addSamples(), DGtal::SimpleLinearRegression::clear(), DGtal::SimpleLinearRegression::computeRegression(), myEpsilonZero, myX, myY, DGtal::SimpleLinearRegression::setEpsilonZero(), and DGtal::SimpleLinearRegression::trustIntervalForY().

Referenced by testSimpleRegressionOrdered().

◆ isValid()

bool DGtal::OrderedLinearRegression::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 241 of file OrderedLinearRegression.h.

242 {
243 return true;
244 }

◆ operator=()

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

Assignment.

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

◆ selfDisplay()

void DGtal::OrderedLinearRegression::selfDisplay ( std::ostream &  that_stream) const
inline

Writes/Displays the object on an output stream.

Parameters
that_streamthe output stream where the object is written.

Definition at line 232 of file OrderedLinearRegression.h.

233 {
234 that_stream << "[OrderedLinearRegression] Number of samples="<< myN;
235 }

References myN.

Field Documentation

◆ myEpsilonZero

double DGtal::OrderedLinearRegression::myEpsilonZero
private

Epsilon zero value.

Definition at line 252 of file OrderedLinearRegression.h.

Referenced by backwardSLR(), and forwardSLR().

◆ myN

unsigned int DGtal::OrderedLinearRegression::myN
private

Number of samples.

Definition at line 255 of file OrderedLinearRegression.h.

Referenced by addSample(), clear(), and selfDisplay().

◆ myX

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

Abscissa values of sample points.

Definition at line 261 of file OrderedLinearRegression.h.

Referenced by addSample(), backwardSLR(), clear(), and forwardSLR().

◆ myY

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

Ordinate values of sample points.

Definition at line 258 of file OrderedLinearRegression.h.

Referenced by addSample(), backwardSLR(), clear(), and forwardSLR().


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