49 TMVA::KDEKernel::KDEKernel( EKernelIter kiter, const
TH1 *hist,
Float_t lower_edge,
Float_t upper_edge,
50 EKernelBorder kborder,
Float_t FineFactor )
53 fLowerEdge (lower_edge ),
54 fUpperEdge (upper_edge),
55 fFineFactor ( FineFactor ),
57 fKDEborder ( kborder ),
58 fLogger( new MsgLogger("KDEKernel") )
61 Log() <<
kFATAL <<
"Called without valid histogram pointer (hist)!" <<
Endl;
66 fFirstIterHist->Reset();
70 fHiddenIteration=
false;
90 if ( (par[1]<=0) || (x[0]>x[1]))
return -1.;
92 Float_t xs1=(x[0]-par[0])/par[1];
93 Float_t xs2=(x[1]-par[0])/par[1];
96 if (xs2==0)
return 0.;
114 if (ktype == kGauss) {
121 fKernel_integ =
new TF1(
"GaussIntegral",
GaussIntegral,fLowerEdge,fUpperEdge,4);
130 Log() <<
kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
134 if (fIter == kAdaptiveKDE) {
140 fHiddenIteration=
true;
142 Float_t histoLowEdge=fHist->GetBinLowEdge(1);
143 Float_t histoUpperEdge=fHist->GetBinLowEdge(fHist->GetNbinsX()+1);
145 for (
Int_t i=1;i<fHist->GetNbinsX();i++) {
147 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
149 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
150 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
151 fFirstIterHist->GetBinLowEdge(j+1),
152 fHist->GetBinCenter(i),
156 if (fKDEborder == 3) {
160 if (i < fHist->GetNbinsX()/5 ) {
161 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
163 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
164 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
165 fFirstIterHist->GetBinLowEdge(j+1),
166 2*histoLowEdge-fHist->GetBinCenter(i),
171 if (i > 4*fHist->GetNbinsX()/5) {
172 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
174 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
175 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
176 fFirstIterHist->GetBinLowEdge(j+1),
177 2*histoUpperEdge-fHist->GetBinCenter(i),
185 fFirstIterHist->SetEntries(fHist->GetEntries());
189 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++)
190 integ+=fFirstIterHist->GetBinContent(j)*fFirstIterHist->GetBinWidth(j);
191 fFirstIterHist->Scale(1./integ);
193 fHiddenIteration=
false;
199 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
201 if (fSigma*
TMath::Sqrt(1.0/fFirstIterHist->GetBinContent(j)) <= 0 ) {
202 Log() <<
kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
205 fSigmaHist->SetBinContent(j,fFineFactor*fSigma/
TMath::Sqrt(fFirstIterHist->GetBinContent(j)));
209 if (fKernel_integ ==0 ) {
210 Log() <<
kFATAL <<
"KDE kernel not correctly initialized!" <<
Endl;
219 if ((fIter == kNonadaptiveKDE) || fHiddenIteration )
220 fKernel_integ->SetParameters(mean,fSigma);
221 else if ((fIter == kAdaptiveKDE) && !fHiddenIteration )
222 fKernel_integ->SetParameters(mean,fSigmaHist->GetBinContent(binnum));
224 if ( fKDEborder == 2 ) {
225 Float_t renormFactor=1.0/fKernel_integ->Eval(fLowerEdge,fUpperEdge);
226 return (renormFactor*fKernel_integ->Eval(lowr,highr));
231 return (fKernel_integ->Eval(lowr,highr));
Double_t GaussIntegral(Double_t *x, Double_t *par)
when using Gaussian as Kernel function this is faster way to calculate the integrals ...
MsgLogger & Endl(MsgLogger &ml)
ClassImp(TMVA::KDEKernel) TMVA
constructor sanity check
1-D histogram with a float per channel (see TH1 documentation)}
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Float_t GetBinKernelIntegral(Float_t lowr, Float_t highr, Float_t mean, Int_t binnum)
calculates the integral of the Kernel
virtual ~KDEKernel(void)
destructor
Abstract ClassifierFactory template that handles arbitrary types.
void SetKernelType(EKernelType ktype=kGauss)
fIter == 1 —> nonadaptive KDE fIter == 2 —> adaptive KDE
Double_t Sqrt(Double_t x)