npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ConstantBandwidthSmoother1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CONSTANTBANDWIDTHSMOOTHER1D_HH_
2 #define NPSTAT_CONSTANTBANDWIDTHSMOOTHER1D_HH_
3 
4 /*!
5 // \file ConstantBandwidthSmoother1D.hh
6 //
7 // \brief Fast constant bandwidth KDE in one dimension via FFT
8 //
9 // Author: I. Volobouev
10 //
11 // October 2011
12 */
13 
16 
17 namespace npstat {
18  class ConvolutionEngine1D;
19 
20  /**
21  // 1-d KDE implementation with constant bandwidth, using kernels
22  // from the beta family (or the Gaussian). Based on FFT, so it
23  // should be reasonably fast even if the number of bins is large.
24  // By default, the data is mirrored at the boundary to reduce the
25  // edge effects.
26  //
27  // The output density is truncated non-negative and normalized.
28  */
30  public AbsPolyFilter1D
31  {
32  public:
33  /**
34  // Constructor arguments are as follows:
35  //
36  // nbins, xmin, xmax -- Parameters for the histogram which will
37  // be accumulated using the data sample to be
38  // smoothed. nbins should preferrably be
39  // a power of 2 (for subsequent FFT).
40  //
41  // symbetaPower -- Power of the symmetric beta kernel to use.
42  // Gaussian kernel chopped of at 12 sigma will
43  // be used in case this parameter is negative.
44  // This parameter must not exceed 10.
45  //
46  // kernelOrder -- Order of the kernel. Meaningful arguments
47  // are even numbers 2 or larger. Numbers below
48  // 2 will be converted to 2, 1 will be subtracted
49  // from odd numbers (poly degree is the kernel
50  // order minus 2).
51  //
52  // bandwidth -- Fixed bandwidth to use. Value of 0.0
53  // (default) means to use the Gaussian plug-in
54  // estimate which will change from one dataset
55  // to another. Note that the bin width of the
56  // histogram with which "smoothHisto" method
57  // will be called is not necessarily the same
58  // from one call to another, so the usage
59  // of fixed bandwidth has to take this into
60  // account (basically, by also using the class
61  // DummyResponseBoxBuilder in the appropriate
62  // place which will lead to constant bin width).
63  //
64  // bwFactor -- Fudge factor for the bandwidth used for
65  // the density estimate (either for the plug-in
66  // bandwidth or for the fixed one provided by
67  // the previous argument).
68  //
69  // mirrorData -- If true, the data will be mirrored at
70  // the boundary.
71  //
72  // label -- Label for the axis. Useful in case
73  // smoothing results are stored for inspection.
74  */
75  ConstantBandwidthSmoother1D(unsigned nbins, double xmin, double xmax,
76  int symbetaPower, unsigned kernelOrder,
77  double bandwidth=0.0, double bwFactor=1.0,
78  bool mirrorData=true, const char* label=0);
79 
80  virtual ~ConstantBandwidthSmoother1D();
81 
82  //@{
83  /** Simple inspector of object properties */
84  inline int symbetaPower() const {return symbetaPower_;}
85  inline unsigned kernelOrder() const {return kernelOrder_;}
86  inline double fixedBandwidth() const {return fixedBandwidth_;}
87  inline double bwFactor() const {return bwFactor_;}
88  inline bool mirrorsData() const {return mirror_;}
89  //@}
90 
91  /** Method that has to be overriden from AbsPolyFilter1D */
92  inline unsigned dataLen() const {return nBins();}
93 
94  /**
95  // Method that has to be overriden from AbsPolyFilter1D.
96  // If the bandwidth is not fixed, the value returned by
97  // "selfContribution" will change after each call to "smooth"
98  // or "weightedSmooth".
99  */
100  inline double selfContribution(unsigned) const {return filter0_;}
101 
102  private:
103  /** Method that has to be overriden from AbsMarginalSmootherBase */
104  virtual void smoothHisto(HistoND<double>& histo,
105  double effectiveSampleSize,
106  double* bandwidthUsed,
107  bool isSampleWeighted);
108 
109  double pluginBandwidth(const HistoND<double>& histo,
110  double effectiveSampleSize);
111  void makeKernel(double actualBandwidth);
112 
113  ConvolutionEngine1D* engine_;
114  std::vector<double> databuf_;
115  std::vector<double> taper_;
116  int symbetaPower_;
117  unsigned kernelOrder_;
118  double fixedBandwidth_;
119  double bwFactor_;
120  double filter0_;
121  bool mirror_;
122  };
123 }
124 
125 #endif // NPSTAT_CONSTANTBANDWIDTHSMOOTHER1D_HH_
Interface definition for 1-d nonparametric density estimation.
Interface definition for 1-d smoothers useable with cross-validation.
Definition: AbsMarginalSmootherBase.hh:29
unsigned nBins() const
Definition: AbsMarginalSmootherBase.hh:41
Definition: ConstantBandwidthSmoother1D.hh:31
ConstantBandwidthSmoother1D(unsigned nbins, double xmin, double xmax, int symbetaPower, unsigned kernelOrder, double bandwidth=0.0, double bwFactor=1.0, bool mirrorData=true, const char *label=0)
unsigned dataLen() const
Definition: ConstantBandwidthSmoother1D.hh:92
int symbetaPower() const
Definition: ConstantBandwidthSmoother1D.hh:84
double selfContribution(unsigned) const
Definition: ConstantBandwidthSmoother1D.hh:100
Definition: ConvolutionEngine1D.hh:31
Definition: AbsArrayProjector.hh:14
Definition: AbsPolyFilter1D.hh:27