npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsSymbetaFilterProvider.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSSYMBETAFILTERPROVIDER_HH_
2 #define NPSTAT_ABSSYMBETAFILTERPROVIDER_HH_
3 
4 /*!
5 // \file AbsSymbetaFilterProvider.hh
6 //
7 // \brief Interface definition for classes which build symmetric beta LOrPE
8 // filters
9 //
10 // Author: I. Volobouev
11 //
12 // October 2013
13 */
14 
15 #include <vector>
16 
17 #include "geners/CPP11_shared_ptr.hh"
19 
20 namespace npstat {
21  /**
22  // Interface definition for classes which build LOrPE filters
23  // using symmetric beta kernels (or a Gaussian kernel) as weights.
24  // The derived classes are supposed to override the "provideFilter"
25  // member function.
26  */
28  {
29  public:
30  inline AbsSymbetaFilterProvider() : memoize_(false) {}
31 
32  inline virtual ~AbsSymbetaFilterProvider() {}
33 
34  /**
35  // Parameters are:
36  //
37  // symbetaPower -- This parameter defines which kernel to use.
38  // Negative value means use Gaussian.
39  //
40  // bandwidth -- Kernel bandwidth.
41  //
42  // degree -- Polynomial degree.
43  //
44  // nbins -- Number of bins in the discretized dataset.
45  //
46  // binwidth -- Bin width.
47  //
48  // bm -- Boundary handling method.
49  //
50  // excludedBin -- Bin number to exclude. Numbers equal to
51  // nbins and larger are to be ignored.
52  //
53  // excludeCentralPoint -- Exclude central bin from the
54  // weight function.
55  //
56  // The function should return an instance of LocalPolyFilter1D
57  // wrapped into a smart pointer.
58  */
59  virtual CPP11_shared_ptr<const LocalPolyFilter1D> provideFilter(
60  int symbetaPower, double bandwidth, double degree,
61  unsigned nbins, double binwidth, const BoundaryHandling& bm,
62  unsigned excludedBin, bool excludeCentralPoint) = 0;
63 
64  //@{
65  /**
66  // This function can be used to advise the filter provider
67  // which filters should be stored for subsequent reuse.
68  // The filter provider is free to heed or to ignore this advice.
69  */
70  inline virtual void startMemoizing() {memoize_ = true;}
71  inline virtual void stopMemoizing() {memoize_ = false;}
72  //@}
73 
74  /** Is the filter provider memoizing filters currently? */
75  inline virtual bool isMemoizing() const {return memoize_;}
76 
77  private:
78  bool memoize_;
79  };
80 
81 
82  /** Simple non-memoizing implementation of AbsSymbetaFilterProvider */
84  {
85  public:
86  inline virtual ~SimpleSymbetaFilterProvider() {}
87 
88  inline virtual CPP11_shared_ptr<const LocalPolyFilter1D> provideFilter(
89  const int symbetaPower, const double bandwidth, const double degree,
90  const unsigned nbins, const double binwidth,
91  const BoundaryHandling& bm,
92  const unsigned excludedBin, const bool excludeCentralPoint)
93  {
94  CPP11_auto_ptr<LocalPolyFilter1D> p;
95  if (excludedBin < nbins)
96  {
97  std::vector<unsigned char> mask(nbins, 0);
98  mask[excludedBin] = 1;
99  p = symbetaLOrPEFilter1D(symbetaPower, bandwidth, degree,
100  nbins, binwidth,
101  bm, &mask[0], excludeCentralPoint);
102  }
103  else
104  p = symbetaLOrPEFilter1D(symbetaPower, bandwidth, degree,
105  nbins, binwidth,
106  bm, (unsigned char*)0,
107  excludeCentralPoint);
108  return CPP11_shared_ptr<const LocalPolyFilter1D>(p.release());
109  }
110  };
111 }
112 
113 #endif // NPSTAT_ABSSYMBETAFILTERPROVIDER_HH_
Local polynomial filtering (regression) on 1-d equidistant grids.
Definition: AbsSymbetaFilterProvider.hh:28
virtual CPP11_shared_ptr< const LocalPolyFilter1D > provideFilter(int symbetaPower, double bandwidth, double degree, unsigned nbins, double binwidth, const BoundaryHandling &bm, unsigned excludedBin, bool excludeCentralPoint)=0
virtual void startMemoizing()
Definition: AbsSymbetaFilterProvider.hh:70
virtual bool isMemoizing() const
Definition: AbsSymbetaFilterProvider.hh:75
Definition: BoundaryHandling.hh:21
Definition: AbsSymbetaFilterProvider.hh:84
virtual CPP11_shared_ptr< const LocalPolyFilter1D > provideFilter(const int symbetaPower, const double bandwidth, const double degree, const unsigned nbins, const double binwidth, const BoundaryHandling &bm, const unsigned excludedBin, const bool excludeCentralPoint)
Definition: AbsSymbetaFilterProvider.hh:88
Definition: AbsArrayProjector.hh:14
CPP11_auto_ptr< LocalPolyFilter1D > symbetaLOrPEFilter1D(int m, double bandwidth, double maxDegree, unsigned numberOfGridPoints, double gridCellSize, const BoundaryHandling &boundaryMethod, const unsigned char *exclusionMask=0, bool excludeCentralPoint=false)