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 |
|
---|
49 | ClassImp(MHRanForestGini);
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Setup histograms, nbins is the number of bins used for the evaluation.
|
---|
54 | // The default is 100 bins.
|
---|
55 | //
|
---|
56 | MHRanForestGini::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 | //
|
---|
73 | MHRanForestGini::~MHRanForestGini()
|
---|
74 | {
|
---|
75 | delete fGraphGini;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Setup Filling of the histograms. It needs:
|
---|
81 | // MMcEvt and MRanForest
|
---|
82 | //
|
---|
83 | Bool_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 | //
|
---|
102 | Bool_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 | //
|
---|
113 | Bool_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 | fGini[i]/=fRanForest->GetNumTrees();
|
---|
124 | fGini[i]/=fRanForest->GetNumData();
|
---|
125 |
|
---|
126 | Stat_t ip = i+1.;
|
---|
127 | Stat_t ig = fGini[i];
|
---|
128 |
|
---|
129 | max=TMath::Max(max,ig);
|
---|
130 | min=TMath::Min(min,ig);
|
---|
131 |
|
---|
132 | fGraphGini->SetPoint(i,ip,ig);
|
---|
133 | }
|
---|
134 | fGraphGini->SetMaximum(1.05*max);
|
---|
135 | fGraphGini->SetMinimum(0.95*min);
|
---|
136 |
|
---|
137 | return kTRUE;
|
---|
138 | }
|
---|
139 |
|
---|
140 | // --------------------------------------------------------------------------
|
---|
141 | //
|
---|
142 | // Draw clone of histogram (For the Meaning see class description)
|
---|
143 | //
|
---|
144 | TObject *MHRanForestGini::DrawClone(Option_t *opt) const
|
---|
145 | {
|
---|
146 | if (fGraphGini->GetN()==0)
|
---|
147 | return NULL;
|
---|
148 |
|
---|
149 | TCanvas &c = *MakeDefCanvas("RanForestGini", fTitle);
|
---|
150 | gROOT->SetSelectedPad(NULL);
|
---|
151 |
|
---|
152 | //gStyle->SetOptStat(10);
|
---|
153 | TGraph &g = (TGraph&)*fGraphGini->DrawClone("AL");
|
---|
154 | g.SetBit(kCanDelete);
|
---|
155 | gPad->Modified();
|
---|
156 | gPad->Update();
|
---|
157 | if (g.GetHistogram())
|
---|
158 | {
|
---|
159 | g.GetXaxis()->SetRangeUser(0, fRanForest->GetNumTrees());
|
---|
160 | g.GetXaxis()->SetTitle("No. of RF-input parameter");
|
---|
161 | g.GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
|
---|
162 | g.SetMarkerStyle(kFullDotMedium);
|
---|
163 | //g.Draw("P");
|
---|
164 | gPad->Modified();
|
---|
165 | gPad->Update();
|
---|
166 | }
|
---|
167 | gPad->SetGrid();
|
---|
168 |
|
---|
169 | return &c;
|
---|
170 | }
|
---|
171 |
|
---|
172 | // --------------------------------------------------------------------------
|
---|
173 | //
|
---|
174 | // Draw histogram. (For the Meaning see class description)
|
---|
175 | //
|
---|
176 | void MHRanForestGini::Draw(Option_t *)
|
---|
177 | {
|
---|
178 | if (fGraphGini->GetN()==0)
|
---|
179 | return;
|
---|
180 |
|
---|
181 | if (!gPad)
|
---|
182 | MakeDefCanvas("RanForest", fTitle);
|
---|
183 |
|
---|
184 | //gStyle->SetOptStat(10);
|
---|
185 | fGraphGini->Draw("ALP");
|
---|
186 | gPad->Modified();
|
---|
187 | gPad->Update();
|
---|
188 | if (fGraphGini->GetHistogram())
|
---|
189 | {
|
---|
190 | fGraphGini->GetXaxis()->SetRangeUser(0, 1);
|
---|
191 | fGraphGini->GetXaxis()->SetTitle("No. of RF-input parameter");
|
---|
192 | fGraphGini->GetYaxis()->SetTitle("Mean decrease in Gini-index [a.u.]");
|
---|
193 |
|
---|
194 | fGraphGini->SetMarkerStyle(kFullDotSmall);
|
---|
195 | //fGraphGini->Draw("P");
|
---|
196 | gPad->Modified();
|
---|
197 | gPad->Update();
|
---|
198 | }
|
---|
199 | }
|
---|