npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ConstantBandwidthSmootherND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CONSTANTBANDWIDTHSMOOTHERND_HH_
2 #define NPSTAT_CONSTANTBANDWIDTHSMOOTHERND_HH_
3 
4 /*!
5 // \file ConstantBandwidthSmootherND.hh
6 //
7 // \brief Constant bandwidth multivariate KDE via FFT
8 //
9 // Author: I. Volobouev
10 //
11 // October 2011
12 */
13 
15 
17 #include "npstat/stat/HistoND.hh"
18 
19 namespace npstat {
20  /**
21  // N-d KDE implementation with constant bandwidth. Uses FFT, so it
22  // should be reasonably fast even if the number of bins is large.
23  // By default, the data is mirrored at the boundaries to reduce the
24  // edge effects.
25  //
26  // The output density is truncated non-negative and normalized.
27  //
28  // If you would like to run cross-validation on bandwidth scans, consider
29  // using a collection of KDEFilterND objects instead.
30  */
31  template <unsigned MaxDeg>
33  {
34  public:
35  enum {deg_size = MaxDeg};
36 
37  /**
38  // Constructor arguments are as follows:
39  //
40  // protoHisto -- Prototype histogram which defines expected data
41  // shape and grid coordinates.
42  //
43  // kernel -- The "base" kernel function. This must have correct
44  // bandwidth settings already. Normally, the location
45  // vector has to be set to all zeros.
46  //
47  // taper -- Damping factors for each polynomial degree
48  // (starting with the 0th order term). This can
49  // be NULL in which case it is assumed that all
50  // factors are 1.
51  //
52  // maxDeg -- Polynomial degree to use with the given kernel.
53  // Must not exceed the MaxDeg template parameter.
54  //
55  // mirror -- If true, the data will be mirrored at the
56  // boundaries to reduce the edge effects.
57  */
58  template <class Numeric>
60  const AbsDistributionND& kernel,
61  const double* taper, unsigned maxDeg,
62  bool mirror = true);
63 
64  inline ~ConstantBandwidthSmootherND() {delete engine_; delete buf_;}
65 
66  //@{
67  /** Simple inspector of object properties */
68  inline unsigned dim() const {return shape_.size();}
69  inline const ArrayShape& shape() const {return shape_;}
70  inline const unsigned* shapeData() const {return &shape_[0];}
71  inline unsigned maxDegree() const {return taper_.size() - 1U;}
72  inline bool mirrorsData() const {return mirror_;}
73  double taper(unsigned degree) const;
74  //@}
75 
76  /**
77  // Perform actual convolution. histoIn and histoOut can refer
78  // to the same histogram.
79  */
80  template <class Numeric, class Real>
81  void smoothHistogram(const HistoND<Numeric>& histoIn,
82  HistoND<Real>* histoOut);
83 
84  static inline unsigned classMaxDegree() {return MaxDeg;}
85 
86  private:
87  ConvolutionEngineND* engine_;
88  ArrayShape shape_;
89  ArrayShape indexBuf_;
90  std::vector<double> taper_;
91  ArrayND<double>* buf_;
92  bool mirror_;
93  };
94 }
95 
96 #include "npstat/stat/ConstantBandwidthSmootherND.icc"
97 
98 #endif // NPSTAT_CONSTANTBANDWIDTHSMOOTHERND_HH_
Interface definition for multivariate continuous statistical distributions.
Fast multidimensional convolutions via Fourier transforms (FFTW interface)
Arbitrary-dimensional histogram template.
Definition: AbsDistributionND.hh:26
Definition: ConstantBandwidthSmootherND.hh:33
unsigned dim() const
Definition: ConstantBandwidthSmootherND.hh:68
void smoothHistogram(const HistoND< Numeric > &histoIn, HistoND< Real > *histoOut)
ConstantBandwidthSmootherND(const HistoND< Numeric > &protoHisto, const AbsDistributionND &kernel, const double *taper, unsigned maxDeg, bool mirror=true)
Definition: ConvolutionEngineND.hh:31
Definition: HistoND.hh:46
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21