MethodCFMlpANN.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: MethodCFMlpANN.h 36966 2010-11-26 09:50:13Z evt $    
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss 
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : MethodCFMlpANN                                                        *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Interface for Clermond-Ferrand artificial neural network.                 *
00012  *      The ANN code has been translated from FORTRAN77 (f2c);                    *
00013  *      see files: MethodCFMlpANN_f2c_mlpl3.cpp                                   *
00014  *                 MethodCFMlpANN_f2c_datacc.cpp                                  *
00015  *                                                                                *
00016  *      --------------------------------------------------------------------      *
00017  *      Reference for the original FORTRAN version:                               *
00018  *           Authors  : J. Proriol and contributions from ALEPH-Clermont-Fd       *
00019  *                      Team members. Contact : gaypas@afal11.cern.ch             *
00020  *                                                                                *
00021  *           Copyright: Laboratoire Physique Corpusculaire                        *
00022  *                      Universite de Blaise Pascal, IN2P3/CNRS                   *
00023  *      --------------------------------------------------------------------      *
00024  *                                                                                *
00025  * Usage: options are given through Factory:                                      *
00026  *            factory->BookMethod( "MethodCFMlpANN", OptionsString );             *
00027  *                                                                                *
00028  *        where:                                                                  *
00029  *            TString OptionsString = "n_training_cycles:n_hidden_layers"         *
00030  *                                                                                *
00031  *        default is:  n_training_cycles = 5000, n_layers = 4                     *
00032  *        note that the number of hidden layers in the NN is                      *
00033  *                                                                                *
00034  *            n_hidden_layers = n_layers - 2                                      *
00035  *                                                                                *
00036  *        since there is one input and one output layer. The number of            *
00037  *        nodes (neurons) is predefined to be                                     *
00038  *                                                                                *
00039  *           n_nodes[i] = nvars + 1 - i (where i=1..n_layers)                     *
00040  *                                                                                *
00041  *        with nvars being the number of variables used in the NN.                *
00042  *        Hence, the default case is: n_neurons(layer 1 (input)) : nvars          *
00043  *                                    n_neurons(layer 2 (hidden)): nvars-1        *
00044  *                                    n_neurons(layer 3 (hidden)): nvars-1        *
00045  *                                    n_neurons(layer 4 (out))   : 2              *
00046  *                                                                                *
00047  *        This artificial neural network usually needs a relatively large         *
00048  *        number of cycles to converge (8000 and more). Overtraining can          *
00049  *        be efficienctly tested by comparing the signal and background           *
00050  *        output of the NN for the events that were used for training and         *
00051  *        an independent data sample (with equal properties). If the separation   *
00052  *        performance is significantly better for the training sample, the        *
00053  *        NN interprets statistical effects, and is hence overtrained. In         * 
00054  *        this case, the number of cycles should be reduced, or the size          *
00055  *        of the training sample increased.                                       *
00056  *                                                                                *
00057  * Authors (alphabetical):                                                        *
00058  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00059  *      Xavier Prudent  <prudent@lapp.in2p3.fr>  - LAPP, France                   *
00060  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00061  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00062  *                                                                                *
00063  * Copyright (c) 2005:                                                            *
00064  *      CERN, Switzerland                                                         * 
00065  *      U. of Victoria, Canada                                                    * 
00066  *      MPI-K Heidelberg, Germany                                                 * 
00067  *      LAPP, Annecy, France                                                      *
00068  *                                                                                *
00069  * Redistribution and use in source and binary forms, with or without             *
00070  * modification, are permitted according to the terms listed in LICENSE           *
00071  * (http://tmva.sourceforge.net/LICENSE)                                          *
00072  *                                                                                *
00073  **********************************************************************************/
00074 
00075 #ifndef ROOT_TMVA_MethodCFMlpANN
00076 #define ROOT_TMVA_MethodCFMlpANN
00077 
00078 //////////////////////////////////////////////////////////////////////////
00079 //                                                                      //
00080 // MethodCFMlpANN                                                       //
00081 //                                                                      //
00082 // Interface for Clermond-Ferrand artificial neural network             //
00083 //                                                                      //
00084 //////////////////////////////////////////////////////////////////////////
00085 
00086 #include <iosfwd>
00087 
00088 #ifndef ROOT_TMVA_MethodBase
00089 #include "TMVA/MethodBase.h"
00090 #endif
00091 #ifndef ROOT_TMVA_MethodCFMlpANN_Utils
00092 #include "TMVA/MethodCFMlpANN_Utils.h"
00093 #endif
00094 #ifndef ROOT_TMVA_TMatrixFfwd
00095 #ifndef ROOT_TMatrixFfwd
00096 #include "TMatrixFfwd.h"
00097 #endif
00098 #endif
00099 
00100 namespace TMVA {
00101 
00102    class MethodCFMlpANN : public MethodBase, MethodCFMlpANN_Utils {
00103 
00104    public:
00105 
00106       MethodCFMlpANN( const TString& jobName,
00107                       const TString& methodTitle, 
00108                       DataSetInfo& theData,
00109                       const TString& theOption = "3000:N-1:N-2",
00110                       TDirectory* theTargetDir = 0 );
00111 
00112       MethodCFMlpANN( DataSetInfo& theData, 
00113                       const TString& theWeightFile,  
00114                       TDirectory* theTargetDir = NULL );
00115 
00116       virtual ~MethodCFMlpANN( void );
00117     
00118       virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t /*numberTargets*/ );
00119 
00120       // training method
00121       void Train( void );
00122 
00123       using MethodBase::ReadWeightsFromStream;
00124 
00125       // write weights to file
00126       void AddWeightsXMLTo( void* parent ) const;
00127 
00128       // read weights from file
00129       void ReadWeightsFromStream( istream& istr );
00130       void ReadWeightsFromXML( void* wghtnode );
00131       // calculate the MVA value
00132       Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
00133 
00134       // data accessors for external functions
00135       Double_t GetData ( Int_t isel, Int_t ivar ) const { return (*fData)(isel, ivar); }
00136       Int_t    GetClass( Int_t ivar             ) const { return (*fClass)[ivar]; }
00137 
00138       // static pointer to this object (required for external functions
00139       static MethodCFMlpANN* This( void );
00140 
00141       // ranking of input variables
00142       const Ranking* CreateRanking() { return 0; }
00143 
00144    protected:
00145 
00146       // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
00147       void MakeClassSpecific( std::ostream&, const TString& ) const;
00148 
00149       // header and auxiliary classes
00150       void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const;
00151 
00152       // get help message text
00153       void GetHelpMessage() const;
00154 
00155       Int_t DataInterface( Double_t*, Double_t*, Int_t*, Int_t*, Int_t*, Int_t*,
00156                            Double_t*, Int_t*, Int_t* );
00157   
00158    private:
00159 
00160       void PrintWeights( std::ostream & o ) const;
00161 
00162       // the option handling methods
00163       void DeclareOptions();
00164       void ProcessOptions();
00165       
00166       static MethodCFMlpANN* fgThis; // this carrier
00167 
00168       // LUTs
00169       TMatrixF       *fData;     // the (data,var) string
00170       std::vector<Int_t> *fClass;    // the event class (1=signal, 2=background)
00171 
00172       Int_t         fNlayers;   // number of layers (including input and output layers)
00173       Int_t         fNcycles;   // number of training cycles
00174       Int_t*        fNodes;     // number of nodes per layer
00175 
00176       // additional member variables for the independent NN::Evaluation phase
00177       Double_t**    fYNN;       // weights
00178       TString       fLayerSpec; // the hidden layer specification string
00179 
00180       // auxiliary member functions
00181       Double_t EvalANN( std::vector<Double_t>&, Bool_t& isOK );
00182       void     NN_ava ( Double_t* );
00183       Double_t NN_fonc( Int_t, Double_t ) const;
00184 
00185       // default initialisation 
00186       void Init( void );
00187 
00188       ClassDef(MethodCFMlpANN,0) // Interface for Clermond-Ferrand artificial neural network
00189    };
00190 
00191 } // namespace TMVA
00192 
00193 #endif

Generated on Tue Jul 5 14:27:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1