annconvergencetest.C

Go to the documentation of this file.
00001 #include "tmvaglob.C"
00002 
00003 // this macro serves to assess the convergence of the MLP ANN. 
00004 // It compares the error estimator for the training and testing samples.
00005 // If overtraining occurred, the estimator for the training sample should 
00006 // monotoneously decrease, while the estimator of the testing sample should 
00007 // show a minimum after which it increases.
00008 
00009 // input: - Input file (result from TMVA),
00010 //        - use of TMVA plotting TStyle
00011 void annconvergencetest( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE )
00012 {
00013    // set style and remove existing canvas'
00014    TMVAGlob::Initialize( useTMVAStyle );
00015   
00016    // checks if file with name "fin" is already open, and if not opens one
00017    TFile* file = TMVAGlob::OpenFile( fin );  
00018 
00019    // get all titles of the method likelihood
00020    TList titles;
00021    UInt_t ninst = TMVAGlob::GetListOfTitles("Method_MLP",titles);
00022    if (ninst==0) {
00023       cout << "Could not locate directory 'Method_MLP' in file " << fin << endl;
00024       return;
00025    }
00026    // loop over all titles
00027    TIter keyIter(&titles);
00028    TDirectory *lhdir;
00029    TKey *key;
00030    while ((key = TMVAGlob::NextKey(keyIter,"TDirectory"))) {
00031       lhdir = (TDirectory *)key->ReadObj();
00032       annconvergencetest( lhdir );
00033    }
00034 }
00035 
00036 void annconvergencetest( TDirectory *lhdir )
00037 {
00038    TString jobName = lhdir->GetName();
00039    static icanvas = -1;
00040    icanvas++;
00041    TCanvas* c = new TCanvas( Form("MLPConvergenceTest_%s",jobName.Data()), Form("MLP Convergence Test, %s",jobName.Data()), 
00042                              100 + (icanvas)*40, 0 + (icanvas+1)*20, 600, 580*0.8  );
00043   
00044    TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
00045    TH1* estimatorHistTest  = (TH1*)lhdir->Get( "estimatorHistTest"  );
00046 
00047    Double_t m1  = estimatorHistTrain->GetMaximum();
00048    Double_t m2  = estimatorHistTest ->GetMaximum();
00049    Double_t max = TMath::Max( m1, m2 );
00050    m1  = estimatorHistTrain->GetMinimum();
00051    m2  = estimatorHistTest ->GetMinimum();
00052    Double_t min = TMath::Min( m1, m2 );
00053    estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
00054    estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
00055    estimatorHistTrain->SetLineColor( 2 );
00056    estimatorHistTrain->SetLineWidth( 2 );
00057    estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
00058   
00059    estimatorHistTest->SetLineColor( 4 );
00060    estimatorHistTest->SetLineWidth( 2 );
00061 
00062    estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
00063    estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
00064    estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
00065    estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );
00066 
00067    estimatorHistTrain->Draw();
00068    estimatorHistTest ->Draw("same");
00069 
00070    // need a legend
00071    TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20, 
00072                                  1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );
00073 
00074    legend->AddEntry(estimatorHistTrain,"Training Sample","l");
00075    legend->AddEntry(estimatorHistTest,"Test sample","l");
00076    legend->Draw("same");
00077    legend->SetMargin( 0.3 );
00078 
00079    c->cd();
00080    TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
00081    c->Update();
00082 
00083    TString fname = "plots/annconvergencetest";
00084    TMVAGlob::imgconv( c, fname );
00085 }

Generated on Tue Jul 5 15:25:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1