# Optimizer in TMVA::DNN?

**URL:** <https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748>\
**Category:** TMVA\
**Created:** [January 28, 2020, 1:14pm UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748 "2020-01-28T13:14:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![physmlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/physmlee/32/20753_2.png) [@physmlee](https://root-forum.cern.ch/u/physmlee)\
**Post date:** [January 28, 2020, 1:14pm UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/1 "2020-01-28T13:14:02Z")

</div>

Hi, everyone?

I’m practicing how to use DNN in TMVA.  
I’d like to use adam optimizer for my network, but I can’t find where and how should I set it.  
I can only find the way through pymva.  
I can find ‘Adam.h’, ‘Optimizer.h’, … headers in $ROOT directory, so I think there should be a way to set the optimizer in C++ TMVA.

Where and how can I apply an optimizer on my DNN method?

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [January 28, 2020, 4:21pm UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/2 "2020-01-28T16:21:54Z")

</div>

@moneta perhaps you can help?

---

<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:** [January 28, 2020, 4:25pm UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/3 "2020-01-28T16:25:19Z")

</div>

Or may be @kialbert ?

---

<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:** [January 28, 2020, 4:38pm UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/4 "2020-01-28T16:38:56Z")

</div>

Hi,

If you are using the kDL method (as in TMVAClassification.C) ADAM is the default optimiser. You can change it by using the Optimiser option string. (e.g. Optimizer=ADAGRAD ) will use the Adagrad optimizer

Lorenzo

---

<div class="post-metadata">

**Author:** ![physmlee](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/physmlee/32/20753_2.png) [@physmlee](https://root-forum.cern.ch/u/physmlee)\
**Post date:** [January 29, 2020, 5:22am UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/5 "2020-01-29T05:22:22Z")

</div>

Actually, I was using kDNN, but it seems better to use kDL.  
Anyway, would there be any disadvantage to use kDL rather than kDNN?  
Additionally, I can not find SOFTMAX activation function in kDL, which exists in kDNN. I want to use softmax function at the output layer, and then to use (categorical\_)crossentropy loss function.  
How should I do?

---

<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:** [January 29, 2020, 9:06am UTC](https://root-forum.cern.ch/t/optimizer-in-tmva-dnn/37748/6 "2020-01-29T09:06:22Z")

</div>

Hi,

Yes it is better to use kDL which is the new implementation supporting different types of layers.  
When you define for the network a cross-entropy loss function the softmax is applied automatically before (i.e it is included in the loss function calculation). See for example  
[https://root.cern.ch/doc/master/Cpu\_2LossFunctions\_8hxx\_source.html#l00077](https://root.cern.ch/doc/master/Cpu_2LossFunctions_8hxx_source.html#l00077)

To avoid applying 2 times the Softmax function, you need just to set to LINEAR the activation for the last layer, as it is done in the TMVAClassification.C example macro:

> <https://github.com/root-project/root/blob/master/tutorials/tmva/TMVAClassification.C#L450>

Lorenzo
