# TMVA parameter fitting with known function

**URL:** <https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562>\
**Category:** TMVA\
**Created:** [August 8, 2019, 12:55am UTC](https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562 "2019-08-08T00:55:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spaceman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spaceman](https://root-forum.cern.ch/u/spaceman)\
**Post date:** [August 8, 2019, 12:55am UTC](https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562/1 "2019-08-08T00:55:01Z")

</div>

Hi All,

Does anyone have an example of ANN regression to extract a set of parameters using a known function? This seems like it would be a popular thing to do but I haven’t found a good example to model off of yet.

Assume you know the functional form with a set of unknown parameters. You want to train an ANN to extract the best parameters the way you would in a chi^2 minimization fit. So you would want to make your own cost function based on the functional form you are starting out with.

I guess for a particular ANN method you can find the error and install your functional form to use in the back-propagation but this can’t be the easiest way to do this for a problem that must be quite popular:

For MethodMLP.cxx  
Double\_t error = ( GetOutputNeuron( itgt )-\>GetActivationValue() - desired )\*eventWeight;

rewrite:  
Double\_t error = ( F(GetOutputNeuron( itgt )-\>GetActivationValue()) - F(desired) )\*eventWeight;

Where F(x,…) is the functional form and ‘F(desired)’ is the experimental data I’m using to extract the unknown set of parameters.

Thank You

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 8, 2019, 7:48am UTC](https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562/2 "2019-08-08T07:48:51Z")

</div>

I think @moneta can most probably help you

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [August 14, 2019, 4:11pm UTC](https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562/3 "2019-08-14T16:11:59Z")

</div>

Hi,

Not sure what you want to do here. (E.g. why not use non-linear least squares?) Do you want to make a model that reimplements parameter estimation?

My understanding is that this would require the derivative of the cost function (something not possible in the current TMVA).

Using a tool that supports automatic differentiation would help you here. Support for this is under consideration for ROOT, but integration is still some time off.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![spaceman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spaceman](https://root-forum.cern.ch/u/spaceman)\
**Post date:** [August 19, 2019, 11:35pm UTC](https://root-forum.cern.ch/t/tmva-parameter-fitting-with-known-function/35562/4 "2019-08-19T23:35:15Z")

</div>

Hi Kim,

The task at hand is a function built of helicity amplitudes where there are several free parameters that connect the amplitudes to a physical interpretation. These parameters change over a range of kinematics so the standard method is using a non-linear least squares fit over many segments of the data broken up into various kinematic ranges. But this results in a lot of error in the parameters.

A ANN does a much better job with something like this but you must be able to build your own cost function. The derivative can help in some cases but most of the time the function is very complex and the numerical derivative slows things down a lot. There are other ways but it all requires implementing your own cost function. This is possible in things like tensorflow but TMVA seems to be less flexible which is a bit disappointing being so powerful for other applications.

thanks  
SM
