SetEventWeight for MLP

Hello,

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:

weight+=(Target==0)*20
weight=1+(Target==0)*20
Weight+=(Target==0)*20

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!

Regards,
Fabian

Hi Fabian,

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

In any case, I advice you to check the formula via TTree::Draw before the NN training:
myTree->Draw(“20*(d==1)”)
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:
myTree->Draw(“d”,“20*(d==1)”)
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).

Cheers,
Christophe.

Hello,

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

Regards,
Fabian

One last thing, because I realize I was too quick with my formula.
You probably understood the suited form is:
"20*(d==1)+1*(d==0)"
otherwise the background weight is 0.