Logo ROOT   6.18/05
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/*! \class TMVA::Ranking
28\ingroup TMVA
29Ranking for variables in method (implementation)
30*/
31
32#include "TMVA/Ranking.h"
33
34#include "TMVA/MsgLogger.h"
35#include "TMVA/Types.h"
36
37#include "TString.h"
38
39#include <iomanip>
40
42
43////////////////////////////////////////////////////////////////////////////////
44/// default constructor
45
47: fRanking(),
48 fContext(""),
49 fRankingDiscriminatorName( "" ),
50 fLogger( new MsgLogger("", kINFO) )
51{
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// constructor
56
57TMVA::Ranking::Ranking( const TString& context, const TString& rankingDiscriminatorName )
58 : fRanking(),
59 fContext( context ),
60 fRankingDiscriminatorName( rankingDiscriminatorName ),
61 fLogger( new MsgLogger(fContext.Data(), kINFO) )
62{
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// destructor
67
69{
70 fRanking.clear();
71 delete fLogger;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75
77{
78 fContext = context;
79 fLogger->SetSource( fContext.Data() );
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Add a new rank
84/// take ownership of it
85
86void TMVA::Ranking::AddRank( const Rank& rank )
87{
88 // sort according to rank value (descending)
89 // Who the hell knows why this does not compile on windows.. write the sorting
90 // reversing myself... (means sorting in "descending" order)
91 // --> std::sort ( fRanking.begin(), fRanking.end() );
92 // --> std::reverse( fRanking.begin(), fRanking.end() );
93 fRanking.push_back( rank );
94
95 UInt_t sizeofarray=fRanking.size();
96 Rank temp(fRanking[0]);
97 for (UInt_t i=0; i<sizeofarray; i++) {
98 for (UInt_t j=sizeofarray-1; j>i; j--) {
99 if (fRanking[j-1] < fRanking[j]) {
100 temp = fRanking[j-1];fRanking[j-1] = fRanking[j]; fRanking[j] = temp;
101 }
102 }
103 }
104
105 for (UInt_t i=0; i<fRanking.size(); i++) fRanking[i].SetRank( i+1 );
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// get maximum length of variable names
110
112{
113 Int_t maxL = 0;
114 for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ++ir )
115 if ((*ir).GetVariable().Length() > maxL) maxL = (*ir).GetVariable().Length();
116
117 TString hline = "";
118 for (Int_t i=0; i<maxL+15+fRankingDiscriminatorName.Length(); i++) hline += "-";
119 Log() << kHEADER << "Ranking result (top variable is best ranked)" << Endl;
120 Log() << kINFO << hline << Endl;
121 Log() << kINFO << std::setiosflags(std::ios::left)
122 << std::setw(5) << "Rank : "
123 << std::setw(maxL+0) << "Variable "
124 << std::resetiosflags(std::ios::right)
125 << " : " << fRankingDiscriminatorName << Endl;
126 Log() << kINFO << hline << Endl;
127 for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ++ir ) {
128 Log() << kINFO
129 << Form( "%4i : ",(*ir).GetRank() )
130 << std::setw(TMath::Max(maxL+0,9)) << (*ir).GetVariable().Data()
131 << Form( " : %3.3e", (*ir).GetRankValue() ) << Endl;
132 }
133 Log() << kINFO << hline << Endl;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// constructor
138
139TMVA::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
156Bool_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
165Bool_t TMVA::Rank::operator> ( const Rank& other ) const
166{
167 if (fRankValue > other.fRankValue) return true;
168 else return false;
169}
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
char * Form(const char *fmt,...)
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Double_t fRankValue
Definition: Ranking.h:95
virtual ~Rank()
destructor
Definition: Ranking.cxx:149
Rank(const TString &variable, Double_t rankValue)
constructor
Definition: Ranking.cxx:139
Bool_t operator>(const Rank &other) const
comparison operator >
Definition: Ranking.cxx:165
Bool_t operator<(const Rank &other) const
comparison operator <
Definition: Ranking.cxx:156
Ranking for variables in method (implementation)
Definition: Ranking.h:48
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Definition: Ranking.cxx:86
virtual void Print() const
get maximum length of variable names
Definition: Ranking.cxx:111
void SetContext(const TString &context)
Definition: Ranking.cxx:76
virtual ~Ranking()
destructor
Definition: Ranking.cxx:68
Ranking()
default constructor
Definition: Ranking.cxx:46
Basic string class.
Definition: TString.h:131
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Double_t Log(Double_t x)
Definition: TMath.h:748