npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
SequentialPolyFilterND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_SEQUENTIALPOLYFILTERND_HH_
2 #define NPSTAT_SEQUENTIALPOLYFILTERND_HH_
3 
4 /*!
5 // \file SequentialPolyFilterND.hh
6 //
7 // \brief Sequential local polynomial filtering (regression) on uniform
8 // hyperrectangular grids
9 //
10 // Author: I. Volobouev
11 //
12 // November 2009
13 */
14 
15 #include <vector>
16 
17 #include "geners/ClassId.hh"
18 #include "geners/CPP11_auto_ptr.hh"
19 
20 #include "npstat/nm/ArrayND.hh"
21 #include "npstat/nm/Matrix.hh"
22 
26 
27 namespace npstat {
28  /**
29  // This class performs local polynomial filtering in multiple dimensions
30  // by sequential application of one-dimensional filters
31  */
33  {
34  public:
35  /**
36  // Main constructor. The arguments are as follows:
37  //
38  // filters -- Array of pointers to LocalPolyFilter1D
39  // objects which will be used to perform
40  // filtering in each dimension. The filters
41  // should be compatible with the expected
42  // span of the data arrays.
43  //
44  // nFilters -- Number of elements in the "filters" array.
45  // Should be equal to the dimensionality of
46  // the data arrays which will be processed
47  // by the "filter" function.
48  //
49  // takeOwnership -- If this argument is set to "true", we will
50  // call the "delete" operator on each element
51  // of the "filters" array the destructor.
52  */
54  unsigned nFilters, bool takeOwnership);
55 
56  SequentialPolyFilterND(const std::vector<AllSymbetaParams1D>& params);
57 
60 
61  virtual ~SequentialPolyFilterND();
62 
63  bool operator==(const SequentialPolyFilterND& r) const;
64  inline bool operator!=(const SequentialPolyFilterND& r) const
65  {return !(*this == r);}
66 
67  //@{
68  /** Inspect object properties */
69  inline unsigned dim() const {return nFilters_;}
70  inline bool takesOwnership() const {return takeOwnership_;}
72  //@}
73 
74  /** Get the filter for the given dimension */
75  const LocalPolyFilter1D* filter(unsigned dimNumber) const;
76 
77  /**
78  // Get the effective multivariate filter coefficients for the
79  // given grid point. Note that this operation is quite slow
80  // (it involves building a multivariate array using outer products
81  // of 1-d arrays) and should not be used when fast performance
82  // is essential.
83  */
85  const unsigned* index, unsigned lenIndex) const;
86 
87  /** Get the complete effective filter matrix */
89 
90  /** Get the info needed to construct the sparse filter matrix */
91  template <class Triplet>
92  CPP11_auto_ptr<std::vector<Triplet> > sparseFilterTriplets() const;
93 
94  /** Check compatibility of an array with the filter */
95  template <class Array>
96  bool isCompatible(const Array& in) const;
97 
98  //@{
99  /**
100  // Contribution of a single point into the density estimate
101  // at that point (not normalized). This is needed for various
102  // leaving-one-out cross validation procedures.
103  */
105  const unsigned* index, unsigned lenIndex) const;
106  double linearSelfContribution(unsigned long index) const;
107  //@}
108 
109  /** This method performs the filtering */
110  template <class ArrIn, class ArrOut>
111  void filter(const ArrIn& in, ArrOut* out) const;
112 
113  /**
114  // A diffent filtering method in which the shapes of the
115  // kernels are determined by the positions of the "sources"
116  // (i.e., sample points) instead of the positions at which
117  // the density (or response) is estimated. Note that elements
118  // of "out" array themselves are used as result accumulators.
119  */
120  template <class ArrIn, class ArrOut>
121  void convolve(const ArrIn& in, ArrOut* out) const;
122 
123  // Methods needed for I/O
124  inline virtual gs::ClassId classId() const {return gs::ClassId(*this);}
125  virtual bool write(std::ostream& os) const;
126 
127  static inline const char* classname()
128  {return "npstat::SequentialPolyFilterND";}
129  static inline unsigned version() {return 1;}
130  static SequentialPolyFilterND* read(const gs::ClassId& id,
131  std::istream& in);
132  private:
134 
135  void cleanup();
136  void copyFilters(const SequentialPolyFilterND& r);
137 
138  const LocalPolyFilter1D** filters_;
139  unsigned nFilters_;
140  std::vector<unsigned long> strides_;
141  mutable std::vector<unsigned> indexBuf_;
142  bool takeOwnership_;
143 
144  template <typename T2, unsigned StackLen2, unsigned StackDim2>
145  void filterLoop(bool useConvolve, unsigned level, unsigned long idx,
146  unsigned dimNumber, T2* inbuf, T2* outbuf,
147  ArrayND<T2,StackLen2,StackDim2>* out) const;
148  };
149 }
150 
151 #include "npstat/stat/SequentialPolyFilterND.icc"
152 
153 #endif // NPSTAT_SEQUENTIALPOLYFILTERND_HH_
Interface definition for multivariate smoothers that can be cross-validated.
Complete set of parameters for building 1-d filters from the symmetric beta family.
Arbitrary-dimensional array template.
Local polynomial filtering (regression) on 1-d equidistant grids.
Template matrix class.
Definition: LocalPolyFilter1D.hh:38
Definition: SequentialPolyFilterND.hh:33
Matrix< double > getFilterMatrix() const
void convolve(const ArrIn &in, ArrOut *out) const
ArrayShape dataShape() const
unsigned dim() const
Definition: SequentialPolyFilterND.hh:69
void filter(const ArrIn &in, ArrOut *out) const
SequentialPolyFilterND(const LocalPolyFilter1D **filters, unsigned nFilters, bool takeOwnership)
CPP11_auto_ptr< std::vector< Triplet > > sparseFilterTriplets() const
double linearSelfContribution(unsigned long index) const
ArrayND< double > getFilter(const unsigned *index, unsigned lenIndex) const
bool isCompatible(const Array &in) const
const LocalPolyFilter1D * filter(unsigned dimNumber) const
double selfContribution(const unsigned *index, unsigned lenIndex) const
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21
Definition: AbsPolyFilterND.hh:27