// @(#)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  : MethodDT  (Boosted Decision Trees)                                   *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Analysis of Boosted Decision Trees                                        *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
 *      Or Cohen        <orcohenor@gmail.com>    - Weizmann Inst., Israel         *
 *                                                                                *
 * 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)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_MethodDT
#define ROOT_TMVA_MethodDT

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MethodDT                                                             //
//                                                                      //
// Analysis of Single Decision Tree                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <vector>
#ifndef ROOT_TH1
#include "TH1.h"
#endif
#ifndef ROOT_TH2
#include "TH2.h"
#endif
#ifndef ROOT_TTree
#include "TTree.h"
#endif
#ifndef ROOT_TMVA_MethodBase
#include "TMVA/MethodBase.h"
#endif
#ifndef ROOT_TMVA_DecisionTree
#include "TMVA/DecisionTree.h"
#endif
#ifndef ROOT_TMVA_Event
#include "TMVA/Event.h"
#endif

namespace TMVA {
   class MethodBoost;

   class MethodDT : public MethodBase {
   public:
      MethodDT( const TString& jobName, 
                const TString& methodTitle, 
                DataSetInfo& theData,
                const TString& theOption = "",
                TDirectory* theTargetDir = 0 );

      MethodDT( DataSetInfo& dsi, 
                const TString& theWeightFile,  
                TDirectory* theTargetDir = NULL );

      virtual ~MethodDT( void );

      virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );

      void Train( void );
      
      using MethodBase::ReadWeightsFromStream;

      // write weights to file
      void AddWeightsXMLTo( void* parent ) const;

      // read weights from file
      void ReadWeightsFromStream( std::istream& istr );
      void ReadWeightsFromXML   ( void* wghtnode );

      // calculate the MVA value
      Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );

      // the option handling methods
      void DeclareOptions();
      void ProcessOptions();
      void DeclareCompatibilityOptions();

      void GetHelpMessage() const;

      // ranking of input variables
      const Ranking* CreateRanking();

      Double_t PruneTree( );

      Double_t TestTreeQuality( DecisionTree *dt );

      Double_t GetPruneStrength () { return fPruneStrength; }

      void SetMinNodeSize(Double_t sizeInPercent);
      void SetMinNodeSize(TString sizeInPercent);

      Int_t GetNNodesBeforePruning(){return fTree->GetNNodesBeforePruning();}
      Int_t GetNNodes(){return fTree->GetNNodes();}

   private:
      // Init used in the various constructors
      void Init( void );

   private:


      std::vector<Event*>             fEventSample;     // the training events

      DecisionTree*                   fTree;            // the decision tree
      //options for the decision Tree
      SeparationBase                 *fSepType;         // the separation used in node splitting
      TString                         fSepTypeS;        // the separation (option string) used in node splitting
      Int_t                           fMinNodeEvents;   // min number of events in node
      Float_t                         fMinNodeSize;     // min percentage of training events in node
      TString                         fMinNodeSizeS;    // string containing min percentage of training events in node
  
      Int_t                           fNCuts;           // grid used in cut applied in node splitting
      Bool_t                          fUseYesNoLeaf;    // use sig or bkg classification in leave nodes or sig/bkg
      Double_t                        fNodePurityLimit; // purity limit for sig/bkg nodes
      UInt_t                          fMaxDepth;        // max depth


      Double_t                         fErrorFraction;   // ntuple var: misclassification error fraction 
      Double_t                         fPruneStrength;   // a parameter to set the "amount" of pruning..needs to be adjusted
      DecisionTree::EPruneMethod       fPruneMethod;     // method used for prunig 
      TString                          fPruneMethodS;    // prune method option String
      Bool_t                           fAutomatic;       // use user given prune strength or automatically determined one using a validation sample 
      Bool_t                           fRandomisedTrees; // choose a random subset of possible cut variables at each node during training
      Int_t                            fUseNvars;        // the number of variables used in the randomised tree splitting
      Bool_t                           fUsePoissonNvars; // fUseNvars is used as a poisson mean, and the actual value of useNvars is at each step drawn form that distribution
      std::vector<Double_t>           fVariableImportance; // the relative importance of the different variables 

      Double_t                        fDeltaPruneStrength; // step size in pruning, is adjusted according to experience of previous trees        
      // debugging flags
      static const Int_t  fgDebugLevel = 0;     // debug level determining some printout/control plots etc.


      Bool_t fPruneBeforeBoost; //aincient variable, only needed for "CompatibilityOptions" 

      ClassDef(MethodDT,0)  // Analysis of Decision Trees 

         };
}

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