npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsCVCopulaSmoother.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSCVCOPULASMOOTHER_HH_
2 #define NPSTAT_ABSCVCOPULASMOOTHER_HH_
3 
4 /*!
5 // \file AbsCVCopulaSmoother.hh
6 //
7 // \brief Interface definition for smoothing copulas with cross-validation
8 //
9 // Abbreviation "CV" used in various places in this code stands for
10 // "cross-validation"
11 //
12 // Author: I. Volobouev
13 //
14 // June 2015
15 */
16 
18 
19 namespace npstat {
21  {
22  public:
23  inline virtual ~AbsCVCopulaSmoother() {}
24 
25  /** Check how the kernel is used */
26  inline bool isConvolving() const {return useConvolute_;}
27 
28  /**
29  // Use either "filter" (kernel placement at the points in which
30  // the density is estimated) or "convolve" mode (kernel placement
31  // at the sample points)
32  */
33  inline void setConvolving(const bool b) {useConvolute_ = b;}
34 
35  /** Bandwidth values to cross-validate */
36  inline const std::vector<double>& bandwidthValues() const
37  {return bandwidthValues_;}
38 
39  /** Calculated values of the cross-validation criterion */
40  inline const std::vector<double>& lastCVValues() const
41  {return cvValues_;}
42 
43  /** Fraction of bins that was affected by regularization */
44  inline const std::vector<double>& lastRegularizedFractions() const
45  {return regFractions_;}
46 
47  /** Number of bandwidth values to cross-validate */
48  inline unsigned getNFilters() const {return bandwidthValues_.size();}
49 
50  /** Index of the bandwidth best according to cross-validation */
51  inline unsigned lastFilterChosen() const {return bestFilt_;}
52 
53  protected:
54  /**
55  // Constructor arguments are as follows:
56  //
57  // nBinsInEachDim -- number of copula bins in each dimension
58  //
59  // dim -- copula dimensionality
60  //
61  // marginTolerance -- tolerance for the margin to be uniform
62  //
63  // maxNormCycles -- max number of copula normalization cycles
64  //
65  // initialBw -- "central" bandwidth for cross validation
66  // calculations (or the actual bandwidth used
67  // in case cross validation is not performed).
68  // Set this parameter to 0.0 in order to
69  // disable filtering altogether.
70  //
71  // cvRange -- we will scan bandwidth values between
72  // initialBw/cvRange and initialBw*cvRange
73  // uniformly in the log space.
74  //
75  // nCV -- number of bandwidth values to try in the
76  // bandwidth scan. If this number is even, it
77  // will be increased by 1 internally so that
78  // the "central" bandwidth is included in
79  // the scan. If this parameter is 0 or 1, the
80  // value given by "initialBw" will be used
81  // and cross-validation will not be performed.
82  //
83  // useConvolve -- if "true", use "convolve" method of the
84  // filter rather than "filter" method.
85  */
86  AbsCVCopulaSmoother(const unsigned* nBinsInEachDim, unsigned dim,
87  double marginTolerance, unsigned maxNormCycles,
88  double initialBw, double cvRange, unsigned nCV,
89  bool useConvolve);
90  /**
91  // Constructor which explicitly specifies the complete set of
92  // bandwidth values to use in cross-validation
93  */
94  AbsCVCopulaSmoother(const unsigned* nBinsInEachDim, unsigned dim,
95  double marginTolerance, unsigned maxNormCycles,
96  const std::vector<double>& bandwidthValues,
97  bool useConvolve);
98  private:
99  // Override from the base class
100  void smoothHisto(HistoND<double>& histo,
101  double effectiveSampleSize,
102  double* bandwidthUsed,
103  bool isSampleWeighted);
104 
105  // This method should return the value of the cross-validation
106  // criterion to be maximized in case "runCrossValidation"
107  // argument is "true" (and, of course, fill out the "result",
108  // "regularizedFraction", and "isNonNegativeAndNormalized").
109  // In case "runCrossValidation" argument is "false", the
110  // smoothing should be performed but the result of the
111  // cross-validation calculation will be ignored (so, to save
112  // time, it is unnecessary to run this calculation).
113  virtual double smoothAndCV(const HistoND<double>& histo,
114  double effectiveSampleSize,
115  bool isSampleWeighted,
116  unsigned bandwidthIndex,
117  bool runCrossValidation,
118  ArrayND<double>* result,
119  double* regularizedFraction,
120  bool* isNonNegativeAndNormalized) = 0;
121 
122  std::vector<double> bandwidthValues_;
123  std::vector<double> cvValues_;
124  std::vector<double> regFractions_;
125  ArrayND<double> density_;
126  unsigned bestFilt_;
127  bool useConvolute_;
128  };
129 }
130 
131 #endif // NPSTAT_ABSCVCOPULASMOOTHER_HH_
Interface definition for classes which build discrete copulas.
Definition: AbsCVCopulaSmoother.hh:21
AbsCVCopulaSmoother(const unsigned *nBinsInEachDim, unsigned dim, double marginTolerance, unsigned maxNormCycles, double initialBw, double cvRange, unsigned nCV, bool useConvolve)
const std::vector< double > & lastRegularizedFractions() const
Definition: AbsCVCopulaSmoother.hh:44
bool isConvolving() const
Definition: AbsCVCopulaSmoother.hh:26
const std::vector< double > & bandwidthValues() const
Definition: AbsCVCopulaSmoother.hh:36
unsigned getNFilters() const
Definition: AbsCVCopulaSmoother.hh:48
AbsCVCopulaSmoother(const unsigned *nBinsInEachDim, unsigned dim, double marginTolerance, unsigned maxNormCycles, const std::vector< double > &bandwidthValues, bool useConvolve)
void setConvolving(const bool b)
Definition: AbsCVCopulaSmoother.hh:33
const std::vector< double > & lastCVValues() const
Definition: AbsCVCopulaSmoother.hh:40
unsigned lastFilterChosen() const
Definition: AbsCVCopulaSmoother.hh:51
Definition: AbsCopulaSmootherBase.hh:31
Definition: AbsArrayProjector.hh:14