npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
VerticallyInterpolatedDistribution1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_VERTICALLYINTERPOLATEDDISTRIBUTION1D_HH_
2 #define NPSTAT_VERTICALLYINTERPOLATEDDISTRIBUTION1D_HH_
3 
4 /*!
5 // \file VerticallyInterpolatedDistribution1D.hh
6 //
7 // \brief Interpolation of 1-d distributions via linear interpolation
8 // of densities
9 //
10 // Author: I. Volobouev
11 //
12 // July 2015
13 */
14 
15 #include <vector>
16 
17 #include "npstat/stat/WeightedDistro1DPtr.hh"
19 
20 namespace npstat {
21  /**
22  // 1-d continuous statistical distribution which interpolates between
23  // other distributions by performing linear interpolation of their
24  // densities.
25  //
26  // Note that the interpolated distributions must still exist while this
27  // object is in use (this class neither owns nor copies them).
28  */
31  {
32  public:
33  /**
34  // It is expected that the object will be constructed
35  // incrementally: first, the constructor will be called
36  // using the expected number of distributions to use
37  // and then function "add" will be used to put the
38  // distributions and weights in. Use the default constructor
39  // if the number of distributions is not known in advance
40  // (the class will still operate as expected but the
41  // performance will take a hit).
42  */
43  explicit VerticallyInterpolatedDistribution1D(unsigned expectedNDistros);
44 
46 
47  inline virtual ~VerticallyInterpolatedDistribution1D() {}
48 
50  {return new VerticallyInterpolatedDistribution1D(*this);}
51 
52  /**
53  // Add a new distribution. Note that, unlike DistributionMix1D,
54  // this class will continue using the reference instead of making
55  // a copy of the distribution.
56  */
57  void add(const AbsDistribution1D& d, double weight);
58 
59  /** Replace an existing distribution */
60  void replace(unsigned i, const AbsDistribution1D& d, double weight);
61 
62  /** Modify the weight for an existing dostribution */
63  void setWeight(unsigned i, double weight);
64 
65  /** Clear all distributions */
66  void clear();
67 
68  /**
69  // The following function should be called to disable
70  // (and later enable) automatic weight normalization
71  // if you want to use the "setWeight" or "replace" methods
72  // many times and, especially, if at some point in this process
73  // the sum of the weights becomes zero. The "density" method
74  // can not be called if normalization is not enabled.
75  */
76  void normalizeAutomatically(bool allow);
77 
78  /** The number of distributions participating in the interpolation */
79  inline unsigned size() const {return count_;}
80 
81  inline unsigned expectedSize() const {return nExpected_;}
82 
83  // Methods inherited from AbsDistribution1D
84  double density(double x) const;
85  double cdf(double x) const;
86  double exceedance(double x) const;
87  double quantile(double x) const;
88 
89  // Methods needed for I/O
90  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
91 
92  static inline const char* classname()
93  {return "npstat::VerticallyInterpolatedDistribution1D";}
94  static inline unsigned version() {return 1;}
95 
96  protected:
97  virtual bool isEqual(const AbsDistribution1D&) const;
98 
99  private:
100  void normalize();
101 
102  std::vector<Private::WeightedDistro1DPtr> wdmem_;
103  unsigned nExpected_;
104  unsigned count_;
105  double wsum_;
106  double xmin_;
107  double xmax_;
108  bool autoNormalize_;
109  };
110 }
111 
112 #endif // NPSTAT_VERTICALLYINTERPOLATEDDISTRIBUTION1D_HH_
Interface for interpolating 1-d distributions.
Definition: AbsInterpolatedDistribution1D.hh:18
Definition: VerticallyInterpolatedDistribution1D.hh:31
virtual bool isEqual(const AbsDistribution1D &) const
void add(const AbsDistribution1D &d, double weight)
virtual VerticallyInterpolatedDistribution1D * clone() const
Definition: VerticallyInterpolatedDistribution1D.hh:49
void replace(unsigned i, const AbsDistribution1D &d, double weight)
virtual gs::ClassId classId() const
Definition: VerticallyInterpolatedDistribution1D.hh:90
unsigned expectedSize() const
Definition: VerticallyInterpolatedDistribution1D.hh:81
unsigned size() const
Definition: VerticallyInterpolatedDistribution1D.hh:79
void setWeight(unsigned i, double weight)
VerticallyInterpolatedDistribution1D(unsigned expectedNDistros)
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31