31 class TKDE :
public TNamed {
69 TKDE(UInt_t events,
const Double_t* data, Double_t xMin = 0.0, Double_t xMax = 0.0,
const Option_t* option =
70 "KernelType:Gaussian;Iteration:Adaptive;Mirror:noMirror;Binning:RelaxedBinning", Double_t rho = 1.0) {
71 Instantiate(
nullptr, events, data,
nullptr, xMin, xMax, option, rho);
74 TKDE(UInt_t events,
const Double_t* data,
const Double_t* dataWeight, Double_t xMin = 0.0, Double_t xMax = 0.0,
const Option_t* option =
75 "KernelType:Gaussian;Iteration:Adaptive;Mirror:noMirror;Binning:RelaxedBinning", Double_t rho = 1.0) {
76 Instantiate(
nullptr, events, data, dataWeight, xMin, xMax, option, rho);
79 template<
class KernelFunction>
80 TKDE(
const Char_t* ,
const KernelFunction& kernfunc, UInt_t events,
const Double_t* data, Double_t xMin = 0.0, Double_t xMax = 0.0,
const Option_t* option =
"KernelType:UserDefined;Iteration:Adaptive;Mirror:noMirror;Binning:RelaxedBinning", Double_t rho = 1.0) {
81 Instantiate(
new ROOT::Math::WrappedFunction<const KernelFunction&>(kernfunc), events, data,
nullptr, xMin, xMax, option, rho);
83 template<
class KernelFunction>
84 TKDE(
const Char_t* ,
const KernelFunction& kernfunc, UInt_t events,
const Double_t* data,
const Double_t * dataWeight, Double_t xMin = 0.0, Double_t xMax = 0.0,
const Option_t* option =
"KernelType:UserDefined;Iteration:Adaptive;Mirror:noMirror;Binning:RelaxedBinning", Double_t rho = 1.0) {
85 Instantiate(
new ROOT::Math::WrappedFunction<const KernelFunction&>(kernfunc), events, data, dataWeight, xMin, xMax, option, rho);
90 void Fill(Double_t data);
91 void Fill(Double_t data, Double_t weight);
92 void SetKernelType(EKernelType kern);
93 void SetIteration(EIteration iter);
94 void SetMirror(EMirror mir);
95 void SetBinning(EBinning);
96 void SetNBins(UInt_t nbins);
97 void SetUseBinsNEvents(UInt_t nEvents);
98 void SetTuneFactor(Double_t rho);
99 void SetRange(Double_t xMin, Double_t xMax);
101 virtual void Draw(
const Option_t* option =
"");
103 Double_t operator()(Double_t x)
const;
104 Double_t operator()(
const Double_t* x,
const Double_t* p=0)
const;
106 Double_t GetValue(Double_t x)
const {
return (*
this)(x); }
107 Double_t GetError(Double_t x)
const;
109 Double_t GetBias(Double_t x)
const;
110 Double_t GetMean()
const;
111 Double_t GetSigma()
const;
112 Double_t GetRAMISE()
const;
114 Double_t GetFixedWeight()
const;
116 TF1* GetFunction(UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
117 TF1* GetUpperFunction(Double_t confidenceLevel = 0.95, UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
118 TF1* GetLowerFunction(Double_t confidenceLevel = 0.95, UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
119 TF1* GetApproximateBias(UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
120 TGraphErrors * GetGraphWithErrors(UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
124 TF1 * GetDrawnFunction() {
return fPDF;}
125 TF1 * GetDrawnUpperFunction() {
return fUpperPDF;}
126 TF1 * GetDrawnLowerFunction() {
return fLowerPDF;}
127 TGraphErrors * GetDrawnGraph() {
return fGraph;}
129 const Double_t * GetAdaptiveWeights()
const;
135 TKDE operator=(TKDE& kde);
137 typedef ROOT::Math::IBaseFunctionOneDim* KernelFunction_Ptr;
138 KernelFunction_Ptr fKernelFunction;
141 friend class TKernel;
145 std::vector<Double_t> fData;
146 std::vector<Double_t> fEvents;
147 std::vector<Double_t> fEventWeights;
152 TF1* fApproximateBias;
153 TGraphErrors* fGraph;
155 EKernelType fKernelType;
156 EIteration fIteration;
161 Bool_t fUseMirroring, fMirrorLeft, fMirrorRight, fAsymLeft, fAsymRight;
164 Bool_t fUseMinMaxFromData;
168 Double_t fSumOfCounts;
169 UInt_t fUseBinsNEvents;
177 Double_t fAdaptiveBandwidthFactor;
179 Double_t fWeightSize;
181 std::vector<Double_t> fCanonicalBandwidths;
182 std::vector<Double_t> fKernelSigmas2;
184 std::vector<Double_t> fBinCount;
186 std::vector<Bool_t> fSettedOptions;
188 struct KernelIntegrand;
189 friend struct KernelIntegrand;
191 void Instantiate(KernelFunction_Ptr kernfunc, UInt_t events,
const Double_t* data,
const Double_t* weight,
192 Double_t xMin, Double_t xMax,
const Option_t* option, Double_t rho);
194 inline Double_t GaussianKernel(Double_t x)
const {
196 Double_t k2_PI_ROOT_INV = 0.398942280401432703;
197 return (x > -9. && x < 9.) ? k2_PI_ROOT_INV * std::exp(-.5 * x * x) : 0.0;
199 inline Double_t EpanechnikovKernel(Double_t x)
const {
200 return (x > -1. && x < 1.) ? 3. / 4. * (1. - x * x) : 0.0;
202 inline Double_t BiweightKernel(Double_t x)
const {
204 return (x > -1. && x < 1.) ? 15. / 16. * (1. - x * x) * (1. - x * x) : 0.0;
206 inline Double_t CosineArchKernel(Double_t x)
const {
208 return (x > -1. && x < 1.) ? M_PI_4 * std::cos(M_PI_2 * x) : 0.0;
210 Double_t UpperConfidenceInterval(
const Double_t* x,
const Double_t* p)
const;
211 Double_t LowerConfidenceInterval(
const Double_t* x,
const Double_t* p)
const;
212 Double_t ApproximateBias(
const Double_t* x,
const Double_t* )
const {
return GetBias(*x); }
213 Double_t ComputeKernelL2Norm()
const;
214 Double_t ComputeKernelSigma2()
const;
215 Double_t ComputeKernelMu()
const;
216 Double_t ComputeKernelIntegral()
const;
217 Double_t ComputeMidspread() ;
218 void ComputeDataStats() ;
220 UInt_t Index(Double_t x)
const;
222 void SetBinCentreData(Double_t xmin, Double_t xmax);
223 void SetBinCountData();
224 void CheckKernelValidity();
225 void SetUserCanonicalBandwidth();
226 void SetUserKernelSigma2();
227 void SetCanonicalBandwidths();
228 void SetKernelSigmas2();
233 void SetSigma(Double_t R);
235 void SetKernelFunction(KernelFunction_Ptr kernfunc = 0);
236 void SetOptions(
const Option_t* option, Double_t rho);
237 void CheckOptions(Bool_t isUserDefinedKernel = kFALSE);
238 void GetOptions(std::string optionType, std::string option);
239 void AssureOptions();
240 void SetData(
const Double_t* data,
const Double_t * weights);
242 void InitFromNewData();
243 void SetMirroredEvents();
244 void SetDrawOptions(
const Option_t* option, TString& plotOpt, TString& drawOpt);
245 void DrawErrors(TString& drawOpt);
246 void DrawConfidenceInterval(TString& drawOpt,
double cl=0.95);
248 TF1* GetKDEFunction(UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
249 TF1* GetKDEApproximateBias(UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
251 TF1* GetPDFUpperConfidenceInterval(Double_t confidenceLevel = 0.95, UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);
252 TF1* GetPDFLowerConfidenceInterval(Double_t confidenceLevel = 0.95, UInt_t npx = 100, Double_t xMin = 1.0, Double_t xMax = 0.0);