ROOT logo
// @(#)root/tmva $Id$
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss 

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate Data analysis       *
 * Package: TMVA                                                                  *
 * Class  : Ranking                                                               *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Implementation (see header for description)                               *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         * 
 *      MPI-K Heidelberg, Germany                                                 * 
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

//_______________________________________________________________________
// 
// Ranking for variables in method (implementation)
//_______________________________________________________________________

#include <iomanip>

#include "TString.h"

#include "TMVA/Ranking.h"
#include "TMVA/MsgLogger.h"

ClassImp(TMVA::Ranking)

//_______________________________________________________________________
TMVA::Ranking::Ranking() 
: fRanking(),
   fContext(""),
   fRankingDiscriminatorName( "" ),
   fLogger( new MsgLogger("", kINFO) )
{
   // default constructor
}

//_______________________________________________________________________
TMVA::Ranking::Ranking( const TString& context, const TString& rankingDiscriminatorName ) 
   : fRanking(),
     fContext( context ),
     fRankingDiscriminatorName( rankingDiscriminatorName ),
     fLogger( new MsgLogger(fContext.Data(), kINFO) )
{
   // constructor
}

//_______________________________________________________________________
TMVA::Ranking::~Ranking() 
{
   // destructor
   fRanking.clear();
   delete fLogger;
}

//_______________________________________________________________________
void TMVA::Ranking::SetContext( const TString& context) 
{
   fContext = context;
   fLogger->SetSource( fContext.Data() );
}

//_______________________________________________________________________
void TMVA::Ranking::AddRank( const Rank& rank )
{
   // Add a new rank
   // take ownership of it

   // sort according to rank value (descending)
   // Who the hell knows why this does not compile on windos.. write the sorting 
   // reversing myself... (means sorting in "descending" order)
   //   --> std::sort   ( fRanking.begin(), fRanking.end() );
   //   --> std::reverse( fRanking.begin(), fRanking.end() );
   fRanking.push_back( rank );
      
   UInt_t sizeofarray=fRanking.size();
   Rank  temp(fRanking[0]);
   for (UInt_t i=0; i<sizeofarray; i++) {
      for (UInt_t j=sizeofarray-1; j>i; j--) {
         if (fRanking[j-1] < fRanking[j]) {
            temp = fRanking[j-1];fRanking[j-1] = fRanking[j]; fRanking[j] = temp;
         }
      }
   }
   
   for (UInt_t i=0; i<fRanking.size(); i++) fRanking[i].SetRank( i+1 );
}

//_______________________________________________________________________
void TMVA::Ranking::Print() const
{
   // get maximum length of variable names
   Int_t maxL = 0; 
   for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ir++ ) 
      if ((*ir).GetVariable().Length() > maxL) maxL = (*ir).GetVariable().Length();
   
   TString hline = "";
   for (Int_t i=0; i<maxL+15+fRankingDiscriminatorName.Length(); i++) hline += "-";
   Log() << kINFO << "Ranking result (top variable is best ranked)" << Endl;
   Log() << kINFO << hline << Endl;
   Log() << kINFO << std::setiosflags(std::ios::left) 
         << std::setw(5) << "Rank : "
         << std::setw(maxL+0) << "Variable "
         << std::resetiosflags(std::ios::right) 
         << " : " << fRankingDiscriminatorName << Endl;
   Log() << kINFO << hline << Endl;
   for (std::vector<Rank>::const_iterator ir = fRanking.begin(); ir != fRanking.end(); ir++ ) {
      Log() << kINFO 
            << Form( "%4i : ",(*ir).GetRank() )
            << std::setw(TMath::Max(maxL+0,9)) << (*ir).GetVariable().Data()
            << Form( " : %3.3e", (*ir).GetRankValue() ) << Endl;
   }
   Log() << kINFO << hline << Endl;
}

// ===============================================================================================

//_______________________________________________________________________
TMVA::Rank::Rank( const TString& variable, Double_t rankValue ) 
   : fVariable( variable ),
     fRankValue( rankValue ),
     fRank( -1 ) 
{
   // constructor
}

//_______________________________________________________________________
TMVA::Rank::~Rank() 
{
   // destructor
}

//_______________________________________________________________________
Bool_t TMVA::Rank::operator< ( const Rank& other ) const
{ 
   // comparison operator <
   if (fRankValue < other.fRankValue) return true;
   else                               return false;
}

