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 | using 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 | //
|
---|
58 | MHRanForestGini::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->SetMaximum(1);
|
---|
69 | fGraphGini->SetMarkerStyle(kFullDotSmall);
|
---|
70 | }
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // Delete the histograms.
|
---|
75 | //
|
---|
76 | MHRanForestGini::~MHRanForestGini()
|
---|
77 | {
|
---|
78 | delete fGraphGini;
|
---|
79 | }
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Setup Filling of the histograms. It needs:
|
---|
84 | // MMcEvt and MRanForest
|
---|
85 | //
|
---|
86 | Bool_t MHRanForestGini::SetupFill(const MParList *plist)
|
---|
87 | {
|
---|
88 | fRanForest = (MRanForest*)plist->FindObject("MRanForest");
|
---|
89 | if (!fRanForest)
|
---|
90 | {
|
---|
91 | *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
|
---|
92 | return kFALSE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | fGini.Set(fRanForest->GetNumDim());
|
---|
96 | return kTRUE;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Fill the RanForest from a MRanForest container into the corresponding
|
---|
102 | // histogram dependant on the particle id.
|
---|
103 | //
|
---|
104 | //
|
---|
105 | Bool_t MHRanForestGini::Fill(const MParContainer *par, const Stat_t w)
|
---|
106 | {
|
---|
107 | for (Int_t i=0;i<fRanForest->GetNumDim();i++)
|
---|
108 | fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i);
|
---|
109 |
|
---|
110 | return kTRUE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | // --------------------------------------------------------------------------
|
---|
114 | //
|
---|
115 | //
|
---|
116 | Bool_t MHRanForestGini::Finalize()
|
---|
117 | {
|
---|
118 | Int_t n = fGini.GetSize();
|
---|
119 |
|
---|
120 | fGraphGini->Set(n);
|
---|
121 |
|
---|
122 | Stat_t max=0.;
|
---|
123 | Stat_t min=0.;
|
---|
124 | for (Int_t i=0; i<n; i++)
|
---|
125 | {
|
---|
126 | fGini[i]/=fRanForest->GetNumTrees();
|
---|
127 | fGini[i]/=fRanForest->GetNumData();
|
---|
128 |
|
---|
129 | Stat_t ip = i+1.;
|
---|
130 | Stat_t ig = fGini[i];
|
---|
131 |
|
---|
132 | max=TMath::Max(max,ig);
|
---|
133 | min=TMath::Min(min,ig);
|
---|
134 |
|
---|
135 | fGraphGini->SetPoint(i,ip,ig);
|
---|
136 | }
|
---|
137 | fGraphGini->SetMaximum(1.05*max);
|
---|
138 | fGraphGini->SetMinimum(0.95*min);
|
---|
139 |
|
---|
140 | return kTRUE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | // --------------------------------------------------------------------------
|
---|
144 | //
|
---|
145 | // Draw histogram. (For the Meaning see class description)
|
---|
146 | //
|
---|
147 | void MHRanForestGini::Draw(Option_t *)
|
---|
148 | {
|
---|
149 | if (fGraphGini->GetN()==0)
|
---|
150 | return;
|
---|
151 |
|
---|
152 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
153 | pad->SetBorderMode(0);
|
---|
154 |
|
---|
155 | AppendPad("");
|
---|
156 |
|
---|
157 | fGraphGini->Draw("ALP");
|
---|
158 | pad->Modified();
|
---|
159 | pad->Update();
|
---|
160 |
|
---|
161 | TH1 *h = fGraphGini->GetHistogram();
|
---|
162 | if (!h)
|
---|
163 | return;
|
---|
164 |
|
---|
165 | h->GetXaxis()->SetRangeUser(0, 1);
|
---|
166 | h->SetXTitle("No.of RF-input parameter");
|
---|
167 | h->SetYTitle("Mean decrease in Gini-index [a.u.]");
|
---|
168 |
|
---|
169 | pad->Modified();
|
---|
170 | pad->Update();
|
---|
171 | }
|
---|