# What is minimize target parameter in TMVA::DNN when my target variable is an array?

**URL:** <https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755>\
**Category:** TMVA\
**Tags:** tmva, root\
**Created:** [September 29, 2022, 8:41am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755 "2022-09-29T08:41:45Z")\
**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:** [September 29, 2022, 8:41am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/1 "2022-09-29T08:41:45Z")

</div>

Hello, I want to reconstruct the direction of a particle, so I store the vx,vy,vz into an array called “direction”. I use the code “dataloader-\>AddTarget( “direction” )” to add the variable and use “CROSSENTROPY” as the loss function. But in this condition, what is the minimize target parameter？

---

<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 29, 2022, 8:52am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/2 "2022-09-29T08:52:04Z")

</div>

Hello, @moneta, could you please help me?

---

<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 30, 2022, 6:57am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/3 "2022-09-30T06:57:50Z")

</div>

Hi, @kialbert Can I define the equation form of “SUMOFSQUARES” in the DNN method by myself?  
Thank you very much!

---

<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:** [September 30, 2022, 12:34pm UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/4 "2022-09-30T12:34:44Z")

</div>

Hi,  
You can have multiple target in TMVA, they are supported. You need to add vx,vy and vz as three separate targets. In case of regression you should not use `CROSSENTROPY` for the loss function, but `SUMOFSQUARES` , i.e. a mean square error function

Sorry for the delay in replying. I realised that my message did not go through before

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:** [October 1, 2022, 2:19am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/5 "2022-10-01T02:19:40Z")

</div>

Hi, moneta, thank you very much for your reply! I have added vx,vy and vz as three separate targets, and use the “SUMOFSQUARES”. In this way, the loss function will be “sqrt((vx-vx’)\*\*2+(vy-vy’)\*\*2+(vz-vz’)\*\*2)”, it means the neutral networks will minimize this function. But for direction reconstruction, I need minimize the function of “(vx_vx’+vy_vy’+vz\*vz’-1)\*\*2” which means (vx,vy,vz) and (vx’,vy’,vz’) these two unit vectors are collinear. So these two functions are not exactly equivalent，can I define the loss function by myslef?  
Thank you very much!

---

<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:** [October 4, 2022, 9:06am UTC](https://root-forum.cern.ch/t/what-is-minimize-target-parameter-in-tmva-dnn-when-my-target-variable-is-an-array/51755/6 "2022-10-04T09:06:02Z")

</div>

Hi,

Unfortunately it is not possible to define the loss function yourself in `TMVA::DNN`. It is not trivial to do it, because one needs to implement, function and gradient for both CPU and GPU.  
If it is a common used function we could add it. Can you in case provide a reference to this loss function ?

Best regards

Lorenzo
