6 template<
typename Number>
10 typedef std::map<Number, Number> Points;
17 virtual void fit(Points * points);
18 const Number getSlope()
const;
19 const Number getIntercept()
const;
20 const Number getRegressionCoefficient()
const;
31 template<
typename Number>
33 : _points(0), _a(0), _b(0), _r(0)
36 template<
typename Number>
38 : _points(points), _a(0), _b(0), _r(0)
41 template<
typename Number>
43 : _points(fit._points), _a(fit._a), _b(fit._b), _r(fit._r)
46 template<
typename Number>
49 _points = fit._points;
60 template<
typename Number>
68 template<
typename Number>
71 int n = _points->size();
73 throw runtime_error(
"LinearFit<Number>::fit() - FATAL - n<2");
74 Number sumx=0,sumy=0,sumx2=0,sumy2=0,sumxy=0;
75 Number x, y,sxx,syy,sxy;
77 typename std::map<Number, Number>::const_iterator i;
78 for (i = _points->begin(); i != _points->end(); i++)
88 sxx = sumx2 - (sumx * sumx / n);
89 syy = sumy2 - (sumy * sumy / n);
90 sxy = sumxy - (sumx * sumy / n);
101 _b = sumy/n - _a*sumx/n;
106 _r = sxy/::sqrt(sxx*syy);
109 template<
typename Number>
113 template<
typename Number>
119 template<
typename Number>
125 template<
typename Number>