SetEventWeight for MLP


I’m trying to set the weights of the events with the default constructor (not the weight for the synapses - I just want to make the net more sensitive for Target == 1 events):

TMultiLayerPerceptron* nn = new TMultiLayerPerceptron(topology.c_str(), “weight+((Target==0)*20)”, tree1);

I’ve found this “weight+((Target==0)*20)” anywhere in the forum but it doesn’t work. I also tried:


I alwas get:
Error in TTreeFormula::Compile: Bad numerical expression : “Weight”

I’ve searched the reference guide but I can’t find any information about the structure of the string to the set the weights. Can anyone give an example of how to use SetEventWeight or the default constructor?

Thanks in advance!


Hi Fabian,

The weight has to be a quantity that you can draw from the TTree.
For example, if your network is
to make it 20 times more sensitive to “target==1”, you could set as weight:

In any case, I advice you to check the formula via TTree::Draw before the NN training:
You should see two peaks, one at 0 with all your background events and one at one with all your signal events.

You can also do the following:
You will see the same two peaks, but with weighted entries. If your weight is there to compensate the lower statistic of one sample, both peaks should then have a similar height (because the weight is applied).



Ok, now it’s getting clear - Thanks a lot!


One last thing, because I realize I was too quick with my formula.
You probably understood the suited form is:
otherwise the background weight is 0.