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

Last change on this file since 1988 was 1966, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.4 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 fGraphGini->SetMarkerStyle(kFullDotSmall);
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 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
87 if (!fRanForest)
88 {
89 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fGini.Set(fRanForest->GetNumDim());
94 return kTRUE;
95}
96
97// --------------------------------------------------------------------------
98//
99// Fill the RanForest from a MRanForest container into the corresponding
100// histogram dependant on the particle id.
101//
102//
103Bool_t MHRanForestGini::Fill(const MParContainer *par)
104{
105 for (Int_t i=0;i<fRanForest->GetNumDim();i++)
106 fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i);
107
108 return kTRUE;
109}
110
111// --------------------------------------------------------------------------
112//
113//
114Bool_t MHRanForestGini::Finalize()
115{
116 Int_t n = fGini.GetSize();
117
118 fGraphGini->Set(n);
119
120 Stat_t max=0.;
121 Stat_t min=0.;
122 for (Int_t i=0; i<n; i++)
123 {
124 fGini[i]/=fRanForest->GetNumTrees();
125 fGini[i]/=fRanForest->GetNumData();
126
127 Stat_t ip = i+1.;
128 Stat_t ig = fGini[i];
129
130 max=TMath::Max(max,ig);
131 min=TMath::Min(min,ig);
132
133 fGraphGini->SetPoint(i,ip,ig);
134 }
135 fGraphGini->SetMaximum(1.05*max);
136 fGraphGini->SetMinimum(0.95*min);
137
138 return kTRUE;
139}
140
141// --------------------------------------------------------------------------
142//
143// Draw histogram. (For the Meaning see class description)
144//
145void MHRanForestGini::Draw(Option_t *)
146{
147 if (fGraphGini->GetN()==0)
148 return;
149
150 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
151 pad->SetBorderMode(0);
152
153 AppendPad("");
154
155 fGraphGini->Draw("ALP");
156 pad->Modified();
157 pad->Update();
158
159 TH1 *h = fGraphGini->GetHistogram();
160 if (!h)
161 return;
162
163 h->GetXaxis()->SetRangeUser(0, 1);
164 h->SetXTitle("No.of RF-input parameter");
165 h->SetYTitle("Mean decrease in Gini-index [a.u.]");
166
167 pad->Modified();
168 pad->Update();
169}
Note: See TracBrowser for help on using the repository browser.