50 TMVA::KDEKernel::KDEKernel( EKernelIter kiter, const
TH1 *hist,
Float_t lower_edge,
Float_t upper_edge,
51 EKernelBorder kborder,
Float_t FineFactor )
54 fLowerEdge (lower_edge ),
55 fUpperEdge (upper_edge),
56 fFineFactor ( FineFactor ),
58 fKDEborder ( kborder ),
59 fLogger( new MsgLogger("KDEKernel") )
62 Log() <<
kFATAL <<
"Called without valid histogram pointer (hist)!" <<
Endl;
67 fFirstIterHist->Reset();
71 fHiddenIteration=
false;
91 if ( (par[1]<=0) || (x[0]>x[1]))
return -1.;
97 if (xs2==0)
return 0.;
115 if (ktype == kGauss) {
122 fKernel_integ =
new TF1(
"GaussIntegral",
GaussIntegral,fLowerEdge,fUpperEdge,4);
131 Log() <<
kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
135 if (fIter == kAdaptiveKDE) {
141 fHiddenIteration=
true;
143 Float_t histoLowEdge=fHist->GetBinLowEdge(1);
144 Float_t histoUpperEdge=fHist->GetBinLowEdge(fHist->GetNbinsX()+1);
146 for (
Int_t i=1;i<fHist->GetNbinsX();i++) {
148 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
150 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
151 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
152 fFirstIterHist->GetBinLowEdge(j+1),
153 fHist->GetBinCenter(i),
157 if (fKDEborder == 3) {
161 if (i < fHist->GetNbinsX()/5 ) {
162 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
164 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
165 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
166 fFirstIterHist->GetBinLowEdge(j+1),
167 2*histoLowEdge-fHist->GetBinCenter(i),
172 if (i > 4*fHist->GetNbinsX()/5) {
173 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
175 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
176 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
177 fFirstIterHist->GetBinLowEdge(j+1),
178 2*histoUpperEdge-fHist->GetBinCenter(i),
186 fFirstIterHist->SetEntries(fHist->GetEntries());
190 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++)
191 integ+=fFirstIterHist->GetBinContent(j)*fFirstIterHist->GetBinWidth(j);
192 fFirstIterHist->Scale(1./integ);
194 fHiddenIteration=
false;
200 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
202 if (fSigma*
TMath::Sqrt(1.0/fFirstIterHist->GetBinContent(j)) <= 0 ) {
203 Log() <<
kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
206 fSigmaHist->SetBinContent(j,fFineFactor*fSigma/
TMath::Sqrt(fFirstIterHist->GetBinContent(j)));
210 if (fKernel_integ ==0 ) {
211 Log() <<
kFATAL <<
"KDE kernel not correctly initialized!" <<
Endl;
220 if ((fIter == kNonadaptiveKDE) || fHiddenIteration )
221 fKernel_integ->SetParameters(mean,fSigma);
222 else if ((fIter == kAdaptiveKDE) && !fHiddenIteration )
223 fKernel_integ->SetParameters(mean,fSigmaHist->GetBinContent(binnum));
225 if ( fKDEborder == 2 ) {
226 Float_t renormFactor=1.0/fKernel_integ->Eval(fLowerEdge,fUpperEdge);
227 return (renormFactor*fKernel_integ->Eval(lowr,highr));
232 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
void SetKernelType(EKernelType ktype=kGauss)
fIter == 1 —> nonadaptive KDE fIter == 2 —> adaptive KDE
Double_t Sqrt(Double_t x)