1 #ifndef NPSTAT_ABSBANDWIDTHGCV_HH_
2 #define NPSTAT_ABSBANDWIDTHGCV_HH_
21 #include "npstat/wrap/arrayNDToNumpy.hh"
22 #include "npstat/wrap/numpyArrayUtils.hh"
27 struct AbsPolyFilter1D;
28 struct AbsPolyFilterND;
36 template<
typename Numeric,
typename Num2>
39 typedef Numeric bin_type;
40 typedef Num2 density_type;
52 const Num2* densityEstimate,
53 const Num2* leaveOneOutEstimate,
60 double effectiveSampleSize,
61 const Num2* densityEstimate,
62 const Num2* leaveOneOutEstimate,
69 PyObject* input, PyObject* leaveOneOut,
72 const int typenum = numpyArrayType(input);
73 const int typenum2 = numpyArrayType(leaveOneOut);
74 if (typenum != NumpyTypecode<double>::code ||
75 typenum2 != NumpyTypecode<double>::code)
76 throw std::invalid_argument(
"In npstat::AbsBandwidthGCV1D::cv: "
77 "unsupported input array type");
78 const unsigned datalen = histo.
nBins();
79 if (!isNumpyShapeCompatible(input, &datalen, 1U) ||
80 !isNumpyShapeCompatible(leaveOneOut, &datalen, 1U))
throw std::invalid_argument(
81 "In npstat::AbsBandwidthCV1D::cv: incompatible array shape");
82 const Num2* in = (
double*)PyArray_DATA((PyArrayObject*)input);
83 const Num2* leave = (
double*)PyArray_DATA((PyArrayObject*)leaveOneOut);
84 return this->
operator()(histo, in, leave, datalen, filterUsed);
87 inline double cvWeighted(
89 const double effectiveSampleSize,
90 PyObject* input, PyObject* leaveOneOut,
93 const int typenum = numpyArrayType(input);
94 const int typenum2 = numpyArrayType(leaveOneOut);
95 if (typenum != NumpyTypecode<double>::code ||
96 typenum2 != NumpyTypecode<double>::code)
97 throw std::invalid_argument(
"In npstat::AbsBandwidthGCV1D::cvWeighted: "
98 "unsupported input array type");
99 const unsigned datalen = histo.
nBins();
100 if (!isNumpyShapeCompatible(input, &datalen, 1U) ||
101 !isNumpyShapeCompatible(leaveOneOut, &datalen, 1U))
throw std::invalid_argument(
102 "In npstat::AbsBandwidthGCV1D::cvWeighted: incompatible array shape");
103 const Num2* in = (
double*)PyArray_DATA((PyArrayObject*)input);
104 const Num2* leave = (
double*)PyArray_DATA((PyArrayObject*)leaveOneOut);
105 return this->
operator()(histo, effectiveSampleSize, in,
106 leave, datalen, filterUsed);
116 template<
typename Numeric,
class Array>
119 typedef Numeric bin_type;
120 typedef Array density_type;
130 const Array& densityEstimate,
131 const Array& leaveOneOutEstimate,
137 double effectiveSampleSize,
138 const Array& densityEstimate,
139 const Array& leaveOneOutEstimate,
145 PyObject* input, PyObject* leaveOneOut,
148 const int typenum = numpyArrayType(input);
149 const int typenum2 = numpyArrayType(leaveOneOut);
150 if (typenum != NumpyTypecode<double>::code ||
151 typenum2 != NumpyTypecode<double>::code)
152 throw std::invalid_argument(
"In npstat::AbsBandwidthCVGND::cv: "
153 "unsupported input array type");
155 if (!isNumpyShapeCompatible(input, shape, histo.
dim()) ||
156 !isNumpyShapeCompatible(leaveOneOut, shape, histo.
dim()))
157 throw std::invalid_argument(
"In npstat::AbsBandwidthCVGND::cv: "
158 "incompatible array shape");
159 double* in = (
double*)PyArray_DATA((PyArrayObject*)input);
160 double* leave = (
double*)PyArray_DATA((PyArrayObject*)leaveOneOut);
163 return this->
operator()(histo, wrap, wrapL, filterUsed);
166 inline double cvWeighted(
168 const double effectiveSampleSize,
169 PyObject* input, PyObject* leaveOneOut,
172 const int typenum = numpyArrayType(input);
173 const int typenum2 = numpyArrayType(leaveOneOut);
174 if (typenum != NumpyTypecode<double>::code ||
175 typenum2 != NumpyTypecode<double>::code)
176 throw std::invalid_argument(
"In npstat::AbsBandwidthCVGND::cvWeighted: "
177 "unsupported input array type");
179 if (!isNumpyShapeCompatible(input, shape, histo.
dim()) ||
180 !isNumpyShapeCompatible(leaveOneOut, shape, histo.
dim()))
181 throw std::invalid_argument(
"In npstat::AbsBandwidthCVGND::cvWeighted: "
182 "incompatible array shape");
183 double* in = (
double*)PyArray_DATA((PyArrayObject*)input);
184 double* leave = (
double*)PyArray_DATA((PyArrayObject*)leaveOneOut);
187 return this->
operator()(histo, effectiveSampleSize, wrap, wrapL, filterUsed);
Arbitrary-dimensional histogram template.
const unsigned * shapeData() const
Definition: ArrayND.hh:335
Definition: HistoND.hh:46
const ArrayND< Numeric > & binContents() const
Definition: HistoND.hh:197
unsigned long nBins() const
Definition: HistoND.hh:226
unsigned dim() const
Definition: HistoND.hh:187
Definition: AbsArrayProjector.hh:14
ArrayND< Numeric > externalMemArrayND(Numeric *data, const unsigned *shape, unsigned dim)
Definition: AbsBandwidthGCV.hh:38
virtual double operator()(const HistoND< Numeric > &histo, double effectiveSampleSize, const Num2 *densityEstimate, const Num2 *leaveOneOutEstimate, unsigned lenEstimate, const AbsPolyFilter1D &filterUsed) const =0
virtual double operator()(const HistoND< Numeric > &histo, const Num2 *densityEstimate, const Num2 *leaveOneOutEstimate, unsigned lenEstimate, const AbsPolyFilter1D &filterUsed) const =0
Definition: AbsBandwidthGCV.hh:118
virtual double operator()(const HistoND< Numeric > &histo, const Array &densityEstimate, const Array &leaveOneOutEstimate, const AbsPolyFilterND &filterUsed) const =0
virtual double operator()(const HistoND< Numeric > &histo, double effectiveSampleSize, const Array &densityEstimate, const Array &leaveOneOutEstimate, const AbsPolyFilterND &filterUsed) const =0
Definition: AbsPolyFilter1D.hh:27
Definition: AbsPolyFilterND.hh:27