# The value of energy regression by DNN method is negative

**URL:** <https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400>\
**Category:** TMVA\
**Tags:** tmva\
**Created:** [August 30, 2022, 1:40pm UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400 "2022-08-30T13:40:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dawei](https://root-forum.cern.ch/u/Dawei)\
**Post date:** [August 30, 2022, 1:40pm UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/1 "2022-08-30T13:40:49Z")

</div>

I use DNN method to reconstruct gamma energy, the energy range of the training set is 20-50MeV, but the energy predictions are negative as shown below. However, the activation function of the output layer of my neural network is RELU, this confuses me.

 ![微信截图_20220830212726](https://root-forum.cern.ch/uploads/default/original/3X/3/0/3075461941c6eb00cb9c11e78a7ba5c263ae03e2.png)  
 ![微信截图_20220830212750](https://root-forum.cern.ch/uploads/default/original/3X/f/4/f467a48e938be0cb0ab4090fbd8d72480fec651d.png)

---

<div class="post-metadata">

**Author:** ![Dawei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dawei](https://root-forum.cern.ch/u/Dawei)\
**Post date:** [August 30, 2022, 1:43pm UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/2 "2022-08-30T13:43:45Z")

</div>

Could you help me？@moneta,I am sorry to bother you again. 🥹

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 30, 2022, 2:06pm UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/3 "2022-08-30T14:06:48Z")

</div>

Hi,  
Can you please share the code and input data, so I can have a closer look ?  
Thanks

Lorenzo

---

<div class="post-metadata">

**Author:** ![Dawei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dawei](https://root-forum.cern.ch/u/Dawei)\
**Post date:** [August 30, 2022, 2:32pm UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/4 "2022-08-30T14:32:14Z")

</div>

Hi, thanks for your reply! This my code and data.Because of the 3MB limit of the file size, I remove some data of the root file  
Thanks,  
David

[DNNRegression.C](https://root-forum.cern.ch/uploads/short-url/84K0oX1BMA4riTuKY87K4f1VXl4.C) (3.3 KB)  
[TrainData.root](https://root-forum.cern.ch/uploads/short-url/xCDGSI3MOCc8tOBnFGugzJOLljj.root) (2.7 MB)

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 31, 2022, 9:38am UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/5 "2022-08-31T09:38:26Z")

</div>

Hi,

The problem is in using the old `kDNN` method that is now deprecated. You should use the new `kDL ` method. The correct booking string is:

```auto
factory->BookMethod(dataloader, TMVA::Types::kDL, "DNN_CPU", nnOptions);

```

By doing this I think I am getting only positive results and a much better regression.

Cheers  
Lorenzo

---

<div class="post-metadata">

**Author:** ![Dawei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@Dawei](https://root-forum.cern.ch/u/Dawei)\
**Post date:** [September 1, 2022, 6:06am UTC](https://root-forum.cern.ch/t/the-value-of-energy-regression-by-dnn-method-is-negative/51400/6 "2022-09-01T06:06:08Z")

</div>

Hi, moneta,Thank you a lot. By changing “KDL”, I have got a better regression 😀

 ![微信截图_20220901140328](https://root-forum.cern.ch/uploads/default/original/3X/b/0/b08dbce5e29a00d9e74b7c6e6882bbb453734b16.png)
