npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsLossCalculator.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSLOSSCALCULATOR_HH_
2 #define NPSTAT_ABSLOSSCALCULATOR_HH_
3 
4 /*!
5 // \file AbsLossCalculator.hh
6 //
7 // \brief Interfaces and utility classes for gridded robust regression
8 //
9 // Author: I. Volobouev
10 //
11 // December 2011
12 */
13 
14 #include "geners/CPP11_array.hh"
15 #include "npstat/nm/ArrayND.hh"
16 
17 namespace npstat {
18  /**
19  // Class for keeping information about local regression
20  // loss (e.g., in a sliding window)
21  */
22  struct LocalLoss
23  {
24  inline LocalLoss() : value(0.0), improvement(0.0) {}
25  inline LocalLoss(double v, double i) : value(v), improvement(i) {}
26 
27  double value; ///< current "loss" (e.g., chi-squared)
28  double improvement; ///< possible improvement due to the point replacement
29 
30  inline bool operator<(const LocalLoss& r) const
31  {return improvement < r.improvement;}
32  };
33 
34  /**
35  // Class for representing the information about
36  // a potential point replacement in nonlinear
37  // regression algorithms on rectangular grids
38  */
39  template <unsigned MaxDim>
41  {
42  typedef CPP11_array<unsigned,MaxDim> Index;
43 
44  inline PointReplacement() : improvedValue(0.0) {}
45 
46  double improvedValue; ///< improved loss value upon replacement
47  Index coord; ///< point index
48  };
49 
50  /**
51  // Class for representing the information about multiple
52  // potential point replacements in nonlinear regression
53  // algorithms on rectangular grids
54  */
55  template <unsigned MaxDim, unsigned MaxReplace>
57  {
58  typedef CPP11_array<unsigned,MaxDim> Index;
59 
60  inline ReplacementBlock() : nReplacements(0) {}
61 
62  /**
63  // Reset this object to a meanigful state with zero
64  // suggested replacements
65  */
66  inline void reset(const unsigned* index, const unsigned sz)
67  {
68  for (unsigned i=0; i<sz; ++i)
69  idx[i] = index[i];
70  for (unsigned i=sz; i<MaxDim; ++i)
71  idx[i] = 0U;
72  dim = sz;
73  nReplacements = 0;
74  }
75 
76  /** Index of the point for which the replacements are suggested */
77  Index idx;
78 
79  /** Actual dimensionality of the point index */
80  unsigned dim;
81 
82  /**
83  // Collection of suggested replacements which result
84  // in the corresponding loss improvement
85  */
87 
88  /** Actual number of suggested replacements */
89  unsigned nReplacements;
90  };
91 
92  /** Abstract base class for calculations of the local loss */
93  template <unsigned MaxDim, unsigned MaxReplace>
95  {
96  inline virtual ~AbsLossCalculator() {}
97 
98  /**
99  // In addition to returning the loss, the following
100  // function must fill out the suggested replacement block
101  */
103  const npstat::ArrayND<double>& slidingWindow,
104  const unsigned* indexInWindow,
105  const unsigned* indexInDataset,
106  ReplacementBlock<MaxDim,MaxReplace>* block) const = 0;
107  };
108 }
109 
110 #endif // NPSTAT_ABSLOSSCALCULATOR_HH_
Arbitrary-dimensional array template.
Definition: AbsArrayProjector.hh:14
Definition: AbsLossCalculator.hh:95
virtual LocalLoss operator()(const npstat::ArrayND< double > &slidingWindow, const unsigned *indexInWindow, const unsigned *indexInDataset, ReplacementBlock< MaxDim, MaxReplace > *block) const =0
Definition: AbsLossCalculator.hh:23
double value
current "loss" (e.g., chi-squared)
Definition: AbsLossCalculator.hh:27
double improvement
possible improvement due to the point replacement
Definition: AbsLossCalculator.hh:28
Definition: AbsLossCalculator.hh:41
double improvedValue
improved loss value upon replacement
Definition: AbsLossCalculator.hh:46
Index coord
point index
Definition: AbsLossCalculator.hh:47
Definition: AbsLossCalculator.hh:57
PointReplacement< MaxDim > replacement[MaxReplace]
Definition: AbsLossCalculator.hh:86
void reset(const unsigned *index, const unsigned sz)
Definition: AbsLossCalculator.hh:66
unsigned nReplacements
Definition: AbsLossCalculator.hh:89
Index idx
Definition: AbsLossCalculator.hh:77
unsigned dim
Definition: AbsLossCalculator.hh:80