source: trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc@ 4754

Last change on this file since 4754 was 2296, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.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 "MRanTree.h"
44#include "MRanForest.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49ClassImp(MHRanForestGini);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Setup histograms, nbins is the number of bins used for the evaluation.
56// The default is 100 bins.
57//
58MHRanForestGini::MHRanForestGini(Int_t nbins, const char *name, const char *title)
59{
60 //
61 // set the name and title of this object
62 //
63 fName = name ? name : "MHRanForestGini";
64 fTitle = title ? title : "Measure of importance of Random Forest-input parameters";
65
66 fGraphGini = new TGraph;
67 fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease");
68 fGraphGini->SetMarkerStyle(kFullDotSmall);
69}
70
71// --------------------------------------------------------------------------
72//
73// Delete the histograms.
74//
75MHRanForestGini::~MHRanForestGini()
76{
77 delete fGraphGini;
78}
79
80// --------------------------------------------------------------------------
81//
82// Setup Filling of the histograms. It needs:
83// MMcEvt and MRanForest
84//
85Bool_t MHRanForestGini::SetupFill(const MParList *plist)
86{
87 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
88 if (!fRanForest)
89 {
90 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
91 return kFALSE;
92 }
93
94 fGini.Set(fRanForest->GetNumDim());
95 return kTRUE;
96}
97
98// --------------------------------------------------------------------------
99//
100// Fill the RanForest from a MRanForest container into the corresponding
101// histogram dependant on the particle id.
102//
103//
104Bool_t MHRanForestGini::Fill(const MParContainer *par, const Stat_t w)
105{
106 for (Int_t i=0;i<fRanForest->GetNumDim();i++)
107 fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i);
108
109 return kTRUE;
110}
111
112// --------------------------------------------------------------------------
113//
114//
115Bool_t MHRanForestGini::Finalize()
116{
117 const Int_t n = fGini.GetSize();
118
119 fGraphGini->Set(n);
120
121 Stat_t max=0;
122 Stat_t min=0;
123 for (Int_t i=0; i<n; i++)
124 {
125 fGini[i] /= fRanForest->GetNumTrees();
126 fGini[i] /= fRanForest->GetNumData();
127
128 const Stat_t ip = i+1;
129 const Stat_t ig = fGini[i];
130
131 if (ig>max) max=ig;
132 if (ig<min) min=ig;
133
134 fGraphGini->SetPoint(i,ip,ig);
135 }
136
137 // This is used in root>3.04/? so that SetMaximum/Minimum can succeed
138 fGraphGini->GetHistogram();
139
140 fGraphGini->SetMaximum(1.05*max);
141 fGraphGini->SetMinimum(0.95*min);
142
143 return kTRUE;
144}
145
146// --------------------------------------------------------------------------
147//
148// Draw histogram. (For the Meaning see class description)
149//
150void MHRanForestGini::Draw(Option_t *)
151{
152 if (fGraphGini->GetN()==0)
153 return;
154
155 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
156 pad->SetBorderMode(0);
157
158 AppendPad("");
159
160 fGraphGini->Draw("ALP");
161 pad->Modified();
162 pad->Update();
163
164 TH1 *h = fGraphGini->GetHistogram();
165 if (!h)
166 return;
167
168 //h->GetXaxis()->SetRangeUser(0, fGini.GetSize()+1);
169 h->SetXTitle("No.of RF-input parameter");
170 h->SetYTitle("Mean decrease in Gini-index [a.u.]");
171
172 pad->Modified();
173 pad->Update();
174}
Note: See TracBrowser for help on using the repository browser.