DGtal  1.5.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)
38 #define SimpleLinearRegression_RECURSES
39 
40 #if !defined SimpleLinearRegression_h
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 
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)
Description of class 'SimpleLinearRegression'.
void addSample(const double x, const double y)
void addSamples(XIterator begin_x, XIterator end_x, YIterator begin_y)
double estimateY(double x) const
void setEpsilonZero(const double aEpsilonZero)
SimpleLinearRegression & operator=(const SimpleLinearRegression &other)
unsigned int myN
Number of samples.
double myEpsilonZero
Epsilon zero value.
std::pair< double, double > trustIntervalForY(const double x, const double a) const
std::vector< double > myX
Abscissa values of sample points.
void selfDisplay(std::ostream &that_stream) const
SimpleLinearRegression(const SimpleLinearRegression &other)
SimpleLinearRegression(double eps_zero=1e-8)
std::vector< double > myY
Ordinate values of sample points.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)