npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
PolyFilterCollection1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_POLYFILTERCOLLECTION1D_HH_
2 #define NPSTAT_POLYFILTERCOLLECTION1D_HH_
3 
4 /*!
5 // \file PolyFilterCollection1D.hh
6 //
7 // \brief Collection of 1-d local polynomial filters intended for use in
8 // bandwidth scans
9 //
10 // Author: I. Volobouev
11 //
12 // September 2010
13 */
14 
15 #include <map>
16 #include <vector>
17 
20 
21 namespace npstat {
22  /**
23  // Collection of LocalPolyFilter1D objects with different bandwidth
24  // values. Filters are stored internally after their corresponding
25  // bandwidth values are used for the first time.
26  //
27  // This class is intended for use with bandwidth scans (for example,
28  // in cross-validation scenarios).
29  */
31  {
32  public:
33  /**
34  // The constructor arguments are as follows:
35  //
36  // distro -- Weight function to use in building the filter.
37  //
38  // taper -- The taper function used to build the filter
39  // (can be NULL).
40  //
41  // maxDegree -- Maximum polynomial degree of the filter.
42  // If the taper array is provided, its length
43  // should be maxDegree + 1.
44  //
45  // binwidth -- Bin width used to bin the data.
46  //
47  // dataLen -- Expected length of the data array to filter.
48  //
49  // bm -- Method used to handle LOrPE weight at the boundary.
50  */
52  const double* taper, unsigned maxDegree,
53  double binwidth, unsigned dataLen,
54  const BoundaryHandling& bm);
55 
57 
58  //@{
59  /** Inspect object properties */
60  inline unsigned dataLength() const {return dataLen_;}
61  inline double binWidth() const {return binwidth_;}
62  inline const BoundaryHandling& boundaryMethod() const {return bm_;}
63  inline unsigned maxDegree() const {return maxDegree_;}
64  double taper(unsigned i) const;
65  //@}
66 
67  /**
68  // Retrive the filter which corresponds to the given bandwidth.
69  // If such a filter does not exist yet, construct it first.
70  */
71  const LocalPolyFilter1D& getPolyFilter(double bandwidth);
72 
73  /**
74  // The method which performs the filtering. "dataLen",
75  // which is the length of both "in" and "out" arrays,
76  // must be the same as the one provided in the constructor.
77  */
78  template <typename Tin, typename Tout>
79  inline void filter(const double bandwidth, const Tin* in,
80  const unsigned dataLen, Tout* out)
81  {getPolyFilter(bandwidth).filter(in, dataLen, out);}
82 
83  /**
84  // This filtering method calls the "convolve" method of
85  // LocalPolyFilter1D objects instead of their "filter" method
86  */
87  template <typename Tin, typename Tout>
88  inline void convolve(const double bandwidth, const Tin* in,
89  const unsigned dataLen, Tout* out)
90  {getPolyFilter(bandwidth).convolve(in, dataLen, out);}
91 
92  private:
96 
97  LocalPolyFilter1D* processBandwidth(double bandwidth);
98 
99  std::map<double,const LocalPolyFilter1D*> filterMap_;
100  std::vector<double> scanBuf_;
101  AbsScalableDistribution1D* kernel_;
102  double binwidth_;
103  double* taper_;
104  unsigned maxDegree_;
105  unsigned dataLen_;
106  BoundaryHandling bm_;
107  };
108 }
109 
110 #endif // NPSTAT_POLYFILTERCOLLECTION1D_HH_
Interface definition for 1-d continuous statistical distributions.
Local polynomial filtering (regression) on 1-d equidistant grids.
Definition: AbsDistribution1D.hh:165
Definition: BoundaryHandling.hh:21
Definition: LocalPolyFilter1D.hh:38
void convolve(const Tin *in, unsigned dataLen, Tout *out) const
void filter(const Tin *in, unsigned dataLen, Tout *out) const
Definition: PolyFilterCollection1D.hh:31
void convolve(const double bandwidth, const Tin *in, const unsigned dataLen, Tout *out)
Definition: PolyFilterCollection1D.hh:88
unsigned dataLength() const
Definition: PolyFilterCollection1D.hh:60
void filter(const double bandwidth, const Tin *in, const unsigned dataLen, Tout *out)
Definition: PolyFilterCollection1D.hh:79
PolyFilterCollection1D(const AbsScalableDistribution1D &distro, const double *taper, unsigned maxDegree, double binwidth, unsigned dataLen, const BoundaryHandling &bm)
const LocalPolyFilter1D & getPolyFilter(double bandwidth)
Definition: AbsArrayProjector.hh:14