I’m still having problems with TMultiLayerPerceptron. I have tried to use it interactively, as below. It seems to take forever to train, even with one epoch (as below). Root Jet Net will give me an answer for 1000 epochs before this will finish, so I must be doing something wrong. I have fully correlated one of the inputs with the output, which I figured should have made the training easy. What is wrong?

the root file is at:

as it is too big to attatch (2.6M)

Also, I cant find out where to create the statements such as: “Entry$%2” - is ther a webpage which explains this syntax?

Toby Davies

[tdavies@nglas16 results]$ root NNtest.root

  •                                     *
  •    W E L C O M E  to  R O O T       *
  •                                     *
  • Version 4.00/08 1 December 2004 *
  •                                     *
  • You are welcome to visit our Web site *
  •      [](            *
  •                                     *

FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Attaching file NNtest.root as _file0…
root [1] TTree * tr=(TTree*)gDirectory->Get(“TDDescVar”)
root [2] TMultiLayerPerceptron myNN(“LepAEn,LepBEn,dilmass,metmag,ChargeProduct,addEt,dPhiMetLJ,ntightjets,jet1_Et,jet2_Et:22:10:5:datasource”,“weight”,tr,“Entry$%2”,"(Entry$+1)%2");
root [3] myNN.Train(1,“text, graph, update=10”);
Training the Neural Network

Well… it takes O(10s) per epoch on my laptop… slow but not exceptional.
Your network is already quite large : 9 inputs, 3 hidden layers, 47 neurons in total, …
That makes a lot of parameters to handle, particularly for the BFGS method which involves inverting a matrix at each step.

What I may suggest:

  • try using less hidden neurons
  • try a simpler learning method (stochastic is the fastest, but ha to be tuned for your network, and may give worse results at the end)
  • try using less events in the tree for the learning (if you can)

Something more important to have a good result is that you have far more often 1 as ouput than 0 (in the training sample). You must compensate this in the weight.

Anyway, with just 20 periods, here is what I got:

TFile *_file0 = TFile::Open("NNtest.root") TTree * tr=(TTree*)gDirectory->Get("TDDescVar") TMultiLayerPerceptron myNN("LepAEn,LepBEn,dilmass,metmag,ChargeProduct,addEt,dPhiMetLJ,ntightjets,jet1_Et,jet2_Et:5:datasource","weight+((datasource==0)*20)",tr,"Entry$%2","(Entry$+1)%2"); myNN.Train(20,"text, graph, update=1"); TMLPAnalyzer ana(myNN) ana.GatherInformations() ana.DrawNetwork(0,"datasource==1","datasource==0")
It is already pretty good for a such complex network trained in less that 5 minutes.

Then, about “Entry$%2”, the synthax is documented in the description of the TTree class, under the title “Special functions and variables”

Thank you for getting back to me! And thanks for the information about the special variables. At least my suspicions that the data was in some way flawed or that my method as wrong have gone. And I got it to work… but:
I used the same file and the commands:

TMultiLayerPerceptron myNN(“jet2_Et:1:datasource”,“weight+((datasource==0)*20)”,tr,“Entry$%2”,"(Entry$+1)%2");
myNN.Train(10,“text, graph, update=1”);

(note that I rigged the input and output to be exactly the same)
and it takes O(7s) to perform each step.
So It must just be that my computer is painfully slow, although I have had other neural nets work with the same input ten times as fast - is there any reason this might be the case?

I have also, as a test, just tried to run the following interactive root commands with the same file:

[tdavies@nglas16 results]$ root -l NNtest.root
root [0]
Attaching file NNtest.root as _file0…
root [1] TTree * tr=(TTree*)gDirectory->Get(“TDDescVar”)
root [2] TMultiLayerPerceptron myNN(“LepAEn,LepBEn,dilmass,metmag,ChargeProduct,addEt,dPhiMetLJ,ntightjets,jet1_Et,jet2_Et:10:datasource”,"weight+((dataso$
root [3] myNN.SetLearningMethod(TMultiLayerPerceptron::kStochastic)
root [4] myNN.Train(10,“text, graph, update=1”);
Training the Neural Network
Error in : Stop.
Epoch: 10 learn=nan test=nan
Training done.
root [5]

What is wrong with it now? Or… how do I find out - I can’t find many diagnostic functions in TMLP.

Toby Davies

This error happens when the computed error is NaN.

Most probably one of the input variables, for one event or more, takes nan as a value. I don’t have time to check your file for that, unfortunately. Maybe this is also the reason why it is slow even when in works.

Right - I suspected this; It’s reasonable that you shouldn’t be doing my checking for me. However, I tried to scan for nan in the file and failed… But I guess that is a different discussion topic. Thank you for all your help!


If you suspect that a field is a NaN, you can check for it by

myTree->Scan ("var", "var!=var");

I (unfortunately) find this very useful. :slight_smile:

Cheers! I had started another topic, but this is great. Cheers!

So there are no nans in the root file above, as far as I can tell. So what could have caused the error seen above in TMLP?

See my answer to your other post at