|
Go to the documentation of this file. 1 #ifndef NPSTAT_KDE1D_HH_
2 #define NPSTAT_KDE1D_HH_
24 template < class Numeric>
29 const Numeric* i_coords, const unsigned long i_nCoords)
30 : kernel_(0), coords_(i_coords, i_coords + i_nCoords)
32 if (coords_.empty()) throw std::invalid_argument(
33 "In npstat::KDE1D constructor: empty point sample");
35 std::sort(coords_.begin(), coords_.end());
36 kernel_ = i_kernel. clone();
40 const std::vector<Numeric>& i_coords)
41 : kernel_(0), coords_(i_coords)
43 if (coords_.empty()) throw std::invalid_argument(
44 "In npstat::KDE1D constructor: empty point sample");
45 std::sort(coords_.begin(), coords_.end());
46 kernel_ = i_kernel. clone();
50 : kernel_(r.kernel_-> clone()), coords_(r.coords_) {}
56 delete kernel_; kernel_ = 0;
58 kernel_ = r.kernel_-> clone();
63 inline ~ KDE1D() { delete kernel_;}
65 inline void setNormFactor( const double d) {kernel_->setNormFactor(d);}
67 inline void setSample( const Numeric* i_coords, const unsigned long i_nCoords)
69 if (!i_nCoords) throw std::invalid_argument(
70 "In npstat::KDE1D::setSample: empty point sample");
73 coords_.reserve(i_nCoords);
74 std::copy(i_coords, i_coords+i_nCoords, std::back_inserter(coords_));
75 std::sort(coords_.begin(), coords_.end());
78 inline void setSample( const std::vector<Numeric>& i_coords)
80 if (i_coords.empty()) throw std::invalid_argument(
81 "In npstat::KDE1D::setSample: empty point sample");
83 std::sort(coords_.begin(), coords_.end());
87 inline double normFactor() const { return kernel_->normFactor();}
88 inline const std::vector<Numeric>& coords() const { return coords_;}
89 inline unsigned long nCoords() const { return coords_.size();}
90 inline Numeric minCoordinate() const { return coords_[0];}
91 inline Numeric maxCoordinate() const { return coords_.back();}
93 inline double density( const double x, const double bw) const
94 { return kernel_-> kde(x, bw, &coords_[0], coords_.size(), true);}
102 const double bandwidth) const
105 *kernel_, bandwidth, &coords_[0], coords_.size(), true, false);
109 const double plcvAlpha) const
112 &coords_[0], coords_.size(), true);
115 inline KDE1DLSCVFunctorHelper<Numeric> lscvFunctor(
116 const double xmin, const double xmax,
117 const unsigned nIntegIntervals, const unsigned nIntegPoints) const
120 nIntegIntervals, nIntegPoints,
121 &coords_[0], coords_.size(), true);
125 inline double densityIntegral(
126 const double xmin, const double xmax,
127 const unsigned nIntegIntervals, const unsigned nIntegPoints,
128 const double bandwidth) const
130 GaussLegendreQuadrature glq(nIntegPoints);
132 xmin, xmax, nIntegIntervals);
135 inline double integratedSquaredError(
136 const AbsDistribution1D& distro,
137 const unsigned nIntegIntervals, const unsigned nIntegPoints,
138 const double bandwidth) const
141 distro, nIntegIntervals, nIntegPoints, bandwidth,
142 false, &coords_[0], coords_.size(), true);
145 inline double rlcv( const double bw, const double plcvAlpha) const
148 &coords_[0], coords_.size(), true)(bw);
151 inline double lscv( const double bw,
152 const double xmin, const double xmax,
153 const unsigned nIntegIntervals,
154 const unsigned nIntegPoints) const
157 nIntegIntervals, nIntegPoints,
158 &coords_[0], coords_.size(), true)(bw);
162 AbsKDE1DKernel* kernel_;
163 std::vector<Numeric> coords_;
Gauss-Legendre quadratures in long double precision.
Cross-validation utilities for brute-force KDE in 1-d.
Definition: AbsKDE1DKernel.hh:23
double integratedSquaredError(const AbsDistribution1D &distro, unsigned nIntegIntervals, unsigned nIntegPoints, double bandwidth, bool useReverseKde, const Numeric *coords, unsigned long nCoords, bool coordinatesSorted=false) const
double kde(double x, double bandwidth, const Numeric *coords, unsigned long nCoords, bool coordinatesSorted=false) const
virtual AbsKDE1DKernel * clone() const =0
Definition: AbsKDE1DKernel.hh:234
Definition: KDE1DCV.hh:107
KDE1DFunctorHelper< Numeric > densityFunctor(const double bandwidth) const Definition: KDE1D.hh:101
Definition: AbsArrayProjector.hh:14
KDE1DRLCVFunctorHelper< Numeric > KDE1DRLCVFunctor(const AbsKDE1DKernel &kernel, const double plcvAlpha, const Numeric *coords, const unsigned long nCoords, const bool coordinatesSorted=false, const bool useReverseKde=false) Definition: KDE1DCV.hh:160
KDE1DLSCVFunctorHelper< Numeric > KDE1DLSCVFunctor(const AbsKDE1DKernel &kernel, const double xmin, const double xmax, const unsigned nIntegIntervals, const unsigned nIntegPoints, const Numeric *coords, const unsigned long nCoords, const bool coordinatesSorted=false, const bool useReverseKde=false) Definition: KDE1DCV.hh:82
|