Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
annconvergencetest.cxx
Go to the documentation of this file.
2 
3 
4 // this macro serves to assess the convergence of the MLP ANN.
5 // It compares the error estimator for the training and testing samples.
6 // If overtraining occurred, the estimator for the training sample should
7 // monotoneously decrease, while the estimator of the testing sample should
8 // show a minimum after which it increases.
9 
10 // input: - Input file (result from TMVA),
11 // - use of TMVA plotting TStyle
12 
13 void TMVA::annconvergencetest(TString dataset, TDirectory *lhdir )
14 {
15  TString jobName = lhdir->GetName();
16  static int icanvas = -1;
17  icanvas++;
18  TCanvas* c = new TCanvas( Form("MLPConvergenceTest_%s",jobName.Data()), Form("MLP Convergence Test, %s",jobName.Data()),
19  100 + (icanvas)*40, 0 + (icanvas+1)*20, 600, 580*0.8 );
20 
21  TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
22  TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" );
23 
24  Double_t m1 = estimatorHistTrain->GetMaximum();
25  Double_t m2 = estimatorHistTest ->GetMaximum();
26  Double_t max = TMath::Max( m1, m2 );
27  m1 = estimatorHistTrain->GetMinimum();
28  m2 = estimatorHistTest ->GetMinimum();
29  Double_t min = TMath::Min( m1, m2 );
30  estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
31  estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
32  estimatorHistTrain->SetLineColor( 2 );
33  estimatorHistTrain->SetLineWidth( 2 );
34  estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
35 
36  estimatorHistTest->SetLineColor( 4 );
37  estimatorHistTest->SetLineWidth( 2 );
38 
39  estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
40  estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
41  estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
42  estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );
43 
44  estimatorHistTrain->Draw("hist");
45  estimatorHistTest ->Draw("samehist");
46 
47  // need a legend
48  TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20,
49  1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );
50 
51  legend->AddEntry(estimatorHistTrain,"Training Sample","l");
52  legend->AddEntry(estimatorHistTest,"Test sample","l");
53  legend->Draw("same");
54  legend->SetMargin( 0.3 );
55 
56  c->cd();
57  TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
58  c->Update();
59 
60  TString fname = dataset+"/plots/annconvergencetest";
61  TMVAGlob::imgconv( c, fname );
62 }
63 
64 void TMVA::annconvergencetest(TString dataset, TString fin , Bool_t useTMVAStyle )
65 {
66  // set style and remove existing canvas'
67  TMVAGlob::Initialize( useTMVAStyle );
68 
69  // checks if file with name "fin" is already open, and if not opens one
70  TFile* file = TMVAGlob::OpenFile( fin );
71 
72  // get all titles of the method likelihood
73  TList titles;
74  TString metmlp="Method_MLP";
75  UInt_t ninst = TMVAGlob::GetListOfTitles(metmlp,titles,file->GetDirectory(dataset.Data()));
76  if (ninst==0) {
77  cout << "Could not locate directory 'Method_MLP' in file " << fin << endl;
78  return;
79  }
80  // loop over all titles
81  TIter keyIter(&titles);
82  TDirectory *lhdir;
83  TKey *key;
84  while ((key = TMVAGlob::NextKey(keyIter,"TDirectory"))) {
85  lhdir = (TDirectory *)key->ReadObj();
86  annconvergencetest(dataset, lhdir );
87  }
88 }