casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalStatsFitter.h
Go to the documentation of this file.
1 
2 // -----------------------------------------------------------------------------
3 
4 /*
5 
6 CalStatsFitter.h
7 
8 Description:
9 ------------
10 This header file contains definitions for the CalStatsFitter class.
11 
12 Classes:
13 --------
14 CalStatsFitter - This class contains the fit statistics static enums and
15 functions.
16 
17 Modification history:
18 ---------------------
19 2011 Dec 08 - Nick Elias, NRAO
20  Initial version created.
21 2012 Jan 25 - Nick Elias, NRAO
22  Error checking added.
23 
24 */
25 
26 // -----------------------------------------------------------------------------
27 // Start of define macro to prevent multiple loading
28 // -----------------------------------------------------------------------------
29 
30 #ifndef CAL_STATS_FITTER_H
31 #define CAL_STATS_FITTER_H
32 
33 // -----------------------------------------------------------------------------
34 // Includes
35 // -----------------------------------------------------------------------------
36 
37 #include <casa/aips.h>
38 
39 #include <casa/Exceptions/Error.h>
40 
41 #include <casa/Arrays/Vector.h>
42 
43 #include <casa/Arrays/ArrayMath.h>
45 
47 
51 
52 // -----------------------------------------------------------------------------
53 // Start of casa namespace
54 // -----------------------------------------------------------------------------
55 
56 namespace casa {
57 
58 // -----------------------------------------------------------------------------
59 // Start of CalStatsFitter class definition
60 // -----------------------------------------------------------------------------
61 
62 /*
63 
64 CalStatsFitter
65 
66 Description:
67 ------------
68 This class contains the fit statistics static enums and functions.
69 
70 NB: At present, this class acts as a namespace for static functions.
71 
72 Classes:
73 --------
74 CalStatsFitter - This class contains the fit statistics enums and functions.
75 
76 Class public static member functions:
77 -------------------------------------
78 fit - This member function is the fitting interface of this class.
79 orderName - This function returns the string corresponding to the
80  CalStatsFitter::ORDER enum.
81 typeName - This function returns the string corresponding to the
82  CalStatsFitter::TYPE enum.
83 weightName - This function returns the string corresponding to the
84  CalStatsFitter::WEIGHT enum.
85 
86 Class private static member functions (least-squares fitting):
87 --------------------------------------------------------------
88 lsqFit - This member function calculates polynomial least-squares fits.
89 
90 Class private static member functions (robust fitting):
91 -------------------------------------------------------
92 robustFit - This member function calculates polynomial robust fits.
93 slope - This member function calculates the robust slope.
94 brackFunc - This member function is root-finding bracketing function used to
95  determine the slope.
96 signum - This member function calculates the signum function (scalar).
97 signum - This member function calculates the signum function (vector).
98 theil - This member function estimates the slope and slope error using
99  Theil's method.
100 
101 Modification history:
102 ---------------------
103 2011 Dec 08 - Nick Elias, NRAO
104  Initial version created with enums ORDER, TYPE, and WEIGHT; public
105  static member functions init() and fit(); and private static
106  member functions lsqFit(), robustFit(), numDataWeight(), slope(),
107  brackFunc(), signum() (scalar), and signum() (vector).
108 2011 Dec 11 - Nick Elias, NRAO
109  Added value, value error, and model vectors to the FIT structure.
110  Added dealloc() (pointer) and dealloc() (reference) public static
111  member functions.
112 2011 Dec 21 - Nick Elias, NRAO
113  Public static member functions init() and dealloc() removed
114  because all of their duties are subsumed by the nested class
115  FIT (it used used to be a structure).
116 2012 Jan 24 - Nick Elias, NRAO
117  Private static member function theil() added. Private static
118  member function numDataWeight() removed because initial robust
119  estimates of fit parameters (before final "trimmed" least squares)
120  no longer employ weighting.
121 2012 Mar 06 - Nick Elias, NRAO
122  Static public member functions orderName(), typeName(), and
123  weightName() added.
124 2012 Mar 15 - Nick Elias, NRAO
125  Public members dResVar and dResMean added to the nested FIT class.
126 
127 */
128 
129 // -----------------------------------------------------------------------------
130 
132 
133  public:
134 
135  // Order enums
136  typedef enum ORDER {
138  } ORDER;
139 
140  // Type enums
141  typedef enum TYPE {
143  } TYPE;
144 
145  // Weight enums
146  typedef enum WEIGHT {
147  WEIGHT_INIT=-1, NO=false, YES=true
148  } WEIGHT;
149 
150  // FIT nested class
151  class FIT {
152  public:
153  ORDER eOrder; // Fit order
154  TYPE eType; // Fit type
155  WEIGHT eWeight; // Fit weight
156  casacore::Bool bValid; // Fit validity boolean
158  casacore::Matrix<casacore::Double> oCovars; // Fit parameter covariances
161  casacore::Double dResVar; // Fit variance of residuals
162  casacore::Double dResMean; // Fit mean of residuals
163  casacore::Double dRedChi2; // Fit reduced chi^2
164  FIT( void );
165  FIT( const FIT& oFit );
166  ~FIT( void );
167  FIT& operator=( const FIT& oFit );
168  };
169 
170  // User interface to all fitting capabilities
173  const ORDER& eOrder, const TYPE& eType, const WEIGHT& eWeight );
174 
175  // The enum names
176  static casacore::String orderName( const ORDER& eOrder );
177  static casacore::String typeName( const TYPE& eOrder );
178  static casacore::String weightName( const WEIGHT& eOrder );
179 
180  private:
181 
182  // Least-squares fitting function
183  static FIT lsqFit( const casacore::Vector<casacore::Double>& oAbs,
185  casacore::Vector<casacore::Bool>& oFlag, const ORDER& eOrder, const WEIGHT& eWeight );
186 
187  // Robust fitting function
190  casacore::Vector<casacore::Bool>& oFlag, const ORDER& eOrder, const WEIGHT& eWeight,
191  const casacore::Double& dTrim );
192 
193  // Functions required to calculate a robust linear fit
195  const casacore::Vector<casacore::Double>& oValue, const casacore::Double& dSlope,
196  const casacore::Double& dSlopeErr, const casacore::Double& dFudge, const casacore::uInt& uiNumSlope,
197  const casacore::uInt& uiNumIter );
199  const casacore::Vector<casacore::Double>& oValue, const casacore::Double& dSlope );
200 
201  // Signum functions (also required to calculate a robust linear fit)
202  static casacore::Double& signum( const casacore::Double& dValue );
204 
205  // casacore::Function for calculating slope estimate using Theil's method
206  static void theil( const casacore::Vector<casacore::Double>& oAbs, const casacore::Vector<casacore::Double>& oValue,
207  casacore::Double& dSlope, casacore::Double& dSlopeErr );
208 
209 };
210 
211 // -----------------------------------------------------------------------------
212 // End of CalStatsFitter class definition
213 // -----------------------------------------------------------------------------
214 
215 };
216 
217 // -----------------------------------------------------------------------------
218 // End of casa namespace
219 // -----------------------------------------------------------------------------
220 
221 #endif
222 
223 // -----------------------------------------------------------------------------
224 // End of define macro to prevent multiple loading
225 // -----------------------------------------------------------------------------
FIT nested class.
casacore::Matrix< casacore::Double > oCovars
casacore::Vector< casacore::Double > oPars
WEIGHT
Weight enums.
static casacore::Double & signum(const casacore::Double &dValue)
Signum functions (also required to calculate a robust linear fit)
static casacore::String weightName(const WEIGHT &eOrder)
casacore::Double dRedChi2
casacore::Double dResMean
FIT & operator=(const FIT &oFit)
casacore::Double dResVar
casacore::Vector< casacore::Double > oRes
static casacore::String orderName(const ORDER &eOrder)
The enum names.
double Double
Definition: aipstype.h:55
static FIT fit(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, const casacore::Vector< casacore::Double > &oValueErr, casacore::Vector< casacore::Bool > &oFlag, const ORDER &eOrder, const TYPE &eType, const WEIGHT &eWeight)
User interface to all fitting capabilities.
static casacore::Double & slope(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, const casacore::Double &dSlope, const casacore::Double &dSlopeErr, const casacore::Double &dFudge, const casacore::uInt &uiNumSlope, const casacore::uInt &uiNumIter)
Functions required to calculate a robust linear fit.
static casacore::Double & brackFunc(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, const casacore::Double &dSlope)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static FIT robustFit(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, const casacore::Vector< casacore::Double > &oValueErr, casacore::Vector< casacore::Bool > &oFlag, const ORDER &eOrder, const WEIGHT &eWeight, const casacore::Double &dTrim)
Robust fitting function.
casacore::Vector< casacore::Double > oModel
static casacore::String typeName(const TYPE &eOrder)
Start of CalStatsFitter class definition
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static FIT lsqFit(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, const casacore::Vector< casacore::Double > &oValueErr, casacore::Vector< casacore::Bool > &oFlag, const ORDER &eOrder, const WEIGHT &eWeight)
Least-squares fitting function.
unsigned int uInt
Definition: aipstype.h:51
static void theil(const casacore::Vector< casacore::Double > &oAbs, const casacore::Vector< casacore::Double > &oValue, casacore::Double &dSlope, casacore::Double &dSlopeErr)
casacore::Function for calculating slope estimate using Theil&#39;s method