1 #ifndef NPSTAT_LORPE1DCV_HH_
2 #define NPSTAT_LORPE1DCV_HH_
28 template <
class Helper>
33 const double filterDegree,
34 const double bwFactor)
36 filterDegree_(filterDegree),
39 if (filterDegree < 0.0)
throw std::invalid_argument(
40 "In npstat::LOrPE1DCVDensityFunctor constructor: "
41 "filter degree can not be negative");
42 if (bwFactor <= 0.0)
throw std::invalid_argument(
43 "In npstat::LOrPE1DCVDensityFunctor constructor: "
44 "bandwidth factor must be positive");
49 inline double operator()(
const double& x)
const
50 {
return helper_.density(x, filterDegree_, bwFactor_);}
53 const Helper& helper_;
58 template <
class Helper>
67 inline double operator()(
const double& x)
const
68 {
return helper_.cvLocalizingWeight(x);}
71 const Helper& helper_;
75 template <
typename Numeric,
class BwFcn,
class WFcn>
77 public Functor2<double, double, double>
80 typedef Numeric point_type;
83 const int i_symbetaPower,
84 const double i_leftBoundary,
85 const double i_rightBoundary,
87 const BwFcn& i_bandwidthFunctor,
88 const WFcn& i_localizingWeight,
89 const double i_localizingWeightXmin,
90 const double i_localizingWeightXmax,
91 const unsigned i_nIntegIntervals,
92 const unsigned i_nIntegPoints,
93 const bool i_normalizeLOrPEEstimate,
94 const std::vector<Numeric>& i_coords)
99 boundFilterDegree_(-1.0),
100 symbetaPower_(i_symbetaPower),
101 leftBoundary_(i_leftBoundary),
102 rightBoundary_(i_rightBoundary),
104 bandwidthFunctor_(i_bandwidthFunctor),
105 localizingWeight_(i_localizingWeight),
106 xminForWeight_(i_localizingWeightXmin),
107 xmaxForWeight_(i_localizingWeightXmax),
108 nIntegIntervals_(i_nIntegIntervals),
109 nIntegPoints_(i_nIntegPoints),
110 normalize_(i_normalizeLOrPEEstimate),
111 memoizeKernels_(
false),
112 memoizeNorms_(
false),
113 useMemoisingKernels_(
false)
115 if (coords_.empty())
throw std::invalid_argument(
116 "In npstat::LOrPE1DCVFunctorHelper constructor: empty point sample");
117 if (leftBoundary_ >= rightBoundary_)
throw std::invalid_argument(
118 "In npstat::LOrPE1DCVFunctorHelper constructor: invalid interval boundaries");
119 if (xminForWeight_ >= xmaxForWeight_)
throw std::invalid_argument(
120 "In npstat::LOrPE1DCVFunctorHelper constructor: invalid weight boundaries");
121 if (!nIntegIntervals_)
throw std::invalid_argument(
122 "In npstat::LOrPE1DCVFunctorHelper constructor: "
123 "number of integration intervals must be positive");
125 "In npstat::LOrPE1DCVFunctorHelper constructor: "
126 "unsupported number of integration points");
127 std::sort(coords_.begin(), coords_.end());
128 calculateEffectiveSampleSize();
133 inline void bindFilterDegree(
const double deg)
135 if (deg < 0.0)
throw std::invalid_argument(
136 "In npstat::LOrPE1DCVFunctorHelper::bindFilterDegree: "
137 "filter degree can not be negative");
138 boundFilterDegree_ = deg;
140 inline void unbindFilterDegree()
141 {boundFilterDegree_ = -1.0;}
142 inline double boundFilterDegree()
const
143 {
return boundFilterDegree_;}
149 inline virtual void setWeights(
const double* weights,
unsigned long nWeights)
151 if (nWeights != coords_.size())
throw std::invalid_argument(
152 "In npstat::LOrPE1DCVFunctorHelper::setWeights: "
153 "incompatible length of the weight array");
155 calculateEffectiveSampleSize();
157 lastBwFactor_ = -1.0;
160 inline int symbetaPower()
const {
return symbetaPower_;}
161 inline double leftBoundary()
const {
return leftBoundary_;}
162 inline double rightBoundary()
const {
return rightBoundary_;}
163 inline BoundaryHandling bh()
const {
return bh_;}
164 inline double localizingWeightXmin()
const {
return xminForWeight_;}
165 inline double localizingWeighXmax()
const {
return xmaxForWeight_;}
166 inline unsigned nIntegIntervals()
const {
return nIntegIntervals_;}
167 inline unsigned nIntegPoints()
const {
return nIntegPoints_;}
172 inline const std::vector<Numeric>& coords()
const {
return coords_;}
173 inline unsigned long nCoords()
const {
return coords_.size();}
174 inline Numeric minCoordinate()
const {
return coords_[0];}
175 inline Numeric maxCoordinate()
const {
return coords_.back();}
176 inline double totalSampleWeight()
const {
return sampleWeight_;}
177 inline double effectiveSampleSize()
const {
return effSampleSize_;}
179 inline bool isMemoizingKernels()
const {
return memoizeKernels_;}
180 inline bool isMemoizingNorms()
const {
return memoizeNorms_;}
181 inline bool isUsingMemoisingKernels()
const {
return useMemoisingKernels_;}
185 inline void memoizeKernels(
const bool b) {memoizeKernels_ = b;}
186 inline void memoizeNorms(
const bool b) {memoizeNorms_ = b;}
187 inline void useMemoisingKernels(
const bool b)
190 useMemoisingKernels_ = b;
197 inline void clearMemoizedInfo()
200 mapOfKernels_.clear();
203 inline void clearKernel()
205 kernel_ = std::shared_ptr<LOrPE1DSymbetaKernel>(0);
206 lastBwFactor_ = -1.0;
209 inline double pointCoordinate(
const unsigned long i)
const
212 Private::coordAndWeight(coords_[i], &x, &w);
216 inline double pointWeight(
const unsigned long i)
const
219 Private::coordAndWeight(coords_[i], &x, &w);
223 inline double bandwidthCurve(
const double x)
const
224 {
return fcnOrConst(bandwidthFunctor_, x);}
226 inline double cvLocalizingWeight(
const double x)
const
228 const double xlolim = std::max(leftBoundary_, xminForWeight_);
229 const double xuplim = std::min(rightBoundary_, xmaxForWeight_);
230 if (x >= xlolim && x <= xuplim)
231 return fcnOrConst(localizingWeight_, x);
236 inline LOrPE1DCVLocalizingWeightFunctor<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >
237 cvLocalizingWeightFunctor()
const
239 return LOrPE1DCVLocalizingWeightFunctor<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >(*this);
242 inline double density(
const double x,
const double filterDegree,
243 const double bwFactor)
const
245 setupKernel(filterDegree, bwFactor);
246 const double bw = bwFactor*fcnOrConst(bandwidthFunctor_, x);
247 return kernel_->lorpe(x, bw, &coords_[0], coords_.size(),
true);
250 inline double density(
const double x,
const double bwFactor)
const
252 validateBoundDegree(
"density");
253 return density(x, boundFilterDegree_, bwFactor);
256 inline LOrPE1DCVDensityFunctor<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >
257 densityFunctor(
const double filterDegree,
const double bwFactor)
const
259 return LOrPE1DCVDensityFunctor<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >(
260 *
this, filterDegree, bwFactor);
263 inline LOrPE1DCVDensityFunctor<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >
264 densityFunctor(
const double bwFactor)
const
266 validateBoundDegree(
"densityFunctor");
267 return densityFunctor(boundFilterDegree_, bwFactor);
270 inline LOrPE1D<Numeric> getLOrPE1D(
271 const double filterDegree,
const double bwFactor)
const
273 setupKernel(filterDegree, bwFactor);
274 LOrPE1D<Numeric> lorpe(*kernel_, coords_);
275 lorpe.setNormFactor(kernel_->normFactor());
279 inline LOrPE1D<Numeric> getLOrPE1D(
const double bwFactor)
const
281 validateBoundDegree(
"getLOrPE1D");
282 return getLOrPE1D(boundFilterDegree_, bwFactor);
285 inline double operator()(
286 const double& filterDegree,
const double& bwFactor)
const
288 setupKernel(filterDegree, bwFactor);
290 const unsigned long ncoords = coords_.size();
291 const Numeric* first = &coords_[0];
292 const Numeric* last = first + ncoords;
293 const double xlolim = std::max(leftBoundary_, xminForWeight_);
294 const double xuplim = std::min(rightBoundary_, xmaxForWeight_);
297 const Numeric xlow = Private::WeightedCoord<Numeric>(xlolim, 0.0).value;
299 first = std::lower_bound(first, last, xlow);
301 const Numeric xup = Private::WeightedCoord<Numeric>(xuplim, DBL_MAX).value;
302 if (xup < *(last - 1))
303 last = std::upper_bound(first, last, xup);
306 long double msum = 0.0L;
308 for (
const Numeric* ptr = first; ptr != last; ++ptr)
310 Private::coordAndWeight(*ptr, &xi, &w);
311 assert(xi >= leftBoundary_ && xi <= rightBoundary_);
313 if (w > 0.0 && xi >= xlolim && xi <= xuplim)
315 const double localWeight = fcnOrConst(localizingWeight_, xi);
316 assert(localWeight >= 0.0);
317 if (localWeight > 0.0)
319 const double bw = bwFactor*fcnOrConst(bandwidthFunctor_, xi);
320 const double estimate = kernel_->lorpe(
321 xi, bw, &coords_[0], ncoords,
true);
322 const double selfC = kernel_->getLastKernelAt0();
323 const double loo = (estimate - w*selfC)*sampleWeight_/(sampleWeight_ - w);
324 msum += pointContribution(selfC, loo, w, localWeight);
328 return valueToMaximize(msum);
331 inline double operator()(
const double& bwFactor)
const
333 validateBoundDegree(
"operator()");
334 return operator()(boundFilterDegree_, bwFactor);
342 const double filterDegree,
const double bwFactor)
const
344 setupKernel(filterDegree, bwFactor);
346 return glq.
integrate(this->bwDensityFunctor(bwFactor),
347 leftBoundary_, rightBoundary_, nIntegIntervals_);
352 validateBoundDegree(
"densityIntegral");
356 inline double integratedSquaredError(
357 const AbsDistribution1D& distro,
358 const double filterDegree,
const double bwFactor)
const
360 setupKernel(filterDegree, bwFactor);
361 LOrPE1DKernelISEFunctor<Numeric,BwFunctor> iseFcn(
362 distro, this->bwDensityFunctor(bwFactor));
363 GaussLegendreQuadrature glq(nIntegPoints_);
364 return glq.integrate(iseFcn, leftBoundary_,
365 rightBoundary_, nIntegIntervals_);
368 inline double integratedSquaredError(
369 const AbsDistribution1D& distro,
const double bwFactor)
const
371 validateBoundDegree(
"integratedSquaredError");
372 return integratedSquaredError(distro, boundFilterDegree_, bwFactor);
380 typedef std::map<std::pair<double,double>,
double> MapOfNorms;
381 typedef std::map<double,std::shared_ptr<LOrPE1DSymbetaKernel> > MapOfKernels;
383 virtual double pointContribution(
384 double selfC,
double leaveOneOutEstimate,
385 double pointWeight,
double localWeight)
const = 0;
386 virtual double valueToMaximize(
double sum)
const = 0;
388 std::vector<Numeric> coords_;
389 double sampleWeight_;
390 double effSampleSize_;
392 mutable std::shared_ptr<LOrPE1DSymbetaKernel> kernel_;
393 mutable double lastBwFactor_;
394 mutable double lastNorm_;
396 double boundFilterDegree_;
399 double leftBoundary_;
400 double rightBoundary_;
403 BwFcn bandwidthFunctor_;
404 WFcn localizingWeight_;
405 double xminForWeight_;
406 double xmaxForWeight_;
407 unsigned nIntegIntervals_;
408 unsigned nIntegPoints_;
411 bool memoizeKernels_;
413 bool useMemoisingKernels_;
415 mutable MapOfNorms mapOfNorms_;
416 mutable MapOfKernels mapOfKernels_;
419 const double bwFactor)
const
422 *kernel_, BwFunctor(bandwidthFunctor_, bwFactor),
423 &coords_[0], coords_.size(),
true);
427 inline void validateBoundDegree(
const char* where)
const
429 if (boundFilterDegree_ < 0.0)
431 std::ostringstream os;
432 os <<
"In npstat::LOrPE1DCVFunctorHelper::" << where
433 <<
": can't use the bandwidth factor alone, "
434 <<
"please bind the filter degree first";
435 throw std::runtime_error(os.str());
439 inline void setupKernel(
const double filterDegree,
440 const double bwFactor)
const
442 if (filterDegree < 0.0)
throw std::invalid_argument(
443 "In npstat::LOrPE1DCVFunctorHelper::setupKernel: "
444 "filter degree can not be negative");
445 if (bwFactor <= 0.0)
throw std::invalid_argument(
446 "In npstat::LOrPE1DCVFunctorHelper::setupKernel: "
447 "bandwidth factor must be positive");
449 const bool needAnotherKernel =
450 !(kernel_ && kernel_->filterDegree() == filterDegree);
451 if (needAnotherKernel)
452 makeKernel(filterDegree);
457 if (bwFactor == lastBwFactor_ && !needAnotherKernel)
459 assert(lastNorm_ > 0.0);
460 kernel_->setNormFactor(lastNorm_);
464 normalizeEstimate(bwFactor);
465 lastBwFactor_ = bwFactor;
466 lastNorm_ = kernel_->normFactor();
472 kernel_->setNormFactor(1.0/sampleWeight_);
473 lastBwFactor_ = bwFactor;
474 lastNorm_ = kernel_->normFactor();
478 inline void makeKernel(
const double filterDegree)
const
480 bool reallyMakeNewKernel =
true;
483 kernel_ = mapOfKernels_[filterDegree];
484 reallyMakeNewKernel = !kernel_;
486 if (reallyMakeNewKernel)
488 LOrPE1DSymbetaKernel* k =
new LOrPE1DSymbetaKernel(
489 symbetaPower_, filterDegree, leftBoundary_,
490 rightBoundary_, bh_, useMemoisingKernels_);
491 kernel_ = std::shared_ptr<LOrPE1DSymbetaKernel>(k);
494 mapOfKernels_[filterDegree] = kernel_;
498 inline void normalizeEstimate(
const double bwFactor)
const
502 bool reallyRecalculateNorm =
true;
505 const double deg = kernel_->filterDegree();
506 MapOfNorms::iterator it = mapOfNorms_.find(std::make_pair(deg, bwFactor));
507 if (it != mapOfNorms_.end())
509 reallyRecalculateNorm =
false;
510 kernel_->setNormFactor(it->second);
514 if (reallyRecalculateNorm)
516 const double defaultNorm = 1.0/sampleWeight_;
517 kernel_->setNormFactor(defaultNorm);
518 GaussLegendreQuadrature glq(nIntegPoints_);
519 const double integ = glq.integrate(this->bwDensityFunctor(bwFactor),
520 leftBoundary_, rightBoundary_, nIntegIntervals_);
522 const double newNorm = defaultNorm/integ;
523 kernel_->setNormFactor(newNorm);
527 const double deg = kernel_->filterDegree();
528 mapOfNorms_[std::make_pair(deg, bwFactor)] = newNorm;
533 inline void calculateEffectiveSampleSize()
535 sampleWeight_ = Private::SampleWeight<Numeric>(coords_).value;
536 if (sampleWeight_ <= 0.0)
throw std::invalid_argument(
537 "In npstat::LOrPE1DCV::calculateEffectiveSampleSize: "
538 "total sample weight must be positive");
539 const double sumWsq = Private::SampleSquaredWeight<Numeric>(coords_).value;
540 effSampleSize_ = sampleWeight_/sumWsq*sampleWeight_;
545 inline std::vector<double> sortedCoords()
const
547 const unsigned long sz = coords_.size();
548 std::vector<double> out;
551 for (
unsigned long i = 0; i < sz; ++i)
553 Private::coordAndWeight(coords_[i], &x, &w);
559 inline std::vector<double> sortedCoordWeights()
const
561 const unsigned long sz = coords_.size();
562 std::vector<double> out;
565 for (
unsigned long i = 0; i < sz; ++i)
567 Private::coordAndWeight(coords_[i], &x, &w);
575 template <
typename Numeric,
class BwFcn,
class WFcn>
581 using Base::LOrPE1DCVFunctorHelper;
586 inline virtual double pointContribution(
587 const double ,
const double leaveOneOutEstimate,
588 const double pointWeight,
const double localWeight)
const
590 return pointWeight*localWeight*leaveOneOutEstimate;
593 inline virtual double valueToMaximize(
const double sum)
const
595 const double xlolim = std::max(Base::leftBoundary_, Base::xminForWeight_);
596 const double xuplim = std::min(Base::rightBoundary_, Base::xmaxForWeight_);
599 make_DensitySquaredTimesWeight(
600 this->bwDensityFunctor(Base::lastBwFactor_), Base::localizingWeight_),
601 xlolim, xuplim, Base::nIntegIntervals_);
602 return -(integ - sum*2.0/Base::sampleWeight_);
606 template <
typename Numeric,
class BwFcn,
class WFcn>
613 const int i_symbetaPower,
614 const double i_leftBoundary,
615 const double i_rightBoundary,
617 const BwFcn& i_bandwidthFunctor,
618 const WFcn& i_localizingWeight,
619 const double i_localizingWeightXmin,
620 const double i_localizingWeightXmax,
621 const unsigned i_nIntegIntervals,
622 const unsigned i_nIntegPoints,
623 const bool i_normalizeLOrPEEstimate,
624 const std::vector<Numeric>& i_coords,
625 const double i_rlcvAlpha = 0.5)
627 i_symbetaPower, i_leftBoundary, i_rightBoundary,
628 i_bh, i_bandwidthFunctor, i_localizingWeight,
629 i_localizingWeightXmin, i_localizingWeightXmax,
630 i_nIntegIntervals, i_nIntegPoints,
631 i_normalizeLOrPEEstimate, i_coords)
633 setRlcvAlpha(i_rlcvAlpha);
638 inline void setRlcvAlpha(
const double alpha)
641 minDensFactor_ = std::pow(Base::effSampleSize_, alpha);
644 inline virtual void setWeights(
const double* weights,
unsigned long nWeights)
647 minDensFactor_ = std::pow(Base::effSampleSize_, rlcvAlpha_);
650 inline double rlcvAlpha()
const {
return rlcvAlpha_;}
653 inline virtual double pointContribution(
654 const double selfC,
const double leaveOneOutEstimate,
655 const double pointWeight,
const double localWeight)
const
657 const double minDens = selfC/minDensFactor_;
658 return pointWeight*localWeight*std::log(std::max(leaveOneOutEstimate, minDens));
661 inline virtual double valueToMaximize(
const double sum)
const
668 double minDensFactor_;
672 template <
typename Numeric,
class BwFcn,
class WFcn>
673 inline LOrPE1DLSCVFunctorHelper<Numeric, BwFcn, WFcn>
675 const double i_leftBoundary,
676 const double i_rightBoundary,
678 const BwFcn& i_bandwidthFunctor,
679 const WFcn& i_localizingWeight,
680 const double i_localizingWeightXmin,
681 const double i_localizingWeightXmax,
682 const unsigned i_nIntegIntervals,
683 const unsigned i_nIntegPoints,
684 const bool i_normalizeLOrPEEstimate,
685 const std::vector<Numeric>& i_coords)
688 i_symbetaPower, i_leftBoundary, i_rightBoundary,
689 i_bh, i_bandwidthFunctor, i_localizingWeight,
690 i_localizingWeightXmin, i_localizingWeightXmax,
691 i_nIntegIntervals, i_nIntegPoints,
692 i_normalizeLOrPEEstimate, i_coords);
700 template <
typename Numeric,
class BwFcn>
701 inline LOrPE1DLSCVFunctorHelper<Numeric, BwFcn, double>
703 const double i_leftBoundary,
704 const double i_rightBoundary,
706 const BwFcn& i_bandwidthFunctor,
707 const unsigned i_nIntegIntervals,
708 const unsigned i_nIntegPoints,
709 const bool i_normalizeLOrPEEstimate,
710 const std::vector<Numeric>& i_coords)
713 i_symbetaPower, i_leftBoundary, i_rightBoundary,
714 i_bh, i_bandwidthFunctor,
715 1.0, -DBL_MAX, DBL_MAX,
716 i_nIntegIntervals, i_nIntegPoints,
717 i_normalizeLOrPEEstimate, i_coords);
725 template <
typename Numeric>
726 inline LOrPE1DLSCVFunctorHelper<Numeric, double, double>
728 const double i_leftBoundary,
729 const double i_rightBoundary,
731 const unsigned i_nIntegIntervals,
732 const unsigned i_nIntegPoints,
733 const bool i_normalizeLOrPEEstimate,
734 const std::vector<Numeric>& i_coords)
737 i_symbetaPower, i_leftBoundary, i_rightBoundary,
738 i_bh, 1.0, 1.0, -DBL_MAX, DBL_MAX,
739 i_nIntegIntervals, i_nIntegPoints,
740 i_normalizeLOrPEEstimate, i_coords);
744 template <
typename Numeric,
class BwFcn,
class WFcn>
745 inline LOrPE1DRLCVFunctorHelper<Numeric, BwFcn, WFcn>
747 const double i_leftBoundary,
748 const double i_rightBoundary,
750 const BwFcn& i_bandwidthFunctor,
751 const WFcn& i_localizingWeight,
752 const double i_localizingWeightXmin,
753 const double i_localizingWeightXmax,
754 const unsigned i_nIntegIntervals,
755 const unsigned i_nIntegPoints,
756 const bool i_normalizeLOrPEEstimate,
757 const std::vector<Numeric>& i_coords,
758 const double i_rlcvAlpha = 0.5)
761 i_symbetaPower, i_leftBoundary, i_rightBoundary,
762 i_bh, i_bandwidthFunctor, i_localizingWeight,
763 i_localizingWeightXmin, i_localizingWeightXmax,
764 i_nIntegIntervals, i_nIntegPoints,
765 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
773 template <
typename Numeric,
class BwFcn>
774 inline LOrPE1DRLCVFunctorHelper<Numeric, BwFcn, double>
776 const double i_leftBoundary,
777 const double i_rightBoundary,
779 const BwFcn& i_bandwidthFunctor,
780 const unsigned i_nIntegIntervals,
781 const unsigned i_nIntegPoints,
782 const bool i_normalizeLOrPEEstimate,
783 const std::vector<Numeric>& i_coords,
784 const double i_rlcvAlpha = 0.5)
787 i_symbetaPower, i_leftBoundary, i_rightBoundary,
788 i_bh, i_bandwidthFunctor,
789 1.0, -DBL_MAX, DBL_MAX,
790 i_nIntegIntervals, i_nIntegPoints,
791 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
799 template <
typename Numeric>
800 inline LOrPE1DRLCVFunctorHelper<Numeric, double, double>
802 const double i_leftBoundary,
803 const double i_rightBoundary,
805 const unsigned i_nIntegIntervals,
806 const unsigned i_nIntegPoints,
807 const bool i_normalizeLOrPEEstimate,
808 const std::vector<Numeric>& i_coords,
809 const double i_rlcvAlpha = 0.5)
812 i_symbetaPower, i_leftBoundary, i_rightBoundary,
813 i_bh, 1.0, 1.0, -DBL_MAX, DBL_MAX,
814 i_nIntegIntervals, i_nIntegPoints,
815 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
821 template <
typename Numeric,
class BwFcn,
class WFcn>
822 inline std::unique_ptr<LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> >
823 LOrPE1DCVFunctor(
const int i_symbetaPower,
824 const double i_leftBoundary,
825 const double i_rightBoundary,
826 const BoundaryHandling& i_bh,
827 const BwFcn& i_bandwidthFunctor,
828 const WFcn& i_localizingWeight,
829 const double i_localizingWeightXmin,
830 const double i_localizingWeightXmax,
831 const unsigned i_nIntegIntervals,
832 const unsigned i_nIntegPoints,
833 const bool i_normalizeLOrPEEstimate,
834 const std::vector<Numeric>& i_coords,
835 const double i_rlcvAlpha)
837 typedef LOrPE1DCVFunctorHelper<Numeric, BwFcn, WFcn> Base;
838 typedef LOrPE1DRLCVFunctorHelper<Numeric, BwFcn, WFcn> RLCV;
839 typedef LOrPE1DLSCVFunctorHelper<Numeric, BwFcn, WFcn> LSCV;
842 if (i_rlcvAlpha < 0.0)
844 i_symbetaPower, i_leftBoundary, i_rightBoundary,
845 i_bh, i_bandwidthFunctor, i_localizingWeight,
846 i_localizingWeightXmin, i_localizingWeightXmax,
847 i_nIntegIntervals, i_nIntegPoints,
848 i_normalizeLOrPEEstimate, i_coords);
851 i_symbetaPower, i_leftBoundary, i_rightBoundary,
852 i_bh, i_bandwidthFunctor, i_localizingWeight,
853 i_localizingWeightXmin, i_localizingWeightXmax,
854 i_nIntegIntervals, i_nIntegPoints,
855 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
856 return std::unique_ptr<Base>(ptr);
859 template <
typename Numeric,
class BwFcn>
860 inline std::unique_ptr<LOrPE1DCVFunctorHelper<Numeric, BwFcn, double> >
861 LOrPE1DGlobCVFunctor(
const int i_symbetaPower,
862 const double i_leftBoundary,
863 const double i_rightBoundary,
864 const BoundaryHandling& i_bh,
865 const BwFcn& i_bandwidthFunctor,
866 const unsigned i_nIntegIntervals,
867 const unsigned i_nIntegPoints,
868 const bool i_normalizeLOrPEEstimate,
869 const std::vector<Numeric>& i_coords,
870 const double i_rlcvAlpha)
872 typedef LOrPE1DCVFunctorHelper<Numeric, BwFcn, double> Base;
873 typedef LOrPE1DRLCVFunctorHelper<Numeric, BwFcn, double> RLCV;
874 typedef LOrPE1DLSCVFunctorHelper<Numeric, BwFcn, double> LSCV;
877 if (i_rlcvAlpha < 0.0)
879 i_symbetaPower, i_leftBoundary, i_rightBoundary,
880 i_bh, i_bandwidthFunctor,
881 1.0, -DBL_MAX, DBL_MAX,
882 i_nIntegIntervals, i_nIntegPoints,
883 i_normalizeLOrPEEstimate, i_coords);
886 i_symbetaPower, i_leftBoundary, i_rightBoundary,
887 i_bh, i_bandwidthFunctor,
888 1.0, -DBL_MAX, DBL_MAX,
889 i_nIntegIntervals, i_nIntegPoints,
890 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
891 return std::unique_ptr<Base>(ptr);
894 template <
typename Numeric>
895 inline std::unique_ptr<LOrPE1DCVFunctorHelper<Numeric, double, double> >
896 LOrPE1DSimpleCVFunctor(
const int i_symbetaPower,
897 const double i_leftBoundary,
898 const double i_rightBoundary,
899 const BoundaryHandling& i_bh,
900 const unsigned i_nIntegIntervals,
901 const unsigned i_nIntegPoints,
902 const bool i_normalizeLOrPEEstimate,
903 const std::vector<Numeric>& i_coords,
904 const double i_rlcvAlpha)
906 typedef LOrPE1DCVFunctorHelper<Numeric, double, double> Base;
907 typedef LOrPE1DRLCVFunctorHelper<Numeric, double, double> RLCV;
908 typedef LOrPE1DLSCVFunctorHelper<Numeric, double, double> LSCV;
911 if (i_rlcvAlpha < 0.0)
913 i_symbetaPower, i_leftBoundary, i_rightBoundary,
914 i_bh, 1.0, 1.0, -DBL_MAX, DBL_MAX,
915 i_nIntegIntervals, i_nIntegPoints,
916 i_normalizeLOrPEEstimate, i_coords);
919 i_symbetaPower, i_leftBoundary, i_rightBoundary,
920 i_bh, 1.0, 1.0, -DBL_MAX, DBL_MAX,
921 i_nIntegIntervals, i_nIntegPoints,
922 i_normalizeLOrPEEstimate, i_coords, i_rlcvAlpha);
923 return std::unique_ptr<Base>(ptr);
Convenience class which aggregates the kernel and the data for unbinned density estimation by LOrPE.
Definition: BoundaryHandling.hh:21
Definition: GaussLegendreQuadrature.hh:27
long double integrate(const Functor1< FcnResult, FcnArg > &fcn, long double a, long double b) const
static bool isAllowed(unsigned npoints)
Definition: LOrPE1DCV.hh:30
Definition: LOrPE1DCV.hh:78
bool normalizingLOrPEEstimate() const
Definition: LOrPE1DCV.hh:170
virtual void setWeights(const double *weights, unsigned long nWeights)
Definition: LOrPE1DCV.hh:149
static bool cvCapable()
Definition: LOrPE1DCV.hh:376
double densityIntegral(const double filterDegree, const double bwFactor) const
Definition: LOrPE1DCV.hh:341
Definition: LOrPE1DCV.hh:60
Definition: LOrPE1DSymbetaKernel.hh:173
Definition: LOrPE1DCV.hh:577
Definition: LOrPE1DCV.hh:608
virtual void setWeights(const double *weights, unsigned long nWeights)
Definition: LOrPE1DCV.hh:644
Definition: fcnOrConst.hh:42
Definition: AbsArrayProjector.hh:14
LOrPE1DLSCVFunctorHelper< Numeric, BwFcn, double > LOrPE1DGlobLSCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const BwFcn &i_bandwidthFunctor, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords)
Definition: LOrPE1DCV.hh:702
LOrPE1DLSCVFunctorHelper< Numeric, double, double > LOrPE1DSimpleLSCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords)
Definition: LOrPE1DCV.hh:727
LOrPE1DRLCVFunctorHelper< Numeric, BwFcn, double > LOrPE1DGlobRLCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const BwFcn &i_bandwidthFunctor, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords, const double i_rlcvAlpha=0.5)
Definition: LOrPE1DCV.hh:775
LOrPE1DLSCVFunctorHelper< Numeric, BwFcn, WFcn > LOrPE1DLSCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const BwFcn &i_bandwidthFunctor, const WFcn &i_localizingWeight, const double i_localizingWeightXmin, const double i_localizingWeightXmax, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords)
Definition: LOrPE1DCV.hh:674
LOrPE1DRLCVFunctorHelper< Numeric, BwFcn, WFcn > LOrPE1DRLCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const BwFcn &i_bandwidthFunctor, const WFcn &i_localizingWeight, const double i_localizingWeightXmin, const double i_localizingWeightXmax, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords, const double i_rlcvAlpha=0.5)
Definition: LOrPE1DCV.hh:746
LOrPE1DRLCVFunctorHelper< Numeric, double, double > LOrPE1DSimpleRLCVFunctor(const int i_symbetaPower, const double i_leftBoundary, const double i_rightBoundary, const BoundaryHandling &i_bh, const unsigned i_nIntegIntervals, const unsigned i_nIntegPoints, const bool i_normalizeLOrPEEstimate, const std::vector< Numeric > &i_coords, const double i_rlcvAlpha=0.5)
Definition: LOrPE1DCV.hh:801
Definition: SimpleFunctors.hh:58
Definition: SimpleFunctors.hh:89
Definition: coordAndWeight.hh:104