//_______________________________________________________________________
Bool_t TMVA::Rank::operator> ( const Rank& other ) const
{ 
   // comparison operator >
   if (fRankValue > other.fRankValue) return true;
   else                               return false;
}
 Ranking.cxx:1
 Ranking.cxx:2
 Ranking.cxx:3
 Ranking.cxx:4
 Ranking.cxx:5
 Ranking.cxx:6
 Ranking.cxx:7
 Ranking.cxx:8
 Ranking.cxx:9
 Ranking.cxx:10
 Ranking.cxx:11
 Ranking.cxx:12
 Ranking.cxx:13
 Ranking.cxx:14
 Ranking.cxx:15
 Ranking.cxx:16
 Ranking.cxx:17
 Ranking.cxx:18
 Ranking.cxx:19
 Ranking.cxx:20
 Ranking.cxx:21
 Ranking.cxx:22
 Ranking.cxx:23
 Ranking.cxx:24
 Ranking.cxx:25
 Ranking.cxx:26
 Ranking.cxx:27
 Ranking.cxx:28
 Ranking.cxx:29
 Ranking.cxx:30
 Ranking.cxx:31
 Ranking.cxx:32
 Ranking.cxx:33
 Ranking.cxx:34
 Ranking.cxx:35
 Ranking.cxx:36
 Ranking.cxx:37
 Ranking.cxx:38
 Ranking.cxx:39
 Ranking.cxx:40
 Ranking.cxx:41
 Ranking.cxx:42
 Ranking.cxx:43
 Ranking.cxx:44
 Ranking.cxx:45
 Ranking.cxx:46
 Ranking.cxx:47
 Ranking.cxx:48
 Ranking.cxx:49
 Ranking.cxx:50
 Ranking.cxx:51
 Ranking.cxx:52
 Ranking.cxx:53
 Ranking.cxx:54
 Ranking.cxx:55
 Ranking.cxx:56
 Ranking.cxx:57
 Ranking.cxx:58
 Ranking.cxx:59
 Ranking.cxx:60
 Ranking.cxx:61
 Ranking.cxx:62
 Ranking.cxx:63
 Ranking.cxx:64
 Ranking.cxx:65
 Ranking.cxx:66
 Ranking.cxx:67
 Ranking.cxx:68
 Ranking.cxx:69
 Ranking.cxx:70
 Ranking.cxx:71
 Ranking.cxx:72
 Ranking.cxx:73
 Ranking.cxx:74
 Ranking.cxx:75
 Ranking.cxx:76
 Ranking.cxx:77
 Ranking.cxx:78
 Ranking.cxx:79
 Ranking.cxx:80
 Ranking.cxx:81
 Ranking.cxx:82
 Ranking.cxx:83
 Ranking.cxx:84
 Ranking.cxx:85
 Ranking.cxx:86
 Ranking.cxx:87
 Ranking.cxx:88
 Ranking.cxx:89
 Ranking.cxx:90
 Ranking.cxx:91
 Ranking.cxx:92
 Ranking.cxx:93
 Ranking.cxx:94
 Ranking.cxx:95
 Ranking.cxx:96
 Ranking.cxx:97
 Ranking.cxx:98
 Ranking.cxx:99
 Ranking.cxx:100
 Ranking.cxx:101
 Ranking.cxx:102
 Ranking.cxx:103
 Ranking.cxx:104
 Ranking.cxx:105
 Ranking.cxx:106
 Ranking.cxx:107
 Ranking.cxx:108
 Ranking.cxx:109
 Ranking.cxx:110
 Ranking.cxx:111
 Ranking.cxx:112
 Ranking.cxx:113
 Ranking.cxx:114
 Ranking.cxx:115
 Ranking.cxx:116
 Ranking.cxx:117
 Ranking.cxx:118
 Ranking.cxx:119
 Ranking.cxx:120
 Ranking.cxx:121
 Ranking.cxx:122
 Ranking.cxx:123
 Ranking.cxx:124
 Ranking.cxx:125
 Ranking.cxx:126
 Ranking.cxx:127
 Ranking.cxx:128
 Ranking.cxx:129
 Ranking.cxx:130
 Ranking.cxx:131
 Ranking.cxx:132
 Ranking.cxx:133
 Ranking.cxx:134
 Ranking.cxx:135
 Ranking.cxx:136
 Ranking.cxx:137
 Ranking.cxx:138
 Ranking.cxx:139
 Ranking.cxx:140
 Ranking.cxx:141
 Ranking.cxx:142
 Ranking.cxx:143
 Ranking.cxx:144
 Ranking.cxx:145
 Ranking.cxx:146
 Ranking.cxx:147
 Ranking.cxx:148
 Ranking.cxx:149
 Ranking.cxx:150
 Ranking.cxx:151
 Ranking.cxx:152
 Ranking.cxx:153
 Ranking.cxx:154
 Ranking.cxx:155
 Ranking.cxx:156
 Ranking.cxx:157
 Ranking.cxx:158
 Ranking.cxx:159
 Ranking.cxx:160