ROOT  6.06/09
Reference Guide
Ranking.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate Data analysis *
6  * Package: TMVA *
7  * Class : Ranking *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
17  * *
18  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * MPI-K Heidelberg, Germany *
21  * *
22  * Redistribution and use in source and binary forms, with or without *
23  * modification, are permitted according to the terms listed in LICENSE *
24  * (http://tmva.sourceforge.net/LICENSE) *
25  **********************************************************************************/
26 
27 //_______________________________________________________________________
28 //
29 // Ranking for variables in method (implementation)
30 //_______________________________________________________________________
31 
32 #include <iomanip>
33 
34 #include "TString.h"
35 
36 #include "TMVA/Ranking.h"
37 #include "TMVA/MsgLogger.h"
38 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// default constructor
43 
44 TMVA::Ranking::Ranking()
45  : fRanking(),
46  fContext(""),
47  fRankingDiscriminatorName( "" ),
48  fLogger( new MsgLogger("", kINFO) )
49 {
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// constructor
54 
55 TMVA::Ranking::Ranking( const TString& context, const TString& rankingDiscriminatorName )
56  : fRanking(),
57  fContext( context ),
58  fRankingDiscriminatorName( rankingDiscriminatorName ),
59  fLogger( new MsgLogger(fContext.Data(), kINFO) )
60 {
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// destructor
65 
67 {
68  fRanking.clear();
69  delete fLogger;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 
74 void TMVA::Ranking::SetContext( const TString& context)
75 {
76  fContext = context;
77  fLogger->SetSource( fContext.Data() );
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Add a new rank
82 /// take ownership of it
83 
84 void TMVA::Ranking::AddRank( const Rank& rank )
85 {
86  // sort according to rank value (descending)
87  // Who the hell knows why this does not compile on windos.. write the sorting
88  // reversing myself... (means sorting in "descending" order)
89  // --> std::sort ( fRanking.begin(), fRanking.end() );
90  // --> std::reverse( fRanking.begin(), fRanking.end() );
91  fRanking.push_back( rank );
92 
93  UInt_t sizeofarray=fRanking.size();
94  Rank temp(fRanking[0]);
95  for (UInt_t i=0; i<sizeofarray; i++) {
96  for (UInt_t j=sizeofarray-1; j>i; j--) {
97  if (fRanking[j-1] < fRanking[j]) {
98  temp = fRanking[j-1];fRanking[j-1] = fRanking[j]; fRanking[j] = temp;
99  }
100  }
101  }
102 
103  for (UInt_t i=0; i<fRanking.size(); i++) fRanking[i].SetRank( i+1 );
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// get maximum length of variable names
108 
110 {
111  Int_t maxL = 0;
112  for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ir++ )
113  if ((*ir).GetVariable().Length() > maxL) maxL = (*ir).GetVariable().Length();
114 
115  TString hline = "";
116  for (Int_t i=0; i<maxL+15+fRankingDiscriminatorName.Length(); i++) hline += "-";
117  Log() << kINFO << "Ranking result (top variable is best ranked)" << Endl;
118  Log() << kINFO << hline << Endl;
119  Log() << kINFO << std::setiosflags(std::ios::left)
120  << std::setw(5) << "Rank : "
121  << std::setw(maxL+0) << "Variable "
122  << std::resetiosflags(std::ios::right)
123  << " : " << fRankingDiscriminatorName << Endl;
124  Log() << kINFO << hline << Endl;
125  for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ir++ ) {
126  Log() << kINFO
127  << Form( "%4i : ",(*ir).GetRank() )
128  << std::setw(TMath::Max(maxL+0,9)) << (*ir).GetVariable().Data()
129  << Form( " : %3.3e", (*ir).GetRankValue() ) << Endl;
130  }
131  Log() << kINFO << hline << Endl;
132 }
133 
134 // ===============================================================================================
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// constructor
138 
139 TMVA::Rank::Rank( const TString& variable, Double_t rankValue )
140  : fVariable( variable ),
141  fRankValue( rankValue ),
142  fRank( -1 )
143 {
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// destructor
148 
150 {
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// comparison operator <
155 
156 Bool_t TMVA::Rank::operator< ( const Rank& other ) const
157 {
158  if (fRankValue < other.fRankValue) return true;
159  else return false;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// comparison operator >
164 
165 Bool_t TMVA::Rank::operator> ( const Rank& other ) const
166 {
167  if (fRankValue > other.fRankValue) return true;
168  else return false;
169 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual ~Rank()
destructor
Definition: Ranking.cxx:149
void SetContext(const TString &context)
Definition: Ranking.cxx:74
std::vector< std::vector< double > > Data
Bool_t operator>(const Rank &other) const
comparison operator >
Definition: Ranking.cxx:165
ClassImp(TMVA::Ranking) TMVA
default constructor
Definition: Ranking.cxx:39
Rank(const TString &variable, Double_t rankValue)
constructor
Definition: Ranking.cxx:139
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual ~Ranking()
destructor
Definition: Ranking.cxx:66
double Double_t
Definition: RtypesCore.h:55
Double_t fRankValue
Definition: Ranking.h:97
Abstract ClassifierFactory template that handles arbitrary types.
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Definition: Ranking.cxx:84
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
virtual void Print() const
get maximum length of variable names
Definition: Ranking.cxx:109
Bool_t operator<(const Rank &other) const
comparison operator <
Definition: Ranking.cxx:156
Definition: math.cpp:60