1 #ifndef NPSTAT_LORPE1D_HH_
2 #define NPSTAT_LORPE1D_HH_
23 template <
class Numeric>
27 typedef Numeric point_type;
30 const Numeric* i_coords,
const unsigned long i_nCoords)
31 : kernel_(i_kernel), coords_(i_coords, i_coords + i_nCoords)
33 if (coords_.empty())
throw std::invalid_argument(
34 "In npstat::LOrPE1D constructor: empty point sample");
40 const std::vector<Numeric>& i_coords)
41 : kernel_(i_kernel), coords_(i_coords)
43 if (coords_.empty())
throw std::invalid_argument(
44 "In npstat::LOrPE1D constructor: empty point sample");
50 inline void setNormFactor(
const double d)
55 inline void setSample(
const Numeric* i_coords,
56 const unsigned long i_nCoords)
58 if (!i_nCoords)
throw std::invalid_argument(
59 "In npstat::LOrPE1D::setSample: empty point sample");
62 coords_.reserve(i_nCoords);
63 std::copy(i_coords, i_coords+i_nCoords, std::back_inserter(coords_));
67 inline void setSample(
const std::vector<Numeric>& i_coords)
69 if (i_coords.empty())
throw std::invalid_argument(
70 "In npstat::LOrPE1D::setSample: empty point sample");
80 inline void setWeights(
const double* weights,
unsigned long nWeights)
82 if (nWeights != coords_.size())
throw std::invalid_argument(
83 "In npstat::LOrPE1D::setWeights: "
84 "incompatible length of the weight array");
86 setStandardNormfactor();
93 inline double normFactor()
const {
return kernel_.normFactor();}
94 inline const std::vector<Numeric>& coords()
const {
return coords_;}
95 inline unsigned long nCoords()
const {
return coords_.size();}
96 inline Numeric minCoordinate()
const {
return coords_[0];}
97 inline Numeric maxCoordinate()
const {
return coords_.back();}
98 inline double totalSampleWeight()
const
99 {
return Private::SampleWeight<Numeric>(coords_).value;}
100 inline double effectiveSampleSize()
const
102 const double sumw = Private::SampleWeight<Numeric>(coords_).value;
103 const double sumWsq = Private::SampleSquaredWeight<Numeric>(coords_).value;
104 return sumw/sumWsq*sumw;
107 inline double pointCoordinate(
const unsigned long i)
const
110 Private::coordAndWeight(coords_[i], &x, &w);
114 inline double pointWeight(
const unsigned long i)
const
117 Private::coordAndWeight(coords_[i], &x, &w);
124 inline double cvLocalizingWeight(
const double )
const {
return 1.0;}
127 inline double density(
const double x,
const double bw)
const
128 {
return kernel_.
lorpe(x, bw, &coords_[0], coords_.size(),
true);}
138 template <
typename Fcn>
140 Fcn bandwidthFunctor)
const
143 kernel_, bandwidthFunctor, &coords_[0], coords_.size(),
true);
147 double densityIntegral(
148 unsigned nIntegIntervals,
unsigned nIntegPoints,
149 Fcn bandwidthFunctor)
const;
152 double integratedSquaredError(
154 const unsigned nIntegIntervals,
const unsigned nIntegPoints,
155 Fcn bandwidthFunctor)
const;
164 unsigned nIntegIntervals,
unsigned nIntegPoints,
165 Fcn bandwidthFunctor);
167 inline bool operator==(
const LOrPE1D& r)
const
168 {
return kernel_ == r.kernel_ && coords_ == r.coords_;}
169 inline bool operator!=(
const LOrPE1D& r)
const
170 {
return !(*
this == r);}
176 inline void sortAndNormalize()
178 std::sort(coords_.begin(), coords_.end());
179 setStandardNormfactor();
182 inline void setStandardNormfactor()
184 const double w = Private::SampleWeight<Numeric>(coords_).value;
185 if (w <= 0.0)
throw std::invalid_argument(
186 "In npstat::LOrPE1D::setStandardNormfactor: "
187 "total sample weight must be positive");
191 LOrPE1DSymbetaKernel kernel_;
192 std::vector<Numeric> coords_;
196 #include "npstat/stat/LOrPE1D.icc"
Gaussian or symmetric beta kernels for unbinned LOrPE.
Definition: LOrPE1DSymbetaKernel.hh:173
Definition: LOrPE1DSymbetaKernel.hh:28
void setNormFactor(double normfactor)
double lorpe(double x, double bandwidth, const Numeric *coords, unsigned long nCoords, bool coordinatesSorted=false) const
Definition: LOrPE1D.hh:25
void setWeights(const double *weights, unsigned long nWeights)
Definition: LOrPE1D.hh:80
bool normalizingLOrPEEstimate() const
Definition: LOrPE1D.hh:90
LOrPE1DFunctorHelper< Numeric, Fcn > densityFunctor(Fcn bandwidthFunctor) const
Definition: LOrPE1D.hh:139
double bandwidthCurve(const double) const
Definition: LOrPE1D.hh:123
static bool cvCapable()
Definition: LOrPE1D.hh:173
double normalizeDensityEstimate(unsigned nIntegIntervals, unsigned nIntegPoints, Fcn bandwidthFunctor)
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31
Definition: coordAndWeight.hh:104