TMVAClassification.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: TMVAClassification.cxx 37399 2010-12-08 15:22:07Z evt $
00002 /**********************************************************************************
00003  * Project   : TMVA - a ROOT-integrated toolkit for multivariate data analysis    *
00004  * Package   : TMVA                                                               *
00005  * Exectuable: TMVAClassification                                                 *
00006  *                                                                                *
00007  * This executable provides examples for the training and testing of the          *
00008  * TMVA classifiers.                                                              *
00009  *                                                                                *
00010  * As input data is used a toy-MC sample consisting of four Gaussian-distributed  *
00011  * and linearly correlated input variables.                                       *
00012  *                                                                                *
00013  * The methods to be used can be switched on and off by means of booleans.        *
00014  *                                                                                *
00015  * Compile and run the example with the following commands                        *
00016  *                                                                                *
00017  *    make                                                                        *
00018  *    ./TMVAClassification <Methods>                                              *
00019  *                                                                                *
00020  * where: <Methods> = "method1 method2"                                           *
00021  *        are the TMVA classifier names                                           *
00022  *                                                                                *
00023  * example:                                                                       *
00024  *    ./TMVAClassification Fisher LikelihoodPCA BDT                               *
00025  *                                                                                *
00026  * If no method given, a default set is of classifiers is used                    *
00027  *                                                                                *
00028  * The output file "TMVA.root" can be analysed with the use of dedicated          *
00029  * macros (simply say: root -l <../macros/macro.C>), which can be conveniently    *
00030  * invoked through a GUI launched by the command                                  *
00031  *                                                                                *
00032  *    root -l ./TMVAGui.C                                                         *
00033  **********************************************************************************/
00034 
00035 #include <cstdlib>
00036 #include <iostream>
00037 #include <map>
00038 #include <string>
00039 
00040 #include "TChain.h"
00041 #include "TFile.h"
00042 #include "TTree.h"
00043 #include "TString.h"
00044 #include "TObjString.h"
00045 #include "TSystem.h"
00046 #include "TROOT.h"
00047 
00048 #include "TMVA/Factory.h"
00049 #include "TMVA/Tools.h"
00050 
00051 // read input data file with ascii format (otherwise ROOT) ?
00052 Bool_t ReadDataFromAsciiIFormat = kFALSE;
00053 
00054 int main( int argc, char** argv )
00055 {
00056    //---------------------------------------------------------------
00057    // Default MVA methods to be trained + tested
00058    std::map<std::string,int> Use;
00059 
00060    // --- Cut optimisation
00061    Use["Cuts"]            = 1;
00062    Use["CutsD"]           = 1;
00063    Use["CutsPCA"]         = 0;
00064    Use["CutsGA"]          = 0;
00065    Use["CutsSA"]          = 0;
00066    // 
00067    // --- 1-dimensional likelihood ("naive Bayes estimator")
00068    Use["Likelihood"]      = 1;
00069    Use["LikelihoodD"]     = 0; // the "D" extension indicates decorrelated input variables (see option strings)
00070    Use["LikelihoodPCA"]   = 1; // the "PCA" extension indicates PCA-transformed input variables (see option strings)
00071    Use["LikelihoodKDE"]   = 0;
00072    Use["LikelihoodMIX"]   = 0;
00073    //
00074    // --- Mutidimensional likelihood and Nearest-Neighbour methods
00075    Use["PDERS"]           = 1;
00076    Use["PDERSD"]          = 0;
00077    Use["PDERSPCA"]        = 0;
00078    Use["PDEFoam"]         = 1;
00079    Use["PDEFoamBoost"]    = 0; // uses generalised MVA method boosting
00080    Use["KNN"]             = 1; // k-nearest neighbour method
00081    //
00082    // --- Linear Discriminant Analysis
00083    Use["LD"]              = 1; // Linear Discriminant identical to Fisher
00084    Use["Fisher"]          = 0;
00085    Use["FisherG"]         = 0;
00086    Use["BoostedFisher"]   = 0; // uses generalised MVA method boosting
00087    Use["HMatrix"]         = 0;
00088    //
00089    // --- Function Discriminant analysis
00090    Use["FDA_GA"]          = 1; // minimisation of user-defined function using Genetics Algorithm
00091    Use["FDA_SA"]          = 0;
00092    Use["FDA_MC"]          = 0;
00093    Use["FDA_MT"]          = 0;
00094    Use["FDA_GAMT"]        = 0;
00095    Use["FDA_MCMT"]        = 0;
00096    //
00097    // --- Neural Networks (all are feed-forward Multilayer Perceptrons)
00098    Use["MLP"]             = 0; // Recommended ANN
00099    Use["MLPBFGS"]         = 0; // Recommended ANN with optional training method
00100    Use["MLPBNN"]          = 1; // Recommended ANN with BFGS training method and bayesian regulator
00101    Use["CFMlpANN"]        = 0; // Depreciated ANN from ALEPH
00102    Use["TMlpANN"]         = 0; // ROOT's own ANN
00103    //
00104    // --- Support Vector Machine 
00105    Use["SVM"]             = 1;
00106    // 
00107    // --- Boosted Decision Trees
00108    Use["BDT"]             = 1; // uses Adaptive Boost
00109    Use["BDTG"]            = 0; // uses Gradient Boost
00110    Use["BDTB"]            = 0; // uses Bagging
00111    Use["BDTD"]            = 0; // decorrelation + Adaptive Boost
00112    // 
00113    // --- Friedman's RuleFit method, ie, an optimised series of cuts ("rules")
00114    Use["RuleFit"]         = 1;
00115    // ---------------------------------------------------------------
00116 
00117    std::cout << std::endl << "==> Start TMVAClassification" << std::endl;
00118 
00119    bool batchMode(false);
00120    bool useDefaultMethods(true);
00121 
00122    // Select methods (don't look at this code - not of interest)
00123    for (int i=1; i<argc; i++) {
00124       std::string regMethod(argv[i]);
00125       if(regMethod=="-b" || regMethod=="--batch") {
00126          batchMode=true;
00127          continue;
00128       }
00129       if (Use.find(regMethod) == Use.end()) {
00130          std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
00131          for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first << " ";
00132          std::cout << std::endl;
00133          return 1;
00134       }
00135       useDefaultMethods = false;
00136    }
00137 
00138    if (!useDefaultMethods) {
00139       for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
00140       for (int i=1; i<argc; i++) {
00141          std::string regMethod(argv[i]);
00142          if(regMethod=="-b" || regMethod=="--batch") continue;
00143          Use[regMethod] = 1;
00144       }
00145    }
00146 
00147    // --------------------------------------------------------------------------------------------------
00148 
00149    // --- Here the preparation phase begins
00150 
00151    // Create a ROOT output file where TMVA will store ntuples, histograms, etc.
00152    TString outfileName( "TMVA.root" );
00153    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
00154 
00155    // Create the factory object. Later you can choose the methods
00156    // whose performance you'd like to investigate. The factory is 
00157    // the only TMVA object you have to interact with
00158    //
00159    // The first argument is the base of the name of all the
00160    // weightfiles in the directory weight/
00161    //
00162    // The second argument is the output file for the training results
00163    // All TMVA output can be suppressed by removing the "!" (not) in
00164    // front of the "Silent" argument in the option string
00165    TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
00166                                                "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );
00167 
00168    // If you wish to modify default settings
00169    // (please check "src/Config.h" to see all available global options)
00170    //    (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
00171    //    (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";
00172 
00173    // Define the input variables that shall be used for the MVA training
00174    // note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
00175    // [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
00176    factory->AddVariable( "myvar1 := var1+var2", 'F' );
00177    factory->AddVariable( "myvar2 := var1-var2", "Expression 2", "", 'F' );
00178    factory->AddVariable( "var3",                "Variable 3", "units", 'F' );
00179    factory->AddVariable( "var4",                "Variable 4", "units", 'F' );
00180 
00181    // You can add so-called "Spectator variables", which are not used in the MVA training,
00182    // but will appear in the final "TestTree" produced by TMVA. This TestTree will contain the
00183    // input variables, the response values of all trained MVAs, and the spectator variables
00184    factory->AddSpectator( "spec1 := var1*2",  "Spectator 1", "units", 'F' );
00185    factory->AddSpectator( "spec2 := var1*3",  "Spectator 2", "units", 'F' );
00186 
00187    // Read training and test data
00188    // (it is also possible to use ASCII format as input -> see TMVA Users Guide)
00189    TString fname = "./tmva_class_example.root";
00190 
00191    if (gSystem->AccessPathName( fname ))  // file does not exist in local directory
00192       gSystem->Exec("wget http://root.cern.ch/files/tmva_class_example.root");
00193    
00194    TFile *input = TFile::Open( fname );
00195    
00196    std::cout << "--- TMVAClassification       : Using input file: " << input->GetName() << std::endl;
00197    
00198    // --- Register the training and test trees
00199 
00200    TTree *signal     = (TTree*)input->Get("TreeS");
00201    TTree *background = (TTree*)input->Get("TreeB");
00202    
00203    // global event weights per tree (see below for setting event-wise weights)
00204    Double_t signalWeight     = 1.0;
00205    Double_t backgroundWeight = 1.0;
00206    
00207    // You can add an arbitrary number of signal or background trees
00208    factory->AddSignalTree    ( signal,     signalWeight     );
00209    factory->AddBackgroundTree( background, backgroundWeight );
00210    
00211    // To give different trees for training and testing, do as follows:
00212    //    factory->AddSignalTree( signalTrainingTree, signalTrainWeight, "Training" );
00213    //    factory->AddSignalTree( signalTestTree,     signalTestWeight,  "Test" );
00214    
00215    // Use the following code instead of the above two or four lines to add signal and background
00216    // training and test events "by hand"
00217    // NOTE that in this case one should not give expressions (such as "var1+var2") in the input
00218    //      variable definition, but simply compute the expression before adding the event
00219    //
00220    //     // --- begin ----------------------------------------------------------
00221    //     std::vector<Double_t> vars( 4 ); // vector has size of number of input variables
00222    //     Float_t  treevars[4], weight;
00223    //     
00224    //     // Signal
00225    //     for (UInt_t ivar=0; ivar<4; ivar++) signal->SetBranchAddress( Form( "var%i", ivar+1 ), &(treevars[ivar]) );
00226    //     for (UInt_t i=0; i<signal->GetEntries(); i++) {
00227    //        signal->GetEntry(i);
00228    //        for (UInt_t ivar=0; ivar<4; ivar++) vars[ivar] = treevars[ivar];
00229    //        // add training and test events; here: first half is training, second is testing
00230    //        // note that the weight can also be event-wise
00231    //        if (i < signal->GetEntries()/2.0) factory->AddSignalTrainingEvent( vars, signalWeight );
00232    //        else                              factory->AddSignalTestEvent    ( vars, signalWeight );
00233    //     }
00234    //   
00235    //     // Background (has event weights)
00236    //     background->SetBranchAddress( "weight", &weight );
00237    //     for (UInt_t ivar=0; ivar<4; ivar++) background->SetBranchAddress( Form( "var%i", ivar+1 ), &(treevars[ivar]) );
00238    //     for (UInt_t i=0; i<background->GetEntries(); i++) {
00239    //        background->GetEntry(i);
00240    //        for (UInt_t ivar=0; ivar<4; ivar++) vars[ivar] = treevars[ivar];
00241    //        // add training and test events; here: first half is training, second is testing
00242    //        // note that the weight can also be event-wise
00243    //        if (i < background->GetEntries()/2) factory->AddBackgroundTrainingEvent( vars, backgroundWeight*weight );
00244    //        else                                factory->AddBackgroundTestEvent    ( vars, backgroundWeight*weight );
00245    //     }
00246          // --- end ------------------------------------------------------------
00247    //
00248    // --- end of tree registration 
00249 
00250    // Set individual event weights (the variables must exist in the original TTree)
00251    //    for signal    : factory->SetSignalWeightExpression    ("weight1*weight2");
00252    //    for background: factory->SetBackgroundWeightExpression("weight1*weight2");
00253    factory->SetBackgroundWeightExpression("weight");
00254 
00255    // Apply additional cuts on the signal and background samples (can be different)
00256    TCut mycuts = ""; // for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
00257    TCut mycutb = ""; // for example: TCut mycutb = "abs(var1)<0.5";
00258 
00259    // Tell the factory how to use the training and testing events
00260    //
00261    // If no numbers of events are given, half of the events in the tree are used 
00262    // for training, and the other half for testing:
00263    //    factory->PrepareTrainingAndTestTree( mycut, "SplitMode=random:!V" );
00264    // To also specify the number of testing events, use:
00265    //    factory->PrepareTrainingAndTestTree( mycut,
00266    //                                         "NSigTrain=3000:NBkgTrain=3000:NSigTest=3000:NBkgTest=3000:SplitMode=Random:!V" );
00267    factory->PrepareTrainingAndTestTree( mycuts, mycutb,
00268                                         "nTrain_Signal=0:nTrain_Background=0:SplitMode=Random:NormMode=NumEvents:!V" );
00269 
00270    // ---- Book MVA methods
00271    //
00272    // Please lookup the various method configuration options in the corresponding cxx files, eg:
00273    // src/MethoCuts.cxx, etc, or here: http://tmva.sourceforge.net/optionRef.html
00274    // it is possible to preset ranges in the option string in which the cut optimisation should be done:
00275    // "...:CutRangeMin[2]=-1:CutRangeMax[2]=1"...", where [2] is the third input variable
00276 
00277    // Cut optimisation
00278    if (Use["Cuts"])
00279       factory->BookMethod( TMVA::Types::kCuts, "Cuts",
00280                            "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart" );
00281 
00282    if (Use["CutsD"])
00283       factory->BookMethod( TMVA::Types::kCuts, "CutsD",
00284                            "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=Decorrelate" );
00285 
00286    if (Use["CutsPCA"])
00287       factory->BookMethod( TMVA::Types::kCuts, "CutsPCA",
00288                            "!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=PCA" );
00289 
00290    if (Use["CutsGA"])
00291       factory->BookMethod( TMVA::Types::kCuts, "CutsGA",
00292                            "H:!V:FitMethod=GA:CutRangeMin[0]=-10:CutRangeMax[0]=10:VarProp[1]=FMax:EffSel:Steps=30:Cycles=3:PopSize=400:SC_steps=10:SC_rate=5:SC_factor=0.95" );
00293 
00294    if (Use["CutsSA"])
00295       factory->BookMethod( TMVA::Types::kCuts, "CutsSA",
00296                            "!H:!V:FitMethod=SA:EffSel:MaxCalls=150000:KernelTemp=IncAdaptive:InitialTemp=1e+6:MinTemp=1e-6:Eps=1e-10:UseDefaultScale" );
00297 
00298    // Likelihood ("naive Bayes estimator")
00299    if (Use["Likelihood"])
00300       factory->BookMethod( TMVA::Types::kLikelihood, "Likelihood",
00301                            "H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmoothBkg[1]=10:NSmooth=1:NAvEvtPerBin=50" );
00302 
00303    // Decorrelated likelihood
00304    if (Use["LikelihoodD"])
00305       factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodD",
00306                            "!H:!V:TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmooth=5:NAvEvtPerBin=50:VarTransform=Decorrelate" );
00307 
00308    // PCA-transformed likelihood
00309    if (Use["LikelihoodPCA"])
00310       factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodPCA",
00311                            "!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmooth=5:NAvEvtPerBin=50:VarTransform=PCA" ); 
00312 
00313    // Use a kernel density estimator to approximate the PDFs
00314    if (Use["LikelihoodKDE"])
00315       factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodKDE",
00316                            "!H:!V:!TransformOutput:PDFInterpol=KDE:KDEtype=Gauss:KDEiter=Adaptive:KDEFineFactor=0.3:KDEborder=None:NAvEvtPerBin=50" ); 
00317 
00318    // Use a variable-dependent mix of splines and kernel density estimator
00319    if (Use["LikelihoodMIX"])
00320       factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodMIX",
00321                            "!H:!V:!TransformOutput:PDFInterpolSig[0]=KDE:PDFInterpolBkg[0]=KDE:PDFInterpolSig[1]=KDE:PDFInterpolBkg[1]=KDE:PDFInterpolSig[2]=Spline2:PDFInterpolBkg[2]=Spline2:PDFInterpolSig[3]=Spline2:PDFInterpolBkg[3]=Spline2:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" ); 
00322 
00323    // Test the multi-dimensional probability density estimator
00324    // here are the options strings for the MinMax and RMS methods, respectively:
00325    //      "!H:!V:VolumeRangeMode=MinMax:DeltaFrac=0.2:KernelEstimator=Gauss:GaussSigma=0.3" );
00326    //      "!H:!V:VolumeRangeMode=RMS:DeltaFrac=3:KernelEstimator=Gauss:GaussSigma=0.3" );
00327    if (Use["PDERS"])
00328       factory->BookMethod( TMVA::Types::kPDERS, "PDERS",
00329                            "!H:!V:NormTree=T:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600" );
00330 
00331    if (Use["PDERSD"])
00332       factory->BookMethod( TMVA::Types::kPDERS, "PDERSD",
00333                            "!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:VarTransform=Decorrelate" );
00334 
00335    if (Use["PDERSPCA"])
00336       factory->BookMethod( TMVA::Types::kPDERS, "PDERSPCA",
00337                            "!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:VarTransform=PCA" );
00338 
00339    // Multi-dimensional likelihood estimator using self-adapting phase-space binning
00340    if (Use["PDEFoam"])
00341       factory->BookMethod( TMVA::Types::kPDEFoam, "PDEFoam",
00342                            "H:!V:SigBgSeparate=F:TailCut=0.001:VolFrac=0.0333:nActiveCells=500:nSampl=2000:nBin=5:Nmin=100:Kernel=None:Compress=T" );
00343 
00344    if (Use["PDEFoamBoost"])
00345       factory->BookMethod( TMVA::Types::kPDEFoam, "PDEFoamBoost",
00346                            "!H:!V:Boost_Num=30:Boost_Transform=linear:SigBgSeparate=F:MaxDepth=4:UseYesNoCell=T:DTLogic=MisClassificationError:FillFoamWithOrigWeights=F:TailCut=0:nActiveCells=500:nBin=20:Nmin=400:Kernel=None:Compress=T" );
00347 
00348    // K-Nearest Neighbour classifier (KNN)
00349    if (Use["KNN"])
00350       factory->BookMethod( TMVA::Types::kKNN, "KNN",
00351                            "H:nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim" );
00352 
00353    // H-Matrix (chi2-squared) method
00354    if (Use["HMatrix"])
00355       factory->BookMethod( TMVA::Types::kHMatrix, "HMatrix", "!H:!V" );
00356 
00357    // Linear discriminant (same as Fisher discriminant)
00358    if (Use["LD"])
00359       factory->BookMethod( TMVA::Types::kLD, "LD", "H:!V:VarTransform=None:CreateMVAPdfs:PDFInterpolMVAPdf=Spline2:NbinsMVAPdf=50:NsmoothMVAPdf=10" );
00360 
00361    // Fisher discriminant (same as LD)
00362    if (Use["Fisher"])
00363       factory->BookMethod( TMVA::Types::kFisher, "Fisher", "H:!V:Fisher:CreateMVAPdfs:PDFInterpolMVAPdf=Spline2:NbinsMVAPdf=50:NsmoothMVAPdf=10" );
00364 
00365    // Fisher with Gauss-transformed input variables
00366    if (Use["FisherG"])
00367       factory->BookMethod( TMVA::Types::kFisher, "FisherG", "H:!V:VarTransform=Gauss" );
00368 
00369    // Composite classifier: ensemble (tree) of boosted Fisher classifiers
00370    if (Use["BoostedFisher"])
00371       factory->BookMethod( TMVA::Types::kFisher, "BoostedFisher", "H:!V:Boost_Num=20:Boost_Transform=log:Boost_Type=AdaBoost:Boost_AdaBoostBeta=0.2");
00372 
00373    // Function discrimination analysis (FDA) -- test of various fitters - the recommended one is Minuit (or GA or SA)
00374    if (Use["FDA_MC"])
00375       factory->BookMethod( TMVA::Types::kFDA, "FDA_MC",
00376                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:SampleSize=100000:Sigma=0.1" );
00377 
00378    if (Use["FDA_GA"]) // can also use Simulated Annealing (SA) algorithm (see Cuts_SA options])
00379       factory->BookMethod( TMVA::Types::kFDA, "FDA_GA",
00380                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:PopSize=300:Cycles=3:Steps=20:Trim=True:SaveBestGen=1" );
00381 
00382    if (Use["FDA_SA"]) // can also use Simulated Annealing (SA) algorithm (see Cuts_SA options])
00383       factory->BookMethod( TMVA::Types::kFDA, "FDA_SA",
00384                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=SA:MaxCalls=15000:KernelTemp=IncAdaptive:InitialTemp=1e+6:MinTemp=1e-6:Eps=1e-10:UseDefaultScale" );
00385 
00386    if (Use["FDA_MT"])
00387       factory->BookMethod( TMVA::Types::kFDA, "FDA_MT",
00388                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=2:UseImprove:UseMinos:SetBatch" );
00389 
00390    if (Use["FDA_GAMT"])
00391       factory->BookMethod( TMVA::Types::kFDA, "FDA_GAMT",
00392                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:Cycles=1:PopSize=5:Steps=5:Trim" );
00393 
00394    if (Use["FDA_MCMT"])
00395       factory->BookMethod( TMVA::Types::kFDA, "FDA_MCMT",
00396                            "H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:SampleSize=20" );
00397 
00398    // TMVA ANN: MLP (recommended ANN) -- all ANNs in TMVA are Multilayer Perceptrons
00399    if (Use["MLP"])
00400       factory->BookMethod( TMVA::Types::kMLP, "MLP", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:!UseRegulator" );
00401 
00402    if (Use["MLPBFGS"])
00403       factory->BookMethod( TMVA::Types::kMLP, "MLPBFGS", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:!UseRegulator" );
00404 
00405    if (Use["MLPBNN"])
00406       factory->BookMethod( TMVA::Types::kMLP, "MLPBNN", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:TrainingMethod=BFGS:UseRegulator" ); // BFGS training with bayesian regulators
00407 
00408    // CF(Clermont-Ferrand)ANN
00409    if (Use["CFMlpANN"])
00410       factory->BookMethod( TMVA::Types::kCFMlpANN, "CFMlpANN", "!H:!V:NCycles=2000:HiddenLayers=N+1,N"  ); // n_cycles:#nodes:#nodes:...  
00411 
00412    // Tmlp(Root)ANN
00413    if (Use["TMlpANN"])
00414       factory->BookMethod( TMVA::Types::kTMlpANN, "TMlpANN", "!H:!V:NCycles=200:HiddenLayers=N+1,N:LearningMethod=BFGS:ValidationFraction=0.3"  ); // n_cycles:#nodes:#nodes:...
00415 
00416    // Support Vector Machine
00417    if (Use["SVM"])
00418       factory->BookMethod( TMVA::Types::kSVM, "SVM", "Gamma=0.25:Tol=0.001:VarTransform=Norm" );
00419 
00420    // Boosted Decision Trees
00421    if (Use["BDTG"]) // Gradient Boost
00422       factory->BookMethod( TMVA::Types::kBDT, "BDTG",
00423                            "!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedGrad:GradBaggingFraction=0.5:nCuts=20:NNodesMax=5" );
00424 
00425    if (Use["BDT"])  // Adaptive Boost
00426       factory->BookMethod( TMVA::Types::kBDT, "BDT",
00427                            "!H:!V:NTrees=850:nEventsMin=150:MaxDepth=3:BoostType=AdaBoost:AdaBoostBeta=0.5:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
00428 
00429    if (Use["BDTB"]) // Bagging
00430       factory->BookMethod( TMVA::Types::kBDT, "BDTB",
00431                            "!H:!V:NTrees=400:BoostType=Bagging:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning" );
00432 
00433    if (Use["BDTD"]) // Decorrelation + Adaptive Boost
00434       factory->BookMethod( TMVA::Types::kBDT, "BDTD",
00435                            "!H:!V:NTrees=400:nEventsMin=400:MaxDepth=3:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=NoPruning:VarTransform=Decorrelate" );
00436 
00437    // RuleFit -- TMVA implementation of Friedman's method
00438    if (Use["RuleFit"])
00439       factory->BookMethod( TMVA::Types::kRuleFit, "RuleFit",
00440                            "H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.001:RuleMinDist=0.001:NTrees=20:fEventsMin=0.01:fEventsMax=0.5:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.01:GDNSteps=10000:GDErrScale=1.02" );
00441 
00442    // For an example of the category classifier, see: TMVAClassificationCategory
00443 
00444    // For an example of the category classifier usage, see: TMVAClassificationCategory
00445 
00446    // --------------------------------------------------------------------------------------------------
00447 
00448    // ---- Now you can optimize the setting (configuration) of the MVAs using the set of training events
00449 
00450    // factory->OptimizeAllMethods("SigEffAt001","Scan");
00451    // factory->OptimizeAllMethods("ROCIntegral","GA");
00452 
00453    // --------------------------------------------------------------------------------------------------
00454 
00455    // ---- Now you can tell the factory to train, test, and evaluate the MVAs
00456 
00457    // Train MVAs using the set of training events
00458    factory->TrainAllMethods();
00459 
00460    // ---- Evaluate all MVAs using the set of test events
00461    factory->TestAllMethods();
00462 
00463    // ----- Evaluate and compare performance of all configured MVAs
00464    factory->EvaluateAllMethods();
00465 
00466    // --------------------------------------------------------------
00467 
00468    // Save the output
00469    outputFile->Close();
00470 
00471    std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl
00472              << "==> TMVAClassification is done!" << std::endl
00473              << std::endl
00474              << "==> To view the results, launch the GUI: \"root -l ./TMVAGui.C\"" << std::endl
00475              << std::endl;
00476 
00477    // Clean up
00478    delete factory;
00479 }
00480 

Generated on Tue Jul 5 15:26:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1