source: trunk/MagicSoft/Mars/mhist/MHRanForestGini.cc@ 1870

Last change on this file since 1870 was 1870, checked in by hengsteb, 22 years ago
*** empty log message ***
File size: 5.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHRanForest
28//
29// This histogram shows a measure of variable importance (mean decrease in
30// Gini-index)
31//
32////////////////////////////////////////////////////////////////////////////
33#include "MHRanForestGini.h"
34
35#include <TPad.h>
36#include <TGraph.h>
37#include <TStyle.h>
38#include <TCanvas.h>
39#include <TMarker.h>
40
41#include "MParList.h"
42#include "MBinning.h"
43#include "MRanTree.h"
44#include "MRanForest.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49ClassImp(MHRanForestGini);
50
51// --------------------------------------------------------------------------
52//
53// Setup histograms, nbins is the number of bins used for the evaluation.
54// The default is 100 bins.
55//
56MHRanForestGini::MHRanForestGini(Int_t nbins, const char *name, const char *title)
57{
58 //
59 // set the name and title of this object
60 //
61 fName = name ? name : "MHRanForestGini";
62 fTitle = title ? title : "Measure of importance of Random Forest-input parameters";
63
64 fGraphGini = new TGraph;
65 fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease");
66 fGraphGini->SetMaximum(1);
67}
68
69// --------------------------------------------------------------------------
70//
71// Delete the histograms.
72//
73MHRanForestGini::~MHRanForestGini()
74{
75 delete fGraphGini;
76}
77
78// --------------------------------------------------------------------------
79//
80// Setup Filling of the histograms. It needs:
81// MMcEvt and MRanForest
82//
83Bool_t MHRanForestGini::SetupFill(const MParList *plist)
84{
85 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
86 if (!fRanForest)
87 {
88 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fGini.Set(fRanForest->GetNumDim());
93 return kTRUE;
94}
95
96// --------------------------------------------------------------------------
97//
98// Fill the RanForest from a MRanForest container into the corresponding
99// histogram dependant on the particle id.
100//
101//
102Bool_t MHRanForestGini::Fill(const MParContainer *par)
103{
104 for (Int_t i=0;i<fRanForest->GetNumDim();i++)
105 fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i);
106
107 return kTRUE;
108}
109
110// --------------------------------------------------------------------------
111//
112//
113Bool_t MHRanForestGini::Finalize()
114{
115 Int_t n = fGini.GetSize();
116
117 fGraphGini->Set(n);
118
119 Stat_t max=0.;
120 Stat_t min=0.;
121 for (Int_t i=0; i<n; i++)
122 {
123 Stat_t ip = i+1.;
124 fGini[i]/=Stat_t(fRanForest->GetNumTrees());
125 fGini[i]/=Stat_t(fRanForest->GetNumData());
126 Stat_t ig = fGini[i];
127 max=TMath::Max(max,ig);
128 min=TMath::Min(min,ig);
129 fGraphGini->SetPoint(i,ip,ig);
130 }
131 fGraphGini->SetMaximum(1.05*max);
132 fGraphGini->SetMinimum(0.95*min);
133
134 return kTRUE;
135}
136
137// --------------------------------------------------------------------------
138//
139// Draw clone of histogram (For the Meaning see class description)
140//
141TObject *MHRanForestGini::DrawClone(Option_t *opt) const
142{
143 if (fGraphGini->GetN()==0)
144 return NULL;
145
146 TCanvas &c = *MakeDefCanvas("RanForestGini", fTitle);
147 gROOT->SetSelectedPad(NULL);
148
149 gStyle->SetOptStat(10);
150 TGraph &g = (TGraph&)*fGraphGini->DrawClone("AL");
151 g.SetBit(kCanDelete);
152 gPad->Modified();
153 gPad->Update();
154 if (g.GetHistogram())
155 {
156 g.GetXaxis()->SetRangeUser(0, fRanForest->GetNumTrees());
157 g.GetXaxis()->SetTitle("No. of RF-input parameter");
158 g.GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
159 g.SetMarkerStyle(kFullDotlarge);
160 g.Draw("P");
161
162 }
163 gPad->SetGrid();
164
165 return &c;
166}
167
168// --------------------------------------------------------------------------
169//
170// Draw histogram. (For the Meaning see class description)
171//
172void MHRanForestGini::Draw(Option_t *)
173{
174 if (fGraphGini->GetN()==0)
175 return;
176
177 if (!gPad)
178 MakeDefCanvas("RanForest", fTitle);
179
180 gStyle->SetOptStat(10);
181 fGraphGini->Draw("ALP");
182 gPad->Modified();
183 gPad->Update();
184 if (fGraphGini->GetHistogram())
185 {
186 fGraphGini->GetXaxis()->SetRangeUser(0, 1);
187 fGraphGini->GetXaxis()->SetTitle("No. of RF-input parameter");
188 fGraphGini->GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
189
190 fGraphGini->SetMarkerStyle(kFullDotSmall);
191 fGraphGini->Draw("P");
192 gPad->Modified();
193 gPad->Update();
194 }
195}
Note: See TracBrowser for help on using the repository browser.