ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
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 = "plots/annconvergencetest";
61  TMVAGlob::imgconv( c, fname );
62 }
63 
64 void TMVA::annconvergencetest( 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 =
71  TMVAGlob::OpenFile( fin );
72 
73  // get all titles of the method likelihood
74  TList titles;
75  TString metmlp="Method_MLP";
76  UInt_t ninst = TMVAGlob::GetListOfTitles(metmlp,titles);
77  if (ninst==0) {
78  cout << "Could not locate directory 'Method_MLP' in file " << fin << endl;
79  return;
80  }
81  // loop over all titles
82  TIter keyIter(&titles);
83  TDirectory *lhdir;
84  TKey *key;
85  while ((key = TMVAGlob::NextKey(keyIter,"TDirectory"))) {
86  lhdir = (TDirectory *)key->ReadObj();
87  annconvergencetest( lhdir );
88  }
89 }
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:245
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:727
return c
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
Basic string class.
Definition: TString.h:137
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
bool Bool_t
Definition: RtypesCore.h:59
void SetMargin(Float_t margin)
Definition: TLegend.h:80
TKey * NextKey(TIter &keyIter, TString className)
Definition: tmvaglob.cxx:357
TLegend * legend
Definition: pirndm.C:35
const char * Data() const
Definition: TString.h:349
Float_t GetTopMargin() const
Definition: TAttPad.h:56
Float_t GetRightMargin() const
Definition: TAttPad.h:55
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
A doubly linked list.
Definition: TList.h:47
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TAxis * GetYaxis()
Definition: TH1.h:320
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
Describe directory structure in memory.
Definition: TDirectory.h:44
The TH1 histogram class.
Definition: TH1.h:80
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
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:7921
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
void annconvergencetest(TDirectory *lhdir)
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:8006
TAxis * GetXaxis()
Definition: TH1.h:319
UInt_t GetListOfTitles(TDirectory *rfdir, TList &titles)
Definition: tmvaglob.cxx:634