npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
LegendreDistro1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_LEGENDREDISTRO1D_HH_
2 #define NPSTAT_LEGENDREDISTRO1D_HH_
3 
4 /*!
5 // \file LegendreDistro1D.hh
6 //
7 // \brief Statistical distribution constructed using orthonormal
8 // Legendre polynomial series
9 //
10 // Author: I. Volobouev
11 //
12 // February 2023
13 */
14 
16 
18 
19 namespace npstat {
20  /**
21  // A distribution whose density is a series in terms of
22  // orthonormal Legendre polynomials on [-1, 1]. The series
23  // coefficients start with degree 1 (note, not 0).
24  */
26  {
27  public:
28  LegendreDistro1D(double location, double scale,
29  const double* coeffs, unsigned maxdeg,
30  bool ensurePositivity = true);
31 
32  LegendreDistro1D(double location, double scale,
33  const std::vector<double>& coeffs,
34  bool ensurePositivity = true);
35 
36  inline virtual LegendreDistro1D* clone() const
37  {return new LegendreDistro1D(*this);}
38 
39  inline virtual ~LegendreDistro1D() {}
40 
41  inline bool isPositive() const {return isPositive_;};
42 
43  // Methods needed for I/O
44  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
45  virtual bool write(std::ostream& os) const;
46 
47  static inline const char* classname()
48  {return "npstat::LegendreDistro1D";}
49  static inline unsigned version() {return 2;}
50  static LegendreDistro1D* read(const gs::ClassId& id, std::istream& in);
51 
52  protected:
53  virtual bool isEqual(const AbsDistribution1D&) const;
54 
55  private:
57 
58  inline static int nParameters() {return -1;}
59 
60  double unscaledDensity(double x) const;
61  double unscaledCdf(double x) const;
62  double unscaledQuantile(double x) const;
63  double unscaledExceedance(double x) const;
64 
65  void checkPositive(bool validatePositivity);
66  void setupCoeffs(const double* coeffs, unsigned maxdeg);
67 
68  LegendreOrthoPoly1D poly_;
69  std::vector<double> allCoeffs_;
70  std::vector<double> integCoeffs_;
71  bool isPositive_;
72  };
73 }
74 
75 #endif // NPSTAT_LEGENDREDISTRO1D_HH_
Orthonormal versions of some classical orthogonal polynomials.
Factories for 1-d distributions for use in interpretive language environments.
Definition: AbsDistribution1D.hh:165
double scale() const
Definition: AbsDistribution1D.hh:183
double location() const
Definition: AbsDistribution1D.hh:180
Definition: LegendreDistro1D.hh:26
virtual bool isEqual(const AbsDistribution1D &) const
virtual LegendreDistro1D * clone() const
Definition: LegendreDistro1D.hh:36
virtual gs::ClassId classId() const
Definition: LegendreDistro1D.hh:44
Definition: ClassicalOrthoPolys1D.hh:23
Definition: Distribution1DFactory.hh:35
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31