npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
PLogliOSDE1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_PLOGLIOSDE1D_HH_
2 #define NPSTAT_PLOGLIOSDE1D_HH_
3 
4 /*!
5 // \file PLogliOSDE1D.hh
6 //
7 // \brief OSDE based on pseudo-log-likelihood
8 //
9 // Author: I. Volobouev
10 //
11 // March 2023
12 */
13 
14 #include <vector>
15 #include <limits>
16 
17 #include "npstat/nm/Matrix.hh"
19 
21 
22 namespace npstat {
24  {
25  public:
26  template<typename Numeric>
27  PLogliOSDE1D(const Numeric* coords, unsigned long lenCoords,
28  double xmin, double xmax, double logTruncationX,
29  unsigned nLogTaylorTerms);
30 
31  inline double xmin() const {return xmin_;}
32  inline double xmax() const {return xmax_;}
33  inline unsigned long sampleSize() const {return nCoords_;}
34  inline double coord(unsigned long i) const
35  {return scale_*coords_.at(i) + shift_;}
36  inline double logTruncationX() const {return trlog_.truncationX();}
37  inline unsigned logTaylorTerms() const {return trlog_.nTaylorTerms();}
38 
39  // coeffs -- array of coefficients, starting with degree 1.
40  // nCoeffs -- length of the array "coeffs".
41  //
42  // The function returns the negative pseudo-log-likelihood value.
43  // Also, the following quantities are filled out on exit:
44  //
45  // gradient -- pseudo-log-likelihood gradient w.r.t. coeffs. The
46  // length of this array should be at least "nCoeffs".
47  //
48  double pseudoLogli(const double* coeffs, unsigned nCoeffs,
49  double* gradient) const;
50 
51  // Get the expectation values of the Legendre polynomials
52  // for the sample, starting with degree 1. The length of
53  // the array "coeffs" should be maxdeg.
54  void sampleCoeffs(double* coeffs, unsigned maxdeg) const;
55 
56  // Once the coefficients have been determined, get the
57  // density estimate for the original sample. Note that
58  // this density estimate will not be guaranteed positive.
59  // The coefficients start with degree 1.
60  LegendreDistro1D densityEstimate(const double* coeffs,
61  unsigned nCoeffs) const;
62 
63  // Check whether the given set of coefficients creates
64  // a series which can be used as a bona fide density.
65  // The coefficients start with degree 1.
66  inline bool isPositive(const double* coeffs,
67  const unsigned nCoeffs) const
68  {return densityEstimate(coeffs, nCoeffs).isPositive();}
69 
70  private:
71  void moveCoordsToStandardInterval();
72  void fillDerivativeTables(unsigned maxdeg) const;
73 
74  // Coordinates will be shifted and scaled to the [-1, 1] interval
75  std::vector<double> coords_;
76  unsigned long nCoords_;
77  double xmin_;
78  double xmax_;
79  double scale_;
80  double shift_;
81  TruncatedLog<double> trlog_;
82 
83  mutable std::vector<double> derivs_;
84  mutable unsigned currentMaxDeg_;
85  };
86 }
87 
88 #include "npstat/stat/PLogliOSDE1D.icc"
89 
90 #endif // NPSTAT_PLOGLIOSDE1D_HH_
Statistical distribution constructed using orthonormal Legendre polynomial series.
Template matrix class.
Truncated log function useful in maximum likelihood fitting of densities for which positivity conditi...
Definition: LegendreDistro1D.hh:26
Definition: PLogliOSDE1D.hh:24
Definition: AbsArrayProjector.hh:14