npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
griddedRobustRegression.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_GRIDDEDROBUSTREGRESSION_HH_
2 #define NPSTAT_GRIDDEDROBUSTREGRESSION_HH_
3 
4 /*!
5 // \file griddedRobustRegression.hh
6 //
7 // \brief A generic framework for local robust regression on regular grids
8 //
9 // Author: I. Volobouev
10 //
11 // December 2011
12 */
13 
14 #include <utility>
15 
18 
19 namespace npstat {
20  /**
21  // A generic framework for local robust regression on regular grids.
22  // It is designed, in particular, in order to implement local least trimmed
23  // squares (LLTS) but can be used with other loss types as well. Works by
24  // replacing (i.e., adjusting) grid values with the highest local loss
25  // in the whole grid by values fitted from local surroundings using,
26  // for example, local orthogonal polynomials.
27  //
28  // A two-run use is envisioned: during the first run, the user accumulates
29  // the "history" of grid replacements. Then the history is analyzed
30  // (typically, the local loss time series will exhibit a characteristic
31  // "knee" when all outliers have been detected and adjusted). During the
32  // second run, the regression is performed up to the desired history point.
33  // Automatic history analyzers might be added in the future, but for now
34  // it is best to just eyeball the history with the help of some convenient
35  // ploting package.
36  //
37  // Compared to other statistical methods in this package, this function is
38  // expected to be very slow (which is not atypical for robust techniques).
39  //
40  // Function template arguments are as follows. These parameters should
41  // be the same as those in the provided loss calculator.
42  //
43  // MaxDim -- Maximum dimensionality of the data grid.
44  // The actual dimensionality must not exceed
45  // this parameter.
46  //
47  // MaxReplace -- Maximum number of grid point adjustments
48  // performed in a single local adjustment cycle.
49  //
50  // Function arguments are as follows:
51  //
52  // in -- Input data for regression.
53  //
54  // slidingWindowSize -- Size of the local window for use by the loss
55  // calculator. The size in each dimension must
56  // be odd and larger than 1.
57  //
58  // slidingWindowDim -- Number of elements in the slidingWindowSize array
59  // (and dimensionality of the predictor space).
60  // Naturally, the code will check that the input data
61  // dimensionality is compatible with this parameter.
62  //
63  // lossCalc -- Local loss calculator. Will be called on data
64  // in all possible local windows. Should calculate
65  // local least trimmed squares or some other such
66  // quantity. See "WeightedLTSLoss.hh" and
67  // "TwoPointsLTSLoss.hh" for examples of such
68  // calculators.
69  //
70  // stopCallback -- The function stops when this returns "true".
71  // The arguments will be the largest remaining
72  // loss and the number of replacements made
73  // so far. See the "GriddedRobustRegressionStop.hh"
74  // header for a simple example of such a callback.
75  //
76  // observationCallback -- Callback to call with the current values
77  // of data (to monitor progress). Can be NULL.
78  //
79  // observationFrequency -- How often to call the above callback. Set this
80  // argument to 0 to disable these calls completely.
81  //
82  // out -- Replaced array (on exit). Can point to the
83  // same area as "in" (naturally, "in" will be
84  // destroyed in this case).
85  //
86  // replacementHistory -- History of replacements. This argument can be
87  // NULL in which case the history is not generated.
88  // This function will not clear a previously filled
89  // history but will append to it.
90  //
91  // verbose -- If "true", will print the location of the local
92  // window in which the replacements are made to
93  // the standard output.
94  //
95  // This function returns the total number of replacements made.
96  */
97  template <unsigned MaxDim, unsigned MaxReplace>
98  unsigned long griddedRobustRegression(
99  const ArrayND<double>& in,
100  const unsigned *slidingWindowSize, unsigned slidingWindowDim,
101  const AbsLossCalculator<MaxDim,MaxReplace>& lossCalc,
102  const Functor2<bool,LocalLoss,unsigned long>& stopCallback,
103  const Functor1<void,ArrayND<double> >* observationCallback,
104  unsigned observationFrequency,
105  ArrayND<double>* out,
106  std::vector<
108  >* replacementHistory, bool verbose = false);
109 }
110 
111 #include "npstat/stat/griddedRobustRegression.icc"
112 
113 #endif // NPSTAT_GRIDDEDROBUSTREGRESSION_HH_
Interfaces and utility classes for gridded robust regression.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: AbsArrayProjector.hh:14
unsigned long griddedRobustRegression(const ArrayND< double > &in, const unsigned *slidingWindowSize, unsigned slidingWindowDim, const AbsLossCalculator< MaxDim, MaxReplace > &lossCalc, const Functor2< bool, LocalLoss, unsigned long > &stopCallback, const Functor1< void, ArrayND< double > > *observationCallback, unsigned observationFrequency, ArrayND< double > *out, std::vector< std::pair< LocalLoss, ReplacementBlock< MaxDim, MaxReplace > > > *replacementHistory, bool verbose=false)
Definition: AbsLossCalculator.hh:95
Definition: SimpleFunctors.hh:58
Definition: AbsLossCalculator.hh:23
Definition: AbsLossCalculator.hh:57