Dear TMVA experts,
I am using pyKeras for training a neural network. When loading the signal and background trees, I use the second argument of the AddSignalTree/AddBackgroundTree function to load the specific weights of the single background/signal samples. However, I am not sure how these weights are actually implemented in Keras.
In fact, I am also trying a parallel approach using native Keras (not TMVA) and uproot, putting the exact same weights in the sample_weight argument of the fit function. From the source code of pyKeras it seems that they are also put in sample_weight as well, but since the results are completely different, I just want to be sure what TMVA is actually doing with those weights.
Thank you and best,
The weights should be considered when training using PyKeras. It should be as when using other TMVA methods such as BDT. Do you have an example reproducing this problem, so I can investigate it ?
Hi @moneta, thanks for the reply.
The TMVA version actually produces meaningful results on my data. The problem arises when I reproduce the same network without TMVA: for my specific case, I used uproot to move the data in a flat structure, then I defined the same architecture used in pyKeras. Since the results are much worse compared to TMVA, the problem seems to be related to the definition of weights.
How does pyKeras uses the weights defined in Addsignaltree? Are they used during training or during the preprocessing? How can I emulate their behaviour on standalone Keras?
The global tree weights in PyKeras should be used as ay other TMVA methods. They are added as event weights when building the
TMVA::Event data structure.
The event weights are then passed to Keras in this line of MethodPyKeras.cxx:
PyRunString("history = model.fit(trainX, trainY, sample_weight=trainWeights, batch_size=batchSize, epochs=numEpochs, verbose=verbose, validation_data=(valX, valY, valWeights), callbacks=callbacks)",
"Failed to train model");
So, ideally, if I have a flat table with the tree weight as a specific column, and use that information on Keras sample_weight, should work? Because that is what I do, but lead to very different results.
Maybe I am missing some preprocessing of such weights between AddBackgroundTree and the event weight.
Yes, I think it should work. It is strange it is leading to a very different result. I can have a look into it, if you have a small and easy reproducible,