Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMVAMultiClassGui.cxx
Go to the documentation of this file.
2 #include <iostream>
3 #include <vector>
4 
5 #include "TList.h"
6 #include "TROOT.h"
7 #include "TKey.h"
8 #include "TString.h"
9 #include "TControlBar.h"
10 #include "TObjString.h"
11 
12 
13 
14 // some global lists
15 static TList* TMVAMultiClassGui_keyContent;
16 static std::vector<TString> TMVAMultiClassGui_inactiveButtons;
17 
18 TList* TMVA::MultiClassGetKeyList( const TString& pattern )
19 {
20  TList* list = new TList();
21 
22  TIter next( TMVAMultiClassGui_keyContent );
23  TKey* key(0);
24  while ((key = (TKey*)next())) {
25  if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
26  }
27  return list;
28 }
29 
30 // utility function
31 void TMVA::MultiClassActionButton( TControlBar* cbar,
32  const TString& title, const TString& macro, const TString& comment,
33  const TString& buttonType, TString requiredKey )
34 {
35  cbar->AddButton( title, macro, comment, buttonType );
36 
37  // search
38  if (requiredKey != "") {
39  Bool_t found = kFALSE;
40  TIter next( TMVAMultiClassGui_keyContent );
41  TKey* key(0);
42  while ((key = (TKey*)next())) {
43  if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
44  }
45  if (!found) TMVAMultiClassGui_inactiveButtons.push_back( title );
46  }
47 }
48 
49 // main GUI
50 void TMVA::TMVAMultiClassGui(const char* fName ,TString dataset)
51 {
52  // Use this script in order to run the various individual macros
53  // that plot the output of TMVA (e.g. running TMVAClassification.cxx),
54  // stored in the file "TMVA.root"
55 
56  TString curMacroPath(gROOT->GetMacroPath());
57  // uncomment next line for macros submitted to next root version
58  gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
59 
60  // for the sourceforge version, including $ROOTSYS/tmva/test in the
61  // macro path is a mistake, especially if "./" was not part of path
62  // add ../macros to the path (comment out next line for the ROOT version of TMVA)
63  // gROOT->SetMacroPath(curMacroPath+":../macros:");
64 
65  TString curIncludePath=gSystem->GetIncludePath();
66  //std::cout <<"inc path="<<curIncludePath<<std::endl;
67  TString newIncludePath=TString("-I../ ")+curIncludePath;
68  gSystem->SetIncludePath(newIncludePath);
69  std::cout <<"new include path="<<gSystem->GetIncludePath()<<std::endl;
70 
71  std::cout << "--- Launch TMVA GUI to view input file: " << fName << std::endl;
72 
73  // init
74  TMVAMultiClassGui_inactiveButtons.clear();
75 
76  // check if file exist
77  TFile* file = TFile::Open( fName );
78  if (!file) {
79  std::cout << "==> Abort TMVAMultiClassGui, please verify filename" << std::endl;
80  return;
81  }
82 
83  if(file->GetListOfKeys()->GetEntries()<=0)
84  {
85  cout << "==> Abort TMVAGui, please verify if dataset exist" << endl;
86  return;
87  }
88  if( (dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()==1))
89  {
90  TKey *key=(TKey*)file->GetListOfKeys()->At(0);
91  dataset=key->GetName();
92  }else if((dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()>=1))
93  {
94  gROOT->Reset();
95  gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
96 
97  TControlBar *bar=new TControlBar("vertical","Select dataset", 0, 0);
98  bar->SetButtonWidth(300);
99  for(int i=0;i<file->GetListOfKeys()->GetEntries();i++)
100  {
101  TKey *key=(TKey*)file->GetListOfKeys()->At(i);
102  dataset=key->GetName();
103  bar->AddButton(dataset.Data(),Form("TMVA::TMVAMultiClassGui(\"%s\",\"%s\")",fName,dataset.Data()),dataset.Data());
104  }
105 
106  bar->AddSeparator();
107  bar->AddButton( "Quit", ".q", "Quit", "button");
108 
109  // set the style
110  bar->SetTextColor("black");
111  bar->Show();
112  gROOT->SaveContext();
113  return ;
114  }
115 
116  // find all references
117  TMVAMultiClassGui_keyContent = (TList*)file->GetDirectory(dataset.Data())->GetListOfKeys()->Clone();
118 
119  //close file
120  file->Close();
121 
122  TString defaultRequiredClassifier = "";
123 
124  // gROOT->Reset();
125  // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
126 
127  // create the control bar
128  TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Multiclass Classification", 0, 0 );
129 
130  const TString buttonType( "button" );
131 
132  // configure buttons
133  Int_t ic = 1;
134 
135  // find all input variables types
136  TList* keylist = MultiClassGetKeyList( "InputVariables" );
137  TListIter it( keylist );
138  TObjString* str = 0;
139  char ch = 'a';
140  while ((str = (TObjString*)it())) {
141  TString tmp = str->GetString();
142  TString title = Form( "Input variables '%s'-transformed (training sample)",
143  tmp.ReplaceAll("InputVariables_","").Data() );
144  if (tmp.Contains( "Id" )) title = "Input variables (training sample)";
145  MultiClassActionButton( cbar,
146  Form( "(%i%c) %s", ic, ch++, title.Data() ),
147  Form( "TMVA::variablesMultiClass(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data(), fName, str->GetString().Data(), title.Data() ),
148  Form( "Plots all '%s'-transformed input variables (macro variablesMultiClass(...))", str->GetString().Data() ),
149  buttonType, str->GetString() );
150  }
151  ic++;
152 
153  // correlation scatter plots
154  it.Reset(); ch = 'a';
155  while ((str = (TObjString*)it())) {
156  TString tmp = str->GetString();
157  TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
158  tmp.ReplaceAll("InputVariables_","").Data() );
159  if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
160  MultiClassActionButton( cbar,
161  Form( "(%i%c) %s", ic, ch++, title.Data() ),
162  Form( "TMVA::CorrGuiMultiClass(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data() , fName, str->GetString().Data(), title.Data() ),
163  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGuiMultiClass(...))",
164  str->GetString().Data() ),
165  buttonType, str->GetString() );
166  }
167 
168  TString title;
169  // coefficients
170  title =Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic );
171  MultiClassActionButton( cbar,
172  title,
173  Form( "TMVA::correlationsMultiClass(\"%s\",\"%s\")",dataset.Data(), fName ),
174  "Plots signal and background correlation summaries for all input variables (macro correlationsMultiClass.cxx)",
175  buttonType );
176 
177  title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
178  MultiClassActionButton( cbar,
179  title,
180  Form( "TMVA::mvasMulticlass(\"%s\",\"%s\",TMVA::kMVAType)",dataset.Data() , fName ),
181  "Plots the output of each classifier for the test data (macro mvas(...,0))",
182  buttonType, defaultRequiredClassifier );
183 
184  title =Form( "(%ib) Classifier Output Distributions (test and training samples superimposed)", ic );
185  MultiClassActionButton( cbar,
186  title,
187  Form( "TMVA::mvasMulticlass(\"%s\",\"%s\",TMVA::kCompareType)",dataset.Data(), fName ),
188  "Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas(...,3))",
189  buttonType, defaultRequiredClassifier );
190  /*
191  title = Form( "(%ic) Classifier Probability Distributions (test sample)", ic );
192  MultiClassActionButton( cbar,
193  Form( "(%ic) Classifier Probability Distributions (test sample)", ic ),
194  Form( "TMVA::mvas(\"%s\",TMVA::kProbaType)", fName ),
195  "Plots the probability of each classifier for the test data (macro mvas(...,1))",
196  buttonType, defaultRequiredClassifier );
197 
198  title =Form( "(%id) Classifier Rarity Distributions (test sample)", ic );
199  MultiClassActionButton( cbar,
200  Form( "(%id) Classifier Rarity Distributions (test sample)", ic ),
201  Form( "TMVA::mvas(\"%s\",TMVA::kRarityType)", fName ),
202  "Plots the Rarity of each classifier for the test data (macro mvas(...,2)) - background distribution should be
203  uniform", buttonType, defaultRequiredClassifier );
204 
205 
206  title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
207  MultiClassActionButton( cbar,
208  title,
209  Form( "TMVA::mvaeffs(\"%s\")", fName ),
210  "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.cxx)",
211  buttonType, defaultRequiredClassifier );
212  */
213 
214  title = Form("(%i) Classifier Backgr. Rej. vs Sig. Eff. (1-vs-rest ROC curves)", ++ic);
215  MultiClassActionButton(
216  cbar, title, Form("TMVA::efficienciesMulticlass1vsRest(\"%s\", \"%s\")", dataset.Data(), fName),
217  "Plots background rejection vs signal efficiencies (macro efficienciesMulticlass.cxx) [\"ROC\" stands "
218  "for \"Receiver Operation Characteristics\"]",
219  buttonType, defaultRequiredClassifier);
220 
221  // title = Form("(%i) Classifier (1/Backgr. Rejection) vs Sig. Eff. (1-vs-rest ROC curve)", ++ic);
222  // MultiClassActionButton(cbar, title, Form("TMVA::efficienciesMulticlass(\"%s\", \"%s\")", dataset.Data(), fName),
223  // "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands
224  // "
225  // "for \"Receiver Operation Characteristics\"]",
226  // buttonType, defaultRequiredClassifier);
227 
228  title = Form("(%i) Classifier Backgr. Rej. vs Sig. Eff. (1-vs-1 ROC curves)", ++ic);
229  MultiClassActionButton(
230  cbar, title, Form("TMVA::efficienciesMulticlass1vs1(\"%s\", \"%s\")", dataset.Data(), fName),
231  "Plots background rejection vs signal efficiencies (macro efficienciesMulticlass.cxx) [\"ROC\" stands "
232  "for \"Receiver Operation Characteristics\"]",
233  buttonType, defaultRequiredClassifier);
234 
235  // title = Form("(%i) Classifier (1/Backgr. Rejection) vs Sig. Eff. (1-vs-1 ROC curve)", ++ic);
236  // MultiClassActionButton(cbar, title, Form("TMVA::efficienciesMulticlass(\"%s\", \"%s\")", dataset.Data(), fName),
237  // "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands
238  // "
239  // "for \"Receiver Operation Characteristics\"]",
240  // buttonType, defaultRequiredClassifier);
241 
242  /*
243  title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
244  MultiClassActionButton( cbar,
245  title,
246  Form( "TMVA::paracoor(\"%s\")", fName ),
247  "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
248  buttonType, defaultRequiredClassifier );
249 
250  title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
251  MultiClassActionButton( cbar,
252  title,
253  Form( "TMVA::probas(\"%s\")", fName ),
254  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
255  buttonType, defaultRequiredClassifier );
256 
257  title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
258  MultiClassActionButton( cbar,
259  title,
260  Form( "TMVA::likelihoodrefs(\"%s\")", fName ),
261  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
262  buttonType, "Likelihood" );
263  */
264 
265  title = Form( "(%ia) Network Architecture (MLP)", ++ic );
266  TString call = Form( "TMVA::network(\"%s\",\"%s\")",dataset.Data() , fName );
267  MultiClassActionButton( cbar,
268  title,
269  call,
270  "Plots the MLP weights (macro network.cxx)",
271  buttonType, "MLP" );
272 
273  title = Form( "(%ib) Network Convergence Test (MLP)", ic );
274  MultiClassActionButton( cbar,
275  title,
276  Form( "TMVA::annconvergencetest(\"%s\",\"%s\")",dataset.Data() , fName ),
277  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
278  buttonType, "MLP" );
279 
280  title = Form( "(%i) Decision Trees (BDT)", ++ic );
281  MultiClassActionButton( cbar,
282  title,
283  Form( "TMVA::BDT(\"%s\",\"%s\")",dataset.Data() , fName ),
284  "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
285  buttonType, "BDT" );
286 
287  /*
288  title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
289  MultiClassActionButton( cbar,
290  title,
291  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
292  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
293  buttonType, "BDT" );
294 
295  */
296  title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
297  MultiClassActionButton( cbar,
298  title,
299  Form("TMVA::PlotFoams(\"%s/weights/TMVAMulticlass_PDEFoam.weights_foams.root\")",dataset.Data()),
300  "Plot Foams (macro PlotFoams.cxx)",
301  buttonType, "PDEFoam" );
302  /*
303  title = Form( "(%i) General Boost Control Plots", ++ic );
304  MultiClassActionButton( cbar,
305  title,
306  Form( "TMVA::BoostControlPlots(\"%s\")", fName ),
307  "Plots to monitor boosting of general classifiers (macro BoostControlPlots.cxx)",
308  buttonType, "Boost" );
309  */
310  cbar->AddSeparator();
311 
312  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
313 
314  // set the style
315  cbar->SetTextColor("black");
316 
317  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
318  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
319 
320  // draw
321  cbar->Show();
322 
323  // indicate inactive buttons
324  for (UInt_t i=0; i<TMVAMultiClassGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAMultiClassGui_inactiveButtons[i], 3 );
325  if (TMVAMultiClassGui_inactiveButtons.size() > 0) {
326  std::cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << std::endl;
327  }
328 
329  gROOT->SaveContext();
330 }