DGtal  1.3.beta
SimpleLinearRegression.h
1 
17 #pragma once
18 
34 #if defined(SimpleLinearRegression_RECURSES)
35 #error Recursive header files inclusion detected in SimpleLinearRegression.h
36 #else // defined(SimpleLinearRegression_RECURSES)
37 
38 #define SimpleLinearRegression_RECURSES
39 
40 #if !defined SimpleLinearRegression_h
41 
42 #define SimpleLinearRegression_h
43 
44 
46 #include <iostream>
47 #include <vector>
49 
50 
51 namespace DGtal
52 {
53 
55  // class SimpleLinearRegression
57 
74  {
75 
76  // ----------------------- Standard services ------------------------------
77  public:
78 
83 
91  SimpleLinearRegression( double eps_zero = 1e-8 );
92 
96  void clear();
97 
109  template <class XIterator, class YIterator>
110  void addSamples( XIterator begin_x, XIterator end_x, YIterator begin_y );
111 
122  void addSample( const double x, const double y );
123 
130  bool computeRegression();
131 
135  double slope() const;
136 
137 
141  double intercept() const;
142 
150  double estimateY( double x ) const;
151 
156  double estimateVariance() const;
157 
171  std::pair<double,double> trustIntervalForY( const double x,
172  const double a ) const;
173 
174 
181  void setEpsilonZero(const double aEpsilonZero)
182  {
183  myEpsilonZero = aEpsilonZero;
184  }
185 
190  double epsilonZero() const
191  {
192  return myEpsilonZero;
193  }
194 
199  double size() const
200  {
201  return myN;
202  }
203 
204  // ----------------------- Interface --------------------------------------
205  public:
206 
211  void selfDisplay( std::ostream & that_stream ) const;
216  bool isValid() const;
217 
218 
219  // ------------------------- Datas ----------------------------------------
220 
221  private:
222 
225 
227  unsigned int myN;
228 
230  std::vector<double> myY;
231 
233  std::vector<double> myX;
234 
237  double myB[ 2 ];
238 
239  //Internal quantities.
240  std::vector<double> myU;
241  double mySumX;
242  double mySumX2;
243  double mySumY;
244  double mySumXY;
245  double myD;
246  double myNormU2;
247 
248  // ------------------------- Hidden services ------------------------------
249  protected:
250 
251  private:
252 
259 
267 
268  // ------------------------- Internals ------------------------------------
269  private:
270 
271 
272  };
273 
280  std::ostream&
281  operator<<( std::ostream & that_stream,
282  const SimpleLinearRegression & that_object_to_display );
283 
284 
285 } // namespace ImaGene
286 
287 
289 // Includes inline functions/methods if necessary.
290 #include "DGtal/math/SimpleLinearRegression.ih"
291 
292 // //
294 
295 #endif // !defined SimpleLinearRegression_h
296 
297 #undef SimpleLinearRegression_RECURSES
298 #endif // else defined(SimpleLinearRegression_RECURSES)
DGtal::SimpleLinearRegression::mySumX
double mySumX
Definition: SimpleLinearRegression.h:241
DGtal::SimpleLinearRegression::estimateVariance
double estimateVariance() const
DGtal::SimpleLinearRegression::myY
std::vector< double > myY
Ordinate values of sample points.
Definition: SimpleLinearRegression.h:230
DGtal::SimpleLinearRegression::myN
unsigned int myN
Number of samples.
Definition: SimpleLinearRegression.h:227
DGtal::SimpleLinearRegression::myU
std::vector< double > myU
Definition: SimpleLinearRegression.h:240
DGtal::SimpleLinearRegression::mySumY
double mySumY
Definition: SimpleLinearRegression.h:243
DGtal::SimpleLinearRegression::myNormU2
double myNormU2
Definition: SimpleLinearRegression.h:246
DGtal::SimpleLinearRegression::mySumXY
double mySumXY
Definition: SimpleLinearRegression.h:244
DGtal::SimpleLinearRegression::setEpsilonZero
void setEpsilonZero(const double aEpsilonZero)
Definition: SimpleLinearRegression.h:181
DGtal::SimpleLinearRegression::myB
double myB[2]
Definition: SimpleLinearRegression.h:237
DGtal::SimpleLinearRegression::operator=
SimpleLinearRegression & operator=(const SimpleLinearRegression &other)
DGtal::SimpleLinearRegression::epsilonZero
double epsilonZero() const
Definition: SimpleLinearRegression.h:190
DGtal::SimpleLinearRegression::trustIntervalForY
std::pair< double, double > trustIntervalForY(const double x, const double a) const
DGtal::SimpleLinearRegression::isValid
bool isValid() const
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::SimpleLinearRegression::selfDisplay
void selfDisplay(std::ostream &that_stream) const
DGtal::SimpleLinearRegression::addSample
void addSample(const double x, const double y)
DGtal::SimpleLinearRegression::computeRegression
bool computeRegression()
DGtal::SimpleLinearRegression::addSamples
void addSamples(XIterator begin_x, XIterator end_x, YIterator begin_y)
DGtal::SimpleLinearRegression::size
double size() const
Definition: SimpleLinearRegression.h:199
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::SimpleLinearRegression::myX
std::vector< double > myX
Abscissa values of sample points.
Definition: SimpleLinearRegression.h:233
DGtal::SimpleLinearRegression::estimateY
double estimateY(double x) const
DGtal::SimpleLinearRegression
Description of class 'SimpleLinearRegression'.
Definition: SimpleLinearRegression.h:73
DGtal::SimpleLinearRegression::clear
void clear()
DGtal::SimpleLinearRegression::myD
double myD
Definition: SimpleLinearRegression.h:245
DGtal::SimpleLinearRegression::intercept
double intercept() const
DGtal::SimpleLinearRegression::slope
double slope() const
DGtal::SimpleLinearRegression::myEpsilonZero
double myEpsilonZero
Epsilon zero value.
Definition: SimpleLinearRegression.h:224
DGtal::SimpleLinearRegression::mySumX2
double mySumX2
Definition: SimpleLinearRegression.h:242
DGtal::SimpleLinearRegression::SimpleLinearRegression
SimpleLinearRegression(double eps_zero=1e-8)
DGtal::SimpleLinearRegression::~SimpleLinearRegression
~SimpleLinearRegression()