Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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( TString::Format("MLPConvergenceTest_%s",jobName.Data()),
19 TString::Format("MLP Convergence Test, %s",jobName.Data()),
20 100 + (icanvas)*40, 0 + (icanvas+1)*20, 600, 580*0.8 );
21
22 TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
23 TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" );
24
25 Double_t m1 = estimatorHistTrain->GetMaximum();
26 Double_t m2 = estimatorHistTest ->GetMaximum();
27 Double_t max = TMath::Max( m1, m2 );
28 m1 = estimatorHistTrain->GetMinimum();
29 m2 = estimatorHistTest ->GetMinimum();
30 Double_t min = TMath::Min( m1, m2 );
31 estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
32 estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
33 estimatorHistTrain->SetLineColor( 2 );
34 estimatorHistTrain->SetLineWidth( 2 );
35 estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
36
37 estimatorHistTest->SetLineColor( 4 );
38 estimatorHistTest->SetLineWidth( 2 );
39
40 estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
41 estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
42 estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
43 estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );
44
45 estimatorHistTrain->Draw("hist");
46 estimatorHistTest ->Draw("samehist");
47
48 // need a legend
49 TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20,
50 1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );
51
52 legend->AddEntry(estimatorHistTrain,"Training Sample","l");
53 legend->AddEntry(estimatorHistTest,"Test sample","l");
54 legend->Draw("same");
55 legend->SetMargin( 0.3 );
56
57 c->cd();
58 TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
59 c->Update();
60
61 TString fname = dataset+"/plots/annconvergencetest";
62 TMVAGlob::imgconv( c, fname );
63}
64
65void TMVA::annconvergencetest(TString dataset, TString fin , Bool_t useTMVAStyle )
66{
67 // set style and remove existing canvas'
68 TMVAGlob::Initialize( useTMVAStyle );
69
70 // checks if file with name "fin" is already open, and if not opens one
71 TFile* file = 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,file->GetDirectory(dataset.Data()));
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(dataset, lhdir );
88 }
89}
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Definition RtypesCore.h:63
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
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:23
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Describe directory structure in memory.
Definition TDirectory.h:45
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6686
TAxis * GetXaxis()
Definition TH1.h:324
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:8513
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:403
TAxis * GetYaxis()
Definition TH1.h:325
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:404
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:8603
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:758
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:317
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:422
void SetMargin(Float_t margin)
Definition TLegend.h:69
A doubly linked list.
Definition TList.h:38
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
__device__ AFloat max(AFloat x, AFloat y)
Definition Kernels.cuh:207
UInt_t GetListOfTitles(TDirectory *rfdir, TList &titles)
Definition tmvaglob.cxx:643
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition tmvaglob.cxx:176
TKey * NextKey(TIter &keyIter, TString className)
Definition tmvaglob.cxx:364
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition tmvaglob.cxx:270
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)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198