npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
NonparametricCompositeBuilder.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_NONPARAMETRICCOMPOSITEBUILDER_HH_
2 #define NPSTAT_NONPARAMETRICCOMPOSITEBUILDER_HH_
3 
4 /*!
5 // \file NonparametricCompositeBuilder.hh
6 //
7 // \brief Density estimation decomposed: do it separately for the marginals
8 // and the copula
9 //
10 // Author: I. Volobouev
11 //
12 // September 2010
13 */
14 
19 
20 namespace npstat {
21  /**
22  // A class for building nonparametric estimates of multivariate
23  // densities by performing separate density estimation for each
24  // marginal and the copula. This allows us to introduce a larger
25  // number of bandwidth parameters into the system which can
26  // often lead to a better estimate.
27  */
28  template <class Point>
30  public AbsCompositeDistroBuilder<Point>
31  {
32  public:
34  typedef typename B::WeightedPointPtr WeightedPointPtr;
35  typedef typename B::WeightedPtrVec WeightedPtrVec;
36  typedef typename B::WeightedValue WeightedValue;
37  typedef typename B::WeightedValueVec WeightedValueVec;
38 
39  /**
40  // Constructor arguments are as follows:
41  //
42  // smoothND -- copula smoother pointer
43  //
44  // smooth1D -- array of pointers for margin smoothers
45  //
46  // boxBuilder -- pointer for the response box builder
47  //
48  // takePointerOwnership -- if true, delete smoothND, boxBuilder,
49  // and pointers inside smooth1D in the
50  // destructor
51  //
52  // interpolationDegreeCopula -- interpolation degree for the
53  // copula density array. Currently
54  // must be 0 or 1, limited by the
55  // abilities of BinnedDensityND
56  // class.
57  //
58  // interpolationDegreeMarginals -- interpolation degree for the
59  // marginal density array. Currently
60  // must be 0 or 1, limited by the
61  // abilities of BinnedDensity1D
62  // class.
63  */
65  AbsCopulaSmootherBase* smoothND,
66  const std::vector<AbsMarginalSmootherBase*>& smooth1D,
67  AbsResponseBoxBuilder<Point>* boxBuilder,
68  bool takePointerOwnership,
69  unsigned interpolationDegreeCopula = 1U,
70  unsigned interpolationDegreeMarginals = 1U);
71 
73 
74  /** Bandwidth factor used in the most recent copula smoothing */
75  inline double lastCopulaBandwidth() const
76  {return copulaBandwidth_;}
77 
78  /** Bandwidth used in the most recent smoothing of the marginals */
79  inline double lastMarginBandwidth(const unsigned i) const
80  {return marginBandwidth_.at(i);}
81 
82  /** Dimensionality of the reconstructed density */
83  inline unsigned dim() const {return smooth1D_.size();}
84 
85  /** Set the archive for storing the histograms */
86  void setArchive(gs::AbsArchive* ar, const char* category = 0);
87 
88  private:
93 
94  virtual BoxND<double> makeResponseBox(
95  unsigned long uniqueId,
96  const double* predictorCoords, unsigned nPredictors,
97  const BoxND<double>& predictorBox,
98  std::vector<OrderedPointND<Point> >& data) const;
99 
100  virtual BoxND<double> makeResponseBoxW(
101  unsigned long uniqueId,
102  const double* predictorCoords, unsigned nPredictors,
103  const BoxND<double>& predictorBox, const WeightedPtrVec& data,
104  const unsigned* dimsToUse, unsigned nDimsToUse) const;
105 
106  virtual AbsDistribution1D* buildMarginal(
107  unsigned long uniqueId, unsigned dimNumber,
108  const Interval<double>& responseRange,
109  const std::vector<typename Point::value_type>&) const;
110 
111  virtual AbsDistributionND* buildCopula(
112  unsigned long uniqueId, std::vector<OrderedPointND<Point> >&) const;
113 
114  virtual AbsDistribution1D* buildMarginalW(
115  unsigned long uniqueId, unsigned dimUsed, unsigned dimNumber,
116  const Interval<double>& responseRange,
117  const WeightedValueVec& data) const;
118 
119  virtual AbsDistributionND* buildCopulaW(unsigned long uniqueId,
120  const WeightedPtrVec& data,
121  const unsigned* dimsToUse,
122  unsigned nDimsToUse) const;
123  AbsCopulaSmootherBase* smoothND_;
124  std::vector<AbsMarginalSmootherBase*> smooth1D_;
125  AbsResponseBoxBuilder<Point>* boxBuilder_;
126  mutable std::vector<double> marginBandwidth_;
127  mutable double copulaBandwidth_;
128  unsigned iDegCopula_;
129  unsigned iDegMarginals_;
130  bool takePointerOwnership_;
131  };
132 }
133 
134 #include "npstat/stat/NonparametricCompositeBuilder.icc"
135 
136 #endif // NPSTAT_NONPARAMETRICCOMPOSITEBUILDER_HH_
Interface definition for classes which build composite distrubutions.
Interface definition for classes which build discrete copulas.
Interface definition for 1-d nonparametric density estimation.
Base class for building response boxes for multivariate density estimation in regression context.
Definition: AbsCompositeDistroBuilder.hh:30
Definition: AbsCopulaSmootherBase.hh:31
Definition: AbsDistributionND.hh:26
Definition: AbsResponseBoxBuilder.hh:23
Definition: Interval.hh:29
Definition: NonparametricCompositeBuilder.hh:31
double lastMarginBandwidth(const unsigned i) const
Definition: NonparametricCompositeBuilder.hh:79
NonparametricCompositeBuilder(AbsCopulaSmootherBase *smoothND, const std::vector< AbsMarginalSmootherBase * > &smooth1D, AbsResponseBoxBuilder< Point > *boxBuilder, bool takePointerOwnership, unsigned interpolationDegreeCopula=1U, unsigned interpolationDegreeMarginals=1U)
unsigned dim() const
Definition: NonparametricCompositeBuilder.hh:83
double lastCopulaBandwidth() const
Definition: NonparametricCompositeBuilder.hh:75
void setArchive(gs::AbsArchive *ar, const char *category=0)
Definition: OrderedPointND.hh:40
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31