32#include "DGtal/base/Common.h"
33#include "ConfigTest.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/math/SimpleLinearRegression.h"
36#include "DGtal/math/OrderedLinearRegression.h"
51 unsigned int nbok = 0;
65 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
66 <<
"Regression == true" << std::endl;
72 nbok += ( std::abs(SLR.
slope() - 1) < 0.01) ? 1 : 0;
74 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
75 <<
"slope == 1" << std::endl;
76 nbok += ( std::abs(SLR.
intercept() - 0.0) < 0.01) ? 1 : 0;
78 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
79 <<
"intercept == 0" << std::endl;
92 unsigned int nbok = 0;
99 std::vector<double> x;
104 std::vector<double> y;
110 SLR.
addSamples( x.begin(), x.end(), y.begin());
114 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
115 <<
"Regression == true" << std::endl;
121 nbok += ( std::abs(SLR.
slope() - 1) < 0.1) ? 1 : 0;
123 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
124 <<
"|slope| =~= 1" << std::endl;
125 nbok += ( std::abs(SLR.
intercept() ) < 0.1) ? 1 : 0;
127 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
128 <<
"|intercept| < (10^-1)" << std::endl;
140 unsigned int nbok = 0;
147 double x[] = {5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14, 14.5, 15, 15.5, 16, 16.5, 17, 17.5, 18, 18.5, 19, 19.5, 20};
149 double y[] = {0.00366568,0.0376311,0.0173014,0.0205614,0.00139069,0.0108356,0.000985302,0.00360493,0.00808965,0.014353,0.00497899,0.0115723,0.00651013,0.00758458,0.00392271,0.00752993,0.00597875,0.00841424,0.00704232,0.00848176,0.00676336,0.00564121,0.00584509,0.00702953,0.00591087,0.00745775,0.00618557,0.00727818,0.00534952,0.0053612,0.00426009};
151 std::vector<double> xx(31),yy(31);
152 for(
unsigned int i=0; i < 31; ++i)
154 xx[i] = std::log(x[i]);
155 yy[i] = std::log(y[i]);
158 SLR.
addSamples( xx.begin(), xx.end(), yy.begin());
162 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
163 <<
"Regression == true" << std::endl;
169 nbok += ( std::abs(SLR.
slope() + 0.25) < 0.1) ? 1 : 0;
171 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
172 <<
"|slope| =~= 1" << std::endl;
183 unsigned int nbok = 0;
188 double x[] = {1, 2, 2.5, 3, 4 ,5 , 6};
189 double y[] = {1, 2, 2.5, 2.9, 4.1, 15, 25.9};
206 nbok += ( SLR.
slope() < 5 ) ? 1 : 0;
208 trace.
info() <<
"Forward slope = " << forward.
slope() <<
" " << forward.
size() << std::endl;
209 nbok += (( forward.
size() == 5 ) && ( forward.
slope() < 1.05 )) ? 1 : 0;
211 trace.
info() <<
"Backward slope = " << backward.
slope() <<
" " << backward.
size() << std::endl;
212 nbok += (( backward.
slope() < 11 ) && ( backward.
slope() > 10 )) ? 1 : 0;
224int main(
int argc,
char** argv )
228 for (
int i = 0; i < argc; ++i )
236 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Description of class 'OrderedLinearRegression'.
void backwardSLR(SimpleLinearRegression &linearModel, const unsigned int n=4, const double alpha=0.01) const
void addSamples(XIterator begin_x, XIterator end_x, YIterator begin_y)
void forwardSLR(SimpleLinearRegression &linearModel, const unsigned int n=4, const double alpha=0.01) const
Description of class 'SimpleLinearRegression'.
void addSample(const double x, const double y)
void addSamples(XIterator begin_x, XIterator end_x, YIterator begin_y)
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
bool testSimpleRegression()
bool testSimpleRegression2()
bool testSimpleRegression3()
bool testSimpleRegressionOrdered()