00001 /// \file CATLineFit.h 00002 /// \brief Regression to fit a line to a set of points. 00003 /// \ingroup CAT 00004 /// 00005 /// Copyright (c) 2002-2008 by Michael Ellison. 00006 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00007 /// 00008 // $Author: mikeellison $ 00009 // $Date: 2008-01-19 19:19:35 -0600 (Sat, 19 Jan 2008) $ 00010 // $Revision: $ 00011 // $NoKeywords: $ 00012 #ifndef _CATLineFit_H_ 00013 #define _CATLineFit_H_ 00014 00015 #include "CATInternal.h" 00016 #include "CATPoint.h" 00017 #include "CATMatrix.h" 00018 00019 00020 /// \class CATLineFit 00021 /// \brief Regression to fit a line to a set of points. 00022 /// \ingroup CAT 00023 class CATLineFit 00024 { 00025 public: 00026 CATLineFit(); 00027 virtual ~CATLineFit(); 00028 00029 /// Add a point to the interpolation data 00030 bool AddPoint( CATFloat64 x, CATFloat64 y); 00031 00032 /// Clear out all current data 00033 bool Clear(); 00034 00035 /// Get the number of data points acquired 00036 CATUInt32 GetNumPoints(); 00037 00038 /// Get an individual data point 00039 bool GetDataPoint( CATUInt32 n, CATFloat64& x, CATFloat64& y); 00040 00041 /// Calculate the Y val from a specified x val 00042 bool CalcYVal( CATFloat64 x, CATFloat64& y); 00043 00044 /// Get error value 00045 bool GetCurrentErr( CATFloat64& err); 00046 00047 /// Get min/max values for x and y 00048 bool GetMinMax( CATFloat64& minX, CATFloat64& minY, CATFloat64& maxX, CATFloat64& maxY); 00049 00050 /// Get the slope of the line 00051 bool Slope(CATFloat64& slope); 00052 00053 /// Get the intercept of the line 00054 bool Intercept(CATFloat64& intercept); 00055 protected: 00056 /// Internal calculation 00057 bool CalcFit(); 00058 00059 std::vector<CATPoint> fPointList; ///< list of X points 00060 CATFloat64 fLastErr; ///< last calculated err 00061 00062 CATUInt32 fDegree; ///< Degree of coefficient to calculate with fit 00063 bool fDirty; ///< Are the coefficients dirty? (i.e. need to call CalcFit?) 00064 CATFloat64 fSlope; ///< If not dirty, this is the slope of the line 00065 CATFloat64 fIntercept; ///< If not dirty, this is the intercept of the line 00066 CATFloat64 fSumX; ///< The sum of all X values 00067 CATFloat64 fSumY; ///< The sum of all Y values 00068 CATFloat64 fSumXY; ///< The sum of all X values times their Y values 00069 CATFloat64 fSumXSquared; ///< The sum of all X^2 (e.g. X1^2 + X2^2 .... + Xn^2) 00070 }; 00071 00072 #endif // _CATLineFit_H_