npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsBinnedComparison1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSBINNEDCOMPARISON1D_HH_
2 #define NPSTAT_ABSBINNEDCOMPARISON1D_HH_
3 
4 /*!
5 // \file AbsBinnedComparison1D.hh
6 //
7 // \brief Interface definition for comparing binned samples and/or densities
8 //
9 // Author: I. Volobouev
10 //
11 // May 2014
12 */
13 
14 #include <vector>
15 
16 namespace npstat {
17  struct AbsDiscreteDistribution1DDistance;
18  struct AbsRandomGenerator;
19  class DiscreteTabulated1D;
20 
22  {
23  public:
24  inline virtual ~AbsBinnedComparison1D() {}
25 
26  /** Printable name identifying the comparison method */
27  virtual const char* name() const = 0;
28 
29  /**
30  // The comparison method interface. Pointers "distance" or "pvalue"
31  // can be NULL in which case the corresponding quantity does not
32  // have to be calculated. If it makes sense for a test to use
33  // a "reference" sample (e.g., exact density with no sampling
34  // uncertainty), this should be the second argument of the function.
35  //
36  // If types T1 or T2 are not doubles, the corresponding arrays
37  // will be converted to doubles internally.
38  */
39  template<typename T1, typename T2>
40  void compare(const T1* data, const T2* reference, unsigned len,
41  double* distance, double* pvalue) const;
42 
43  protected:
44  // Helper function for converting real numbers into unsigned.
45  // Will throw std::invalid_argument if the input is negative
46  // or larger than the largest unsigned long.
47  static unsigned long realToULong(const long double d);
48 
49  // Helper function for calculating p-values by running
50  // pseudo-experiments. Sample size of 0.5 or less indicates
51  // infinitelty precise density which will not be sampled.
52  static double pvalueByPseudo(const AbsDiscreteDistribution1DDistance& c,
53  AbsRandomGenerator& rng,
54  const DiscreteTabulated1D& data,
55  double dataSampleSize,
56  const DiscreteTabulated1D& reference,
57  double refSampleSize,
58  double observedDistance, unsigned nPseudo);
59  private:
60  // Main comparison function to be overriden by derived classes
61  virtual void compareD(const double* data, const double* reference,
62  unsigned len, double* distance,
63  double* pvalue) const = 0;
64 
65  mutable std::vector<double> buf1_;
66  mutable std::vector<double> buf2_;
67  };
68 }
69 
70 #include "npstat/stat/AbsBinnedComparison1D.icc"
71 
72 #endif // NPSTAT_ABSBINNEDCOMPARISON1D_HH_
Definition: AbsBinnedComparison1D.hh:22
virtual const char * name() const =0
void compare(const T1 *data, const T2 *reference, unsigned len, double *distance, double *pvalue) const
Definition: DiscreteDistributions1D.hh:21
Definition: AbsArrayProjector.hh:14
Definition: AbsDiscreteDistribution1D.hh:161
Definition: AbsRandomGenerator.hh:27