int FitLineIt(const DblVector& PointsY, const DblVector& PointsX, double& a, double& b, int It, double ErrWidth) { // base case if(It==0) return 0; std::cout << "Line fitting no samples: " << PointsY.size() << std::endl; // fitting FitLine(PointsY, PointsX, a, b); double Error = 0.0; for(int i=0; i<(int)PointsY.size(); i++) { double Val0 = a*PointsX[i]+b; double Val1 = PointsY[i]; Error += dblsqr(Val1-Val0); //std::cout << Val1 << " " << Val0 << std::endl; } Error /= (double)PointsY.size(); Error = sqrt(Error); DblVector px, py; int Cnt=0; for(int k=0; k<(int)PointsX.size(); k++) { double Val = a*PointsX[k]+b; double Dist = sqrt(dblsqr(PointsY[k] - Val)); if(Dist<Error*ErrWidth) { px.push_back(PointsX[k]); py.push_back(PointsY[k]); Cnt++; } } return FitLineIt(py, px, a, b, It-1, ErrWidth); }
void DblVector::GetStatistics(double& Mean, double& Sigma) const { double sum=0.0; unsigned int i; for(i=0; i<size(); i++) { sum+=(*this)[i]; } Mean = sum/(double)size(); sum=0.0; for(i=0; i<size(); i++) { sum+=dblsqr((*this)[i]-Mean); } sum/=(double)size(); Sigma = sqrt(sum); }