# Adding "PDFInterpol=logspline" to TMVA::Factory?

**URL:** <https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433>\
**Category:** TMVA\
**Created:** [November 24, 2020, 11:47pm UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433 "2020-11-24T23:47:42Z")\
**Posts on this page:** 5\
**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:** [November 24, 2020, 11:47pm UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433/1 "2020-11-24T23:47:42Z")

</div>

Without knowing definitively the underlying distribution of a TMVA response, I have been considering fitting the PDF histograms of the response using `PDFInterpol=KDE` as opposed to one of the `PDFInterpol=Spline{0-5}` options. However, one of my colleagues has argued that the KDE would produce too small tails when considering the Rarity/CDF of the fitted PDF. It looks like this dilemma has been [posted elsewhere](https://stats.stackexchange.com/questions/59389/kernel-density-estimator-that-doesnt-collapse-in-the-tails), where it was suggested that a logspline could yield the desired behavior of bigger tails. Figure 2 in these [lecture notes](http://www.econ.uiuc.edu/~roger/courses/574/lectures/L18.pdf) have raised my hopes that a logspline fit to the histogram PDFs may be worthwhile to pursue.

Has this been considered before? Could it be implemented?

---

<div class="post-metadata">

**Author:** ![oshadura](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oshadura/32/14460_2.png) [@oshadura](https://root-forum.cern.ch/u/oshadura)\
**Post date:** [November 25, 2020, 10:19am UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433/2 "2020-11-25T10:19:51Z")

</div>

@moneta @swunsch could you help here please? Thanks in advance!

---

<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:** [November 29, 2020, 12:21am UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433/3 "2020-11-29T00:21:24Z")

</div>

As an interim solution, I was looking into rebuilding ROOT and enabling R support bindings to be able to use R’s [logspline library](https://cran.r-project.org/web/packages/logspline/index.html). The way I thought I would do this is I would refer to the evaluated response values within the `TrainTree` in the file written for the single TMVA::Factory object that I create. I would use the response values corresponding to `classID==0` to create a vector “x” which I would then feed into R to get a response using `fit <- logspline(x)`.

I found this method won’t work, though, because it seems the `TrainTree` object within the file has only saved the response values, their probabilities, their `classID`, and ther `className` for the first method booked. With a single Factory object I book multiple TMVA::DataLoader objects of type `kFisher` to try different combinations of signal and background samples, in order to use the same overall data sample for each DataLoader object. A`TDirectoryFile` object is created for each training within the `Method_Fisher` TDirectoryFile object though. Could additional leafs for each training be added to the `TrainTree` and `TestTree`?

---

<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:** [February 4, 2022, 8:58pm UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433/4 "2022-02-04T20:58:57Z")

</div>

I was eventually able to find a workaround. Under the `TrainTree` and `TestTree` object, I filled the vector “x” with Fisher discriminant values coming from events containing “Signal” under the “className” TLeaf.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [February 7, 2022, 8:47am UTC](https://root-forum.cern.ch/t/adding-pdfinterpol-logspline-to-tmva-factory/42433/5 "2022-02-07T08:47:03Z")

</div>

Thanks, @jwruss and apologies for us not providing an answer. And even more thanks for sharing your solution here, publicly: much appreciated!
