npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
UnitMapInterpolationND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_UNITMAPINTERPOLATIONND_HH_
2 #define NPSTAT_UNITMAPINTERPOLATIONND_HH_
3 
4 /*!
5 // \file UnitMapInterpolationND.hh
6 //
7 // \brief Interpolation of multivariate statistical distributions by
8 // conditional quantiles
9 //
10 // The interpolation will be linear (or multilinear), with user-defined
11 // weights.
12 //
13 // Author: I. Volobouev
14 //
15 // March 2010
16 */
17 
19 
20 namespace npstat {
21  /**
22  // This class interpolates multivariate statistical distributions
23  // by conditional quantiles (which is a particular mapping from the
24  // unit cube into the density support region). Interpolation weights
25  // are to be calculated outside of this class.
26  */
28  {
29  public:
30  /**
31  // The first constructor argument is the dimensionality of
32  // the density support, the second is the number of distributions
33  // which will be used in the interpolation. That number, in
34  // general, will depend on the dimensionality of the parameter
35  // space. After the object is constructed, the distributions
36  // should be added with the "add" method. It is possible to add
37  // more than "nInterpolated" distributions (which will result
38  // in a slightly less efficient code), however the user must add
39  // at least "nInterpolated" distributions before calling the
40  // "density" method. All interpolated distributions must have
41  // their unit cube mapping implemented by conditional quantiles
42  // (so that their "mappedByQuantiles" method returns "true").
43  //
44  // This class does not make copies of the interpolated distributions
45  // and works with references and pointers (making internal copies
46  // would result in a significant performance hit in a variety of
47  // typical situations). This means that all added distributions
48  // must still exist while this object is in use. It is the
49  // responsibility of the user of this class to make sure that
50  // this is indeed the case.
51  */
52  UnitMapInterpolationND(unsigned dim, unsigned nInterpolated);
53 
54  inline virtual ~UnitMapInterpolationND() {}
55 
56  inline virtual UnitMapInterpolationND* clone() const
57  {return new UnitMapInterpolationND(*this);}
58 
59  inline bool mappedByQuantiles() const {return true;}
60 
61  //@{
62  /**
63  // In this method, "d" must refer to a distribution for which
64  // "mappedByQuantiles" method returns "true".
65  */
66  void add(const AbsDistributionND& d, double weight);
67  void replace(unsigned i, const AbsDistributionND& d, double weight);
68  //@}
69 
70  /** Set the weight for the given term in the weighted sum */
71  void setWeight(unsigned i, double weight);
72 
73  /** Clear all the terms in the weighted sum */
74  void clear();
75 
76  /**
77  // This method should be called to disable
78  // (and later enable) automatic weight normalization
79  // if you want to use the "setWeight" or "replace" methods
80  // many times and, especially, if at some point in this process
81  // the sum of the weights becomes zero. The "density" and
82  // "unitMap" methods can not be called if normalization
83  // is not enabled.
84  */
85  void normalizeAutomatically(bool allow);
86 
87  /** The number of terms in the weighted sum */
88  inline unsigned size() const {return distros_.size();}
89 
90  double density(const double* x, unsigned dim) const;
91  void unitMap(const double* rnd, unsigned dim, double* x) const;
92 
93  /** Method needed for "geners" I/O */
94  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
95 
96  // Class name for the I/O
97  static inline const char* classname()
98  {return "npstat::UnitMapInterpolationND";}
99 
100  // Version number for the I/O
101  static inline unsigned version() {return 1;}
102 
103  protected:
104  virtual bool isEqual(const AbsDistributionND&) const;
105 
106  private:
107  void normalize();
108 
109  std::vector<WeightedND> distros_;
110  mutable std::vector<double> work_;
111  mutable std::vector<double> point_;
112  double wsum_;
113  unsigned nInterpolated_;
114  bool autoNormalize_;
115  };
116 }
117 
118 #endif // NPSTAT_UNITMAPINTERPOLATIONND_HH_
Interface for multidimensional interpolation between densities.
Definition: AbsDistributionND.hh:26
unsigned dim() const
Definition: AbsDistributionND.hh:51
Definition: AbsInterpolationAlgoND.hh:18
Definition: UnitMapInterpolationND.hh:28
void setWeight(unsigned i, double weight)
virtual UnitMapInterpolationND * clone() const
Definition: UnitMapInterpolationND.hh:56
unsigned size() const
Definition: UnitMapInterpolationND.hh:88
UnitMapInterpolationND(unsigned dim, unsigned nInterpolated)
void unitMap(const double *rnd, unsigned dim, double *x) const
void normalizeAutomatically(bool allow)
void add(const AbsDistributionND &d, double weight)
bool mappedByQuantiles() const
Definition: UnitMapInterpolationND.hh:59
double density(const double *x, unsigned dim) const
virtual gs::ClassId classId() const
Definition: UnitMapInterpolationND.hh:94
Definition: AbsArrayProjector.hh:14