Hi,
I am using TMultiLayerPerceptron to do the neural network training and
testing. However I have trouble using the output of neural network.
Let me a bit more specific. First, all the neural network is trained
successfully, I dumped the weights to a file. In principle, I have the
neural network, right? Then I load weights and I should be able to use the
neural network. I have a sample script as an attachment.
Thanks for any help.
Ming
{
gROOT->Reset();
if (!gROOT->GetClass(“TMultiLayerPerceptron”)) {
gSystem->Load(“libMLP”);
}
Float_t lPstar1(0.0), lPstar2(0.0), outNN(0.0);
Float_t lPmiss(0.0), lEtotal(0.0), lAngle(0.0);
Int_t chargeL1(0), chargeL2(0), type(0);
TFile in(“input.root”);
obc->SetBranchAddress(“lPstar1” , &lPstar1 ) ; // obc is one of the trees in the root file
obc->SetBranchAddress(“lPstar2” , &lPstar2 ) ;
obc->SetBranchAddress(“lAngle” , &lAngle ) ;
obc->SetBranchAddress(“lPmiss” , &lPmiss ) ;
obc->SetBranchAddress(“lEtotal” , &lEtotal ) ;
TBranch * outNNBranch = obc->Branch(“outNN”, &outNN, “outNN/F”);
TMultiLayerPerceptron *mlp = new TMultiLayerPerceptron(“lPstar1,lPstar2,lAngle,lPmiss,lEtotal:5:outNN”,obc);
mlp->LoadWeights(“weights.txt”);
Float_t params[5];
for (Int_t i = 0; i < obc->GetEntries(); i++) {
obc->GetEntry(i);
params[0] = lPstar1;
params[1] = lPstar2;
params[2] = lAngle;
params[3] = lPmiss;
params[4] = lEtotal;
outNN = mlp->Evaluate(0,params);
outNNBranch->Fill();
}
}