Logo ROOT  
Reference Guide
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 efficiently 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#include <vector>
88
89#include "TMVA/MethodBase.h"
91#include "TMatrixF.h"
92
93namespace TMVA {
94
96
97 public:
98
99 MethodCFMlpANN( const TString& jobName,
100 const TString& methodTitle,
101 DataSetInfo& theData,
102 const TString& theOption = "3000:N-1:N-2");
103
104 MethodCFMlpANN( DataSetInfo& theData,
105 const TString& theWeightFile);
106
107 virtual ~MethodCFMlpANN( void );
108
109 virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t /*numberTargets*/ );
110
111 // training method
112 void Train( void );
113
115
116 // write weights to file
117 void AddWeightsXMLTo( void* parent ) const;
118
119 // read weights from file
120 void ReadWeightsFromStream( std::istream& istr );
121 void ReadWeightsFromXML( void* wghtnode );
122 // calculate the MVA value
123 Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
124
125 // data accessors for external functions
126 Double_t GetData ( Int_t isel, Int_t ivar ) const { return (*fData)(isel, ivar); }
127 Int_t GetClass( Int_t ivar ) const { return (*fClass)[ivar]; }
128
129
130 // ranking of input variables
131 const Ranking* CreateRanking() { return 0; }
132
133 protected:
134
135 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
136 void MakeClassSpecific( std::ostream&, const TString& ) const;
137
138 // header and auxiliary classes
139 void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const;
140
141 // get help message text
142 void GetHelpMessage() const;
143
145 Double_t*, Int_t*, Int_t* );
146
147 private:
148
149 void PrintWeights( std::ostream & o ) const;
150
151 // the option handling methods
152 void DeclareOptions();
153 void ProcessOptions();
154
155 // LUTs
156 TMatrixF *fData; // the (data,var) string
157 std::vector<Int_t> *fClass; // the event class (1=signal, 2=background)
158
159 Int_t fNlayers; // number of layers (including input and output layers)
160 Int_t fNcycles; // number of training cycles
161 Int_t* fNodes; // number of nodes per layer
162
163 // additional member variables for the independent NN::Evaluation phase
164 Double_t** fYNN; // weights
165 TString fLayerSpec; // the hidden layer specification string
167
168 // auxiliary member functions
169 Double_t EvalANN( std::vector<Double_t>&, Bool_t& isOK );
170 void NN_ava ( Double_t* );
171 Double_t NN_fonc( Int_t, Double_t ) const;
172
173 // default initialisation
174 void Init( void );
175
176 ClassDef(MethodCFMlpANN,0); // Interface for Clermond-Ferrand artificial neural network
177 };
178
179} // namespace TMVA
180
181#endif
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:325
int type
Definition: TGX11.cxx:121
Class that contains all the data information.
Definition: DataSetInfo.h:62
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
virtual void ReadWeightsFromStream(std::istream &)=0
Implementation of Clermond-Ferrand artificial neural network.
Interface to Clermond-Ferrand artificial neural network.
const Ranking * CreateRanking()
void PrintWeights(std::ostream &o) const
write the weights of the neural net
void MakeClassSpecific(std::ostream &, const TString &) const
Double_t GetData(Int_t isel, Int_t ivar) const
Double_t EvalANN(std::vector< Double_t > &, Bool_t &isOK)
evaluates NN value as function of input variables
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns CFMlpANN output (normalised within [0,1])
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: NCycles=xx :t...
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t)
CFMlpANN can handle classification with 2 classes.
void NN_ava(Double_t *)
auxiliary functions
std::vector< Int_t > * fClass
void AddWeightsXMLTo(void *parent) const
write weights to xml file
void ProcessOptions()
decode the options in the option string
void Train(void)
training of the Clement-Ferrand NN classifier
Double_t NN_fonc(Int_t, Double_t) const
activation function
void ReadWeightsFromStream(std::istream &istr)
read back the weight from the training from file (stream)
void MakeClassSpecificHeader(std::ostream &, const TString &="") const
write specific classifier response for header
virtual ~MethodCFMlpANN(void)
destructor
MethodCFMlpANN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="3000:N-1:N-2")
standard constructor
void Init(void)
default initialisation called by all constructors
Int_t GetClass(Int_t ivar) const
Int_t DataInterface(Double_t *, Double_t *, Int_t *, Int_t *, Int_t *, Int_t *, Double_t *, Int_t *, Int_t *)
data interface function
void ReadWeightsFromXML(void *wghtnode)
read weights from xml file
void GetHelpMessage() const
get help message text
Ranking for variables in method (implementation)
Definition: Ranking.h:48
EAnalysisType
Definition: Types.h:128
TMatrixT.
Definition: TMatrixT.h:39
Basic string class.
Definition: TString.h:136
create variable transformations