ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MethodCFMlpANN.h
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 : MethodCFMlpANN *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Interface for Clermond-Ferrand artificial neural network. *
12  * The ANN code has been translated from FORTRAN77 (f2c); *
13  * see files: MethodCFMlpANN_f2c_mlpl3.cpp *
14  * MethodCFMlpANN_f2c_datacc.cpp *
15  * *
16  * -------------------------------------------------------------------- *
17  * Reference for the original FORTRAN version: *
18  * Authors : J. Proriol and contributions from ALEPH-Clermont-Fd *
19  * Team members. Contact : gaypas@afal11.cern.ch *
20  * *
21  * Copyright: Laboratoire Physique Corpusculaire *
22  * Universite de Blaise Pascal, IN2P3/CNRS *
23  * -------------------------------------------------------------------- *
24  * *
25  * Usage: options are given through Factory: *
26  * factory->BookMethod( "MethodCFMlpANN", OptionsString ); *
27  * *
28  * where: *
29  * TString OptionsString = "n_training_cycles:n_hidden_layers" *
30  * *
31  * default is: n_training_cycles = 5000, n_layers = 4 *
32  * note that the number of hidden layers in the NN is *
33  * *
34  * n_hidden_layers = n_layers - 2 *
35  * *
36  * since there is one input and one output layer. The number of *
37  * nodes (neurons) is predefined to be *
38  * *
39  * n_nodes[i] = nvars + 1 - i (where i=1..n_layers) *
40  * *
41  * with nvars being the number of variables used in the NN. *
42  * Hence, the default case is: n_neurons(layer 1 (input)) : nvars *
43  * n_neurons(layer 2 (hidden)): nvars-1 *
44  * n_neurons(layer 3 (hidden)): nvars-1 *
45  * n_neurons(layer 4 (out)) : 2 *
46  * *
47  * This artificial neural network usually needs a relatively large *
48  * number of cycles to converge (8000 and more). Overtraining can *
49  * be efficienctly tested by comparing the signal and background *
50  * output of the NN for the events that were used for training and *
51  * an independent data sample (with equal properties). If the separation *
52  * performance is significantly better for the training sample, the *
53  * NN interprets statistical effects, and is hence overtrained. In *
54  * this case, the number of cycles should be reduced, or the size *
55  * of the training sample increased. *
56  * *
57  * Authors (alphabetical): *
58  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
59  * Xavier Prudent <prudent@lapp.in2p3.fr> - LAPP, France *
60  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
61  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
62  * *
63  * Copyright (c) 2005: *
64  * CERN, Switzerland *
65  * U. of Victoria, Canada *
66  * MPI-K Heidelberg, Germany *
67  * LAPP, Annecy, France *
68  * *
69  * Redistribution and use in source and binary forms, with or without *
70  * modification, are permitted according to the terms listed in LICENSE *
71  * (http://tmva.sourceforge.net/LICENSE) *
72  * *
73  **********************************************************************************/
74 
75 #ifndef ROOT_TMVA_MethodCFMlpANN
76 #define ROOT_TMVA_MethodCFMlpANN
77 
78 //////////////////////////////////////////////////////////////////////////
79 // //
80 // MethodCFMlpANN //
81 // //
82 // Interface for Clermond-Ferrand artificial neural network //
83 // //
84 //////////////////////////////////////////////////////////////////////////
85 
86 #include <iosfwd>
87 
88 #ifndef ROOT_TMVA_MethodBase
89 #include "TMVA/MethodBase.h"
90 #endif
91 #ifndef ROOT_TMVA_MethodCFMlpANN_Utils
93 #endif
94 #ifndef ROOT_TMatrixF
95 #include "TMatrixF.h"
96 #endif
97 
98 namespace TMVA {
99 
101 
102  public:
103 
104  MethodCFMlpANN( const TString& jobName,
105  const TString& methodTitle,
106  DataSetInfo& theData,
107  const TString& theOption = "3000:N-1:N-2",
108  TDirectory* theTargetDir = 0 );
109 
110  MethodCFMlpANN( DataSetInfo& theData,
111  const TString& theWeightFile,
112  TDirectory* theTargetDir = NULL );
113 
114  virtual ~MethodCFMlpANN( void );
115 
116  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t /*numberTargets*/ );
117 
118  // training method
119  void Train( void );
120 
122 
123  // write weights to file
124  void AddWeightsXMLTo( void* parent ) const;
125 
126  // read weights from file
127  void ReadWeightsFromStream( std::istream& istr );
128  void ReadWeightsFromXML( void* wghtnode );
129  // calculate the MVA value
130  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
131 
132  // data accessors for external functions
133  Double_t GetData ( Int_t isel, Int_t ivar ) const { return (*fData)(isel, ivar); }
134  Int_t GetClass( Int_t ivar ) const { return (*fClass)[ivar]; }
135 
136  // static pointer to this object (required for external functions
137  static MethodCFMlpANN* This( void );
138 
139  // ranking of input variables
140  const Ranking* CreateRanking() { return 0; }
141 
142  protected:
143 
144  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
145  void MakeClassSpecific( std::ostream&, const TString& ) const;
146 
147  // header and auxiliary classes
148  void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const;
149 
150  // get help message text
151  void GetHelpMessage() const;
152 
154  Double_t*, Int_t*, Int_t* );
155 
156  private:
157 
158  void PrintWeights( std::ostream & o ) const;
159 
160  // the option handling methods
161  void DeclareOptions();
162  void ProcessOptions();
163 
164  static MethodCFMlpANN* fgThis; // this carrier
165 
166  // LUTs
167  TMatrixF *fData; // the (data,var) string
168  std::vector<Int_t> *fClass; // the event class (1=signal, 2=background)
169 
170  Int_t fNlayers; // number of layers (including input and output layers)
171  Int_t fNcycles; // number of training cycles
172  Int_t* fNodes; // number of nodes per layer
173 
174  // additional member variables for the independent NN::Evaluation phase
175  Double_t** fYNN; // weights
176  TString fLayerSpec; // the hidden layer specification string
177 
178  // auxiliary member functions
179  Double_t EvalANN( std::vector<Double_t>&, Bool_t& isOK );
180  void NN_ava ( Double_t* );
181  Double_t NN_fonc( Int_t, Double_t ) const;
182 
183  // default initialisation
184  void Init( void );
185 
186  ClassDef(MethodCFMlpANN,0) // Interface for Clermond-Ferrand artificial neural network
187  };
188 
189 } // namespace TMVA
190 
191 #endif
void Train(void)
training of the Clement-Ferrand NN classifier
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: NCycles=xx :t...
void NN_ava(Double_t *)
auxiliary functions
void ReadWeightsFromXML(void *wghtnode)
read weights from xml file
Int_t GetClass(Int_t ivar) const
static MethodCFMlpANN * fgThis
EAnalysisType
Definition: Types.h:124
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t DataInterface(Double_t *, Double_t *, Int_t *, Int_t *, Int_t *, Int_t *, Double_t *, Int_t *, Int_t *)
data interface function
virtual ~MethodCFMlpANN(void)
destructor
#define ClassDef(name, id)
Definition: Rtypes.h:254
std::vector< Int_t > * fClass
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t)
CFMlpANN can handle classification with 2 classes.
const Ranking * CreateRanking()
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns CFMlpANN output (normalised within [0,1])
MethodCFMlpANN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="3000:N-1:N-2", TDirectory *theTargetDir=0)
standard constructor option string: "n_training_cycles:n_hidden_layers" default is: n_training_cycles...
unsigned int UInt_t
Definition: RtypesCore.h:42
void MakeClassSpecificHeader(std::ostream &, const TString &="") const
write specific classifier response for header
void AddWeightsXMLTo(void *parent) const
write weights to xml file
Double_t EvalANN(std::vector< Double_t > &, Bool_t &isOK)
evaluates NN value as function of input variables
void GetHelpMessage() const
get help message text
void ReadWeightsFromStream(std::istream &istr)
read back the weight from the training from file (stream)
Double_t NN_fonc(Int_t, Double_t) const
activation function
double Double_t
Definition: RtypesCore.h:55
Describe directory structure in memory.
Definition: TDirectory.h:44
int type
Definition: TGX11.cxx:120
void Init(void)
default initialisation called by all constructors
void ProcessOptions()
decode the options in the option string
void MakeClassSpecific(std::ostream &, const TString &) const
#define NULL
Definition: Rtypes.h:82
void PrintWeights(std::ostream &o) const
write the weights of the neural net
virtual void ReadWeightsFromStream(std::istream &)=0
static MethodCFMlpANN * This(void)
static pointer to this object (required for external functions
Double_t GetData(Int_t isel, Int_t ivar) const