npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
CopulaInterpolationND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_COPULAINTERPOLATIONND_HH_
2 #define NPSTAT_COPULAINTERPOLATIONND_HH_
3 
4 /*!
5 // \file CopulaInterpolationND.hh
6 //
7 // \brief Interpolation of multivariate statistical distributions decomposed
8 // into copula and marginals
9 //
10 // Author: I. Volobouev
11 //
12 // March 2010
13 */
14 
17 
18 namespace npstat {
19  /**
20  // This class interpolates multivariate statistical distributions
21  // decomposed into copula and marginals. Interpolation weights are
22  // to be calculated outside of this class.
23  */
25  {
26  public:
27  /**
28  // Constructor arguments are the dimensionality of the density
29  // and the number of terms in the weighted sum which represents
30  // the interpolated density. The terms are added to the sum
31  // later, by calling "add" or "replace" methods. At least
32  // "nInterpolated" distributions must be added by the "add"
33  // method before calling the "density" method.
34  */
35  CopulaInterpolationND(unsigned dim, unsigned nInterpolated);
36 
37  inline virtual ~CopulaInterpolationND() {}
38 
39  inline virtual CopulaInterpolationND* clone() const
40  {return new CopulaInterpolationND(*this);}
41 
42  inline bool mappedByQuantiles() const {return false;}
43 
44  //@{
45  /**
46  // In this method, "d" must refer to a CompositeDistributionND object
47  */
48  void add(const AbsDistributionND& d, double weight);
49  void replace(unsigned i, const AbsDistributionND& d, double weight);
50  //@}
51 
52  /** Set the weight for the given term in the weighted sum */
53  void setWeight(unsigned i, double weight);
54 
55  /** Clear all the terms in the weighted sum */
56  void clear();
57 
58  /**
59  // This method should be called to disable
60  // (and later enable) automatic weight normalization
61  // if you want to use the "setWeight" or "replace" methods
62  // many times and, especially, if at some point in this process
63  // the sum of the weights becomes zero. The "density" and
64  // "unitMap" methods can not be called if normalization
65  // is not enabled.
66  */
67  void normalizeAutomatically(bool allow);
68 
69  /** The number of terms in the weighted sum */
70  inline unsigned size() const {return copulas_.size();}
71 
72  //@{
73  /** Interpolate the complete multivariate distribution */
74  double density(const double* x, unsigned dim) const;
75  void unitMap(const double* rnd, unsigned dim, double* x) const;
76  //@}
77 
78  /** Interpolate the copula density */
79  double copulaDensity(const double* x, unsigned dim) const;
80 
81  /** Interpolate the product of the marginals */
82  double productOfTheMarginals(const double* x, unsigned dim) const;
83 
84  //@{
85  /** Interpolate the marginal distribution for dimension "idim" */
86  double marginalDensity(unsigned idim, double x) const;
87  double marginalCdf(unsigned idim, double x) const;
88  double marginalExceedance(unsigned idim, double x) const;
89  double marginalQuantile(unsigned idim, double x) const;
90  //@}
91 
92  /** Method needed for "geners" I/O */
93  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
94 
95  // Class name for the I/O
96  static inline const char* classname()
97  {return "npstat::CopulaInterpolationND";}
98 
99  // Version number for the I/O
100  static inline unsigned version() {return 1;}
101 
102  protected:
103  virtual bool isEqual(const AbsDistributionND&) const;
104 
105  private:
106  void normalize();
107 
108  std::vector<InterpolatedDistribution1D> marginInterpolators_;
109  std::vector<WeightedND> copulas_;
110  std::vector<double> wCdf_;
111  mutable std::vector<double> work_;
112  double wsum_;
113  unsigned nInterpolated_;
114  bool autoNormalize_;
115  };
116 }
117 
118 #endif // NPSTAT_COPULAINTERPOLATIONND_HH_
Interface for multidimensional interpolation between densities.
Interpolation of 1-d distributions via linear interpolation of quantile functions.
Definition: AbsDistributionND.hh:26
unsigned dim() const
Definition: AbsDistributionND.hh:51
Definition: AbsInterpolationAlgoND.hh:18
Definition: CopulaInterpolationND.hh:25
double copulaDensity(const double *x, unsigned dim) const
void add(const AbsDistributionND &d, double weight)
double productOfTheMarginals(const double *x, unsigned dim) const
void normalizeAutomatically(bool allow)
double density(const double *x, unsigned dim) const
double marginalDensity(unsigned idim, double x) const
void unitMap(const double *rnd, unsigned dim, double *x) const
unsigned size() const
Definition: CopulaInterpolationND.hh:70
CopulaInterpolationND(unsigned dim, unsigned nInterpolated)
virtual CopulaInterpolationND * clone() const
Definition: CopulaInterpolationND.hh:39
virtual gs::ClassId classId() const
Definition: CopulaInterpolationND.hh:93
void setWeight(unsigned i, double weight)
bool mappedByQuantiles() const
Definition: CopulaInterpolationND.hh:42
Definition: AbsArrayProjector.hh:14