|
Go to the documentation of this file. 1 #ifndef NPSTAT_ABSKDE1DKERNEL_HH_
2 #define NPSTAT_ABSKDE1DKERNEL_HH_
27 virtual void setNormFactor( double normfactor) = 0;
29 virtual double xmin() const = 0;
30 virtual double xmax() const = 0;
31 virtual double normFactor() const = 0;
33 virtual double operator()( double x) const = 0;
45 virtual double squaredIntegral( unsigned nIntegPoints) const;
54 template < typename Numeric>
55 double kde( double x, double bandwidth,
56 const Numeric* coords, unsigned long nCoords,
57 bool coordinatesSorted = false) const;
60 template < typename Numeric>
62 const Numeric* coords, unsigned long nCoords,
63 bool coordinatesSorted = false) const;
71 double looKde( double bandwidth, unsigned long nCoords,
72 double originalDensityEstimate) const;
80 template < typename Numeric>
82 unsigned nIntegIntervals, unsigned nIntegPoints,
83 double bandwidth, bool useReverseKde,
84 const Numeric* coords, unsigned long nCoords,
85 bool coordinatesSorted = false) const;
92 template < typename Numeric>
94 double xmin, double xmax,
95 unsigned nIntegIntervals, unsigned nIntegPoints,
96 double bandwidth, bool useReverseKde,
97 const Numeric* coords, unsigned long nCoords,
98 bool coordinatesSorted = false) const;
104 : kernel(ref), xpow(power) {}
108 inline double operator()( const double& x) const
109 { return kernel(x)*(xpow ? pow(x, xpow) : 1.0);}
123 inline double operator()( const double& x) const
124 { const double k = kernel(x); return k*k;}
132 inline double kde2( double x, double bandwidth,
133 const double* coords, unsigned nCoords,
134 bool coordinatesSorted = false) const
136 return kde(x, bandwidth, coords, nCoords, coordinatesSorted);
139 inline double reverseKde2( double x, double bandwidth,
140 const double* coords, unsigned nCoords,
141 bool coordinatesSorted = false) const
143 return reverseKde(x, bandwidth, coords, nCoords, coordinatesSorted);
146 inline double integratedSquaredError2(
147 const AbsDistribution1D& distro,
148 unsigned nIntegIntervals, unsigned nIntegPoints,
149 double bandwidth, bool useReverseKde,
150 const double* coords, unsigned nCoords,
151 bool coordinatesSorted = false) const
154 bandwidth, useReverseKde, coords, nCoords,
158 inline double integratedKdeSquared2(
159 double xmin, double xmax,
160 unsigned nIntegIntervals, unsigned nIntegPoints,
161 double bandwidth, bool useReverseKde,
162 const double* coords, unsigned nCoords,
163 bool coordinatesSorted = false) const
166 bandwidth, useReverseKde, coords, nCoords,
177 const double normfactor=1.0)
178 : distro_(0), norm_(0.0)
180 setNormFactor(normfactor);
185 : distro_(0), norm_(r.norm_) {distro_ = r.distro_-> clone();}
193 distro_ = r.distro_-> clone();
204 inline virtual void setNormFactor( const double normfactor)
206 if (normfactor <= 0.0) throw std::invalid_argument(
207 "In npstat::KDE1DDensityKernel::setNormFactor: "
208 "normalization factor must be positive");
212 inline double xmin() const { return distro_-> quantile(0.0);}
213 inline double xmax() const { return distro_-> quantile(1.0);}
214 inline double normFactor() const { return norm_;}
216 inline double operator()( const double x) const
217 { return norm_*distro_-> density(x);}
220 AbsDistribution1D* distro_;
232 template < typename Numeric>
237 const double bandwidth,
238 const Numeric* coords,
239 const unsigned long nCoords,
240 const bool coordinatesSorted,
241 const bool useReverseKde)
242 : kernel_(kernel), bandwidth_(bandwidth),
243 coords_(coords), nCoords_(nCoords),
244 coordinatesSorted_(coordinatesSorted),
245 useReverseKde_(useReverseKde) {}
249 inline double operator()( const double& x) const
253 kde = kernel_. reverseKde(x, bandwidth_, coords_, nCoords_,
256 kde = kernel_. kde(x, bandwidth_, coords_, nCoords_,
264 const Numeric* coords_;
265 unsigned long nCoords_;
266 bool coordinatesSorted_;
271 template < typename Numeric>
274 const Numeric* coords, const unsigned long nCoords,
275 const bool coordinatesSorted = false, const bool useReverseKde = false)
278 coordinatesSorted, useReverseKde);
286 const double bandwidth,
287 const bool useReverseKde = false)
288 : kernel_(kernel), bandwidth_(bandwidth),
289 useReverseKde_(useReverseKde)
291 if (bandwidth_ <= 0.0) throw std::invalid_argument(
292 "In npstat::KDE1DFunctor2 constructor: bandwidth must be positive");
297 inline double operator()( const double& x, const double& y) const
299 const double delta = useReverseKde_ ? x - y : y - x;
300 return kernel_(delta/bandwidth_)/bandwidth_;
310 #include "npstat/stat/AbsKDE1DKernel.icc"
Interface definition for 1-d continuous statistical distributions.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: AbsKDE1DKernel.hh:101
Definition: AbsKDE1DKernel.hh:116
Definition: AbsKDE1DKernel.hh:23
double reverseKde(double x, double bandwidth, const Numeric *coords, unsigned long nCoords, bool coordinatesSorted=false) const
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
double looKde(double bandwidth, unsigned long nCoords, double originalDensityEstimate) const
double integratedKdeSquared(double xmin, double xmax, unsigned nIntegIntervals, unsigned nIntegPoints, double bandwidth, bool useReverseKde, const Numeric *coords, unsigned long nCoords, bool coordinatesSorted=false) const
virtual double momentIntegral(unsigned k, unsigned nIntegPoints) const
virtual AbsKDE1DKernel * clone() const =0
Definition: AbsKDE1DKernel.hh:174
virtual KDE1DDensityKernel * clone() const Definition: AbsKDE1DKernel.hh:199
Definition: AbsKDE1DKernel.hh:283
Definition: AbsKDE1DKernel.hh:234
Definition: AbsArrayProjector.hh:14
KDE1DFunctorHelper< Numeric > KDE1DFunctor(const AbsKDE1DKernel &kernel, const double bandwidth, const Numeric *coords, const unsigned long nCoords, const bool coordinatesSorted=false, const bool useReverseKde=false) Definition: AbsKDE1DKernel.hh:272
Definition: AbsDistribution1D.hh:31
virtual double density(double x) const =0
virtual AbsDistribution1D * clone() const =0
virtual double quantile(double x) const =0
Definition: SimpleFunctors.hh:58
Definition: SimpleFunctors.hh:89
|