# Update to non-adaptive bandwidth in TMVA::PDF class?

**URL:** <https://root-forum.cern.ch/t/update-to-non-adaptive-bandwidth-in-tmva-pdf-class/41293>\
**Category:** TMVA\
**Created:** [September 4, 2020, 3:35am UTC](https://root-forum.cern.ch/t/update-to-non-adaptive-bandwidth-in-tmva-pdf-class/41293 "2020-09-04T03:35:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwruss](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jwruss](https://root-forum.cern.ch/u/jwruss)\
**Post date:** [September 4, 2020, 3:35am UTC](https://root-forum.cern.ch/t/update-to-non-adaptive-bandwidth-in-tmva-pdf-class/41293/1 "2020-09-04T03:35:48Z")

</div>

I have been looking at TMVA’s implementation of KDE with Gaussian kernel, and noticed that the non-adaptive bandwidth is defined as the bandwidth which minimizes the AMISE for an underlying _Gaussian_ distribution.

The general expression for the non-adaptive, AMISE-minimizing bandwidth is given in [this section](https://en.wikipedia.org/wiki/Kernel_density_estimation#Bandwidth_selection) of the Wikipedia article on KDE. When assuming a Gaussian kernel, this expression has as values

R(K) = 1 / (2 \* sqrt(pi)),  
m\_2(K) = 1.

Only when the underlying distribution “f” is assumed to be Gaussian do we then have

R(f’’) = 3 / (8 \* sqrt(pi) \* RMS\_x)

and then recover the non-adaptive bandwidth implemented in TMVA. This is according to [here](https://en.wikipedia.org/wiki/Kernel_density_estimation#A_rule-of-thumb_bandwidth_estimator) in the Wikipedia article and comparing it to equation (26) on page 58 of the TMVA User’s Guide.

Since TMVA’s implementation uses a finely binned histogram as a reference for the distribution “f”, why not use discrete Fourier transformation on the bins of this histogram to estimate R(f’’)?

After finding the discrete Fourier transform “F = F(k)” of this histogrammed “f = f(x)”, the calculation of R(f’’) can be expedited using Parseval’s theorem:

R(f’’) = R(k^2 \* abs(F)).

Other than implementing that calculation of R(f’’) using FFT, it looks like really only lines 125-126 of [KDEKernel.cxx](https://root.cern.ch/doc/v606/KDEKernel_8cxx_source.html#l00125) have to be updated, replacing the use of the the Gaussian-assumed R(f’’) with this value.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 4, 2020, 6:37am UTC](https://root-forum.cern.ch/t/update-to-non-adaptive-bandwidth-in-tmva-pdf-class/41293/2 "2020-09-04T06:37:24Z")

</div>

I guess @moneta and @kialbert can help.
