Logo ROOT   6.18/05
Reference Guide
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
13void 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
64void 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}
#define c(i)
Definition: RSha256.hxx:101
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
char * Form(const char *fmt,...)
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:31
Describe directory structure in memory.
Definition: TDirectory.h:34
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:805
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
The TH1 histogram class.
Definition: TH1.h:56
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6309
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7964
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
TAxis * GetYaxis()
Definition: TH1.h:317
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2981
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition: TH1.cxx:8049
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:722
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
void SetMargin(Float_t margin)
Definition: TLegend.h:69
A doubly linked list.
Definition: TList.h:44
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
static constexpr double m2
UInt_t GetListOfTitles(TDirectory *rfdir, TList &titles)
Definition: tmvaglob.cxx:636
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
TKey * NextKey(TIter &keyIter, TString className)
Definition: tmvaglob.cxx:357
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
void annconvergencetest(TString dataset, TDirectory *lhdir)
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
Definition: file.py:1