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

Last change on this file since 1866 was 1866, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.5 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 "MRanForest.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MMcEvt.hxx"
49
50ClassImp(MHRanForestGini);
51
52// --------------------------------------------------------------------------
53//
54// Setup histograms, nbins is the number of bins used for the evaluation.
55// The default is 100 bins.
56//
57MHRanForestGini::MHRanForestGini(Int_t nbins, const char *name, const char *title)
58{
59 //
60 // set the name and title of this object
61 //
62 fName = name ? name : "MHRanForestGini";
63 fTitle = title ? title : "Measure of importance of Random Forest-input parameters";
64
65 fGraphGini = new TGraph;
66 fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease");
67 fGraphGini->SetMaximum(1);
68}
69
70// --------------------------------------------------------------------------
71//
72// Delete the histograms.
73//
74MHRanForestGini::~MHRanForestGini()
75{
76 delete fGraphGini;
77}
78
79// --------------------------------------------------------------------------
80//
81// Setup Filling of the histograms. It needs:
82// MMcEvt and MRanForest
83//
84Bool_t MHRanForestGini::SetupFill(const MParList *plist)
85{
86 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
87 if (!fMcEvt)
88 {
89 *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
94 if (!fRanForest)
95 {
96 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fGini.Set(fRanForest->GetNumDim());
101 return kTRUE;
102}
103
104// --------------------------------------------------------------------------
105//
106// Fill the RanForest from a MRanForest container into the corresponding
107// histogram dependant on the particle id.
108//
109//
110Bool_t MHRanForestGini::Fill(const MParContainer *par)
111{
112 for (Int_t i=0;i<fRanForest->GetNumDim();i++)
113 fGini[i]+=fRanForest->GetGiniDec(i);
114
115 return kTRUE;
116}
117
118// --------------------------------------------------------------------------
119//
120//
121Bool_t MHRanForestGini::Finalize()
122{
123 Int_t n = fGini.GetSize();
124
125 fGraphGini->Set(n);
126
127 Stat_t max=0.;
128 Stat_t min=0.;
129 for (Int_t i=0; i<n; i++)
130 {
131 Stat_t ip = i+1.;
132 fGini[i]/=Stat_t(fRanForest->GetNumTrees());
133 fGini[i]/=Stat_t(fRanForest->GetNumData());
134 Stat_t ig = fGini[i];
135 max=TMath::Max(max,ig);
136 min=TMath::Min(min,ig);
137 fGraphGini->SetPoint(i,ip,ig);
138 }
139 fGraphGini->SetMaximum(1.05*max);
140 fGraphGini->SetMinimum(0.95*min);
141
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Draw clone of histogram (For the Meaning see class description)
148//
149TObject *MHRanForestGini::DrawClone(Option_t *opt) const
150{
151 if (fGraphGini->GetN()==0)
152 return NULL;
153
154 TCanvas &c = *MakeDefCanvas("RanForestGini", fTitle);
155 gROOT->SetSelectedPad(NULL);
156
157 gStyle->SetOptStat(10);
158 TGraph &g = (TGraph&)*fGraphGini->DrawClone("AL");
159 g.SetBit(kCanDelete);
160 gPad->Modified();
161 gPad->Update();
162 if (g.GetHistogram())
163 {
164 g.GetXaxis()->SetRangeUser(0, fRanForest->GetNumTrees());
165 g.GetXaxis()->SetTitle("No. of RF-input parameter parameter");
166 g.GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
167 g.SetMarkerStyle(kFullDotlarge);
168 g.Draw("P");
169
170 }
171 gPad->SetGrid();
172
173 return &c;
174}
175
176// --------------------------------------------------------------------------
177//
178// Draw histogram. (For the Meaning see class description)
179//
180void MHRanForestGini::Draw(Option_t *)
181{
182 if (fGraphGini->GetN()==0)
183 return;
184
185 if (!gPad)
186 MakeDefCanvas("RanForest", fTitle);
187
188 gStyle->SetOptStat(10);
189 fGraphGini->Draw("ALP");
190 gPad->Modified();
191 gPad->Update();
192 if (fGraphGini->GetHistogram())
193 {
194 fGraphGini->GetXaxis()->SetRangeUser(0, 1);
195 fGraphGini->GetXaxis()->SetTitle("No. of parameter");
196 fGraphGini->GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
197
198 fGraphGini->SetMarkerStyle(kFullDotSmall);
199 fGraphGini->Draw("P");
200 gPad->Modified();
201 gPad->Update();
202 }
203}
Note: See TracBrowser for help on using the repository browser.