npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
TwoPointsLTSLoss.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_TWOPOINTSLTSLOSS_HH_
2 #define NPSTAT_TWOPOINTSLTSLOSS_HH_
3 
4 /*!
5 // \file TwoPointsLTSLoss.hh
6 //
7 // \brief Loss function for local least trimmed squares with two excluded points
8 //
9 // Author: I. Volobouev
10 //
11 // December 2011
12 */
13 
14 #include "npstat/nm/OrthoPolyND.hh"
17 
18 namespace npstat {
19  /**
20  // Calculator of windowed least trimmed squares for use with gridded
21  // robust regression. The chi-squared is calculated for the whole window
22  // with excluded central point and arbitrary other point. The loss
23  // improvement is estimated only for the point in the window center,
24  // excluding that other point which results in the best local LTS.
25  //
26  // Template parameters MaxDim and MaxReplace are just like those in
27  // griddedRobustRegression.hh. For use with this particular loss
28  // calculator, MaxReplace value of 1 is the most appropriate. Template
29  // parameter MaxDeg is the maximum local polynomial degree.
30  */
31  template <unsigned MaxDim, unsigned MaxReplace, unsigned MaxDeg>
32  class TwoPointsLTSLoss : public AbsLossCalculator<MaxDim,MaxReplace>
33  {
34  public:
36 
37  /**
38  // "weight" is the function used to generate local polynomials.
39  // It will be called on the local window using window coordinate
40  // system. For example, the point in the window center will be
41  // at the origin, and coordinates of all points neighboring the
42  // origin in each dimension will be either 0 or 1. The weight
43  // therefore must have an appropriate bandwidth, consistent
44  // with the expected local window width. If the bandwidth is
45  // too small (weight on the edges of the window is exactly 0)
46  // then the code will still work but will be inefficient.
47  //
48  // "deg" is the actual degree of these polynomials (must not
49  // exceed "maxdeg").
50  //
51  // If the "fixStripes" parameter is true, the local loss in the
52  // window will be calculated not only by removing all possible
53  // second points in addition to the central one but also by removing
54  // all possible 1-d stripes of points passing through the center.
55  */
56  inline TwoPointsLTSLoss(const AbsDistributionND& weight, unsigned deg,
57  bool fixStripes = false)
58  : wFcn_(weight.clone()), polyPairs_(0), polyLines_(0),
59  degree_(deg), fixStripes_(fixStripes) {}
60 
61  virtual ~TwoPointsLTSLoss();
62 
64  const ArrayND<double>& slidingWindow,
65  const unsigned* indexInWindow,
66  const unsigned* indexInDataset,
67  BlockReplacement* block) const;
68 
69  private:
70  typedef OrthoPolyND<MaxDeg> Poly;
71 
73  TwoPointsLTSLoss& operator=(const TwoPointsLTSLoss&);
74 
75  void initialize(const ArrayND<double>& in);
76 
77  AbsDistributionND* wFcn_;
78  ArrayND<Poly*>* polyPairs_;
79  ArrayND<Poly*>* polyLines_;
80  ArrayShape expectedShape_;
81  mutable std::vector<double> coeffs_;
82  unsigned degree_;
83  bool fixStripes_;
84  };
85 }
86 
87 #include "npstat/stat/TwoPointsLTSLoss.icc"
88 
89 #endif // NPSTAT_TWOPOINTSLTSLOSS_HH_
Interface definition for multivariate continuous statistical distributions.
Interfaces and utility classes for gridded robust regression.
Discrete orthogonal polynomial series of arbitrary dimensionality in hyperrectangular domains.
Definition: AbsDistributionND.hh:26
Definition: OrthoPolyND.hh:28
Definition: TwoPointsLTSLoss.hh:33
TwoPointsLTSLoss(const AbsDistributionND &weight, unsigned deg, bool fixStripes=false)
Definition: TwoPointsLTSLoss.hh:56
virtual LocalLoss operator()(const ArrayND< double > &slidingWindow, const unsigned *indexInWindow, const unsigned *indexInDataset, BlockReplacement *block) const
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21
Definition: AbsLossCalculator.hh:95
Definition: AbsLossCalculator.hh:23
Definition: AbsLossCalculator.hh:57