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 
93 namespace 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
TMVA::MethodCFMlpANN::Init
void Init(void)
default initialisation called by all constructors
Definition: MethodCFMlpANN.cxx:257
TMVA::MethodCFMlpANN::NN_ava
void NN_ava(Double_t *)
auxiliary functions
Definition: MethodCFMlpANN.cxx:377
TMVA::MethodCFMlpANN::fYNN
Double_t ** fYNN
Definition: MethodCFMlpANN.h:164
TMVA::MethodCFMlpANN::Train
void Train(void)
training of the Clement-Ferrand NN classifier
Definition: MethodCFMlpANN.cxx:285
TMVA::MethodCFMlpANN::MakeClassSpecific
void MakeClassSpecific(std::ostream &, const TString &) const
Definition: MethodCFMlpANN.cxx:691
TMVA::MethodCFMlpANN::ReadWeightsFromXML
void ReadWeightsFromXML(void *wghtnode)
read weights from xml file
Definition: MethodCFMlpANN.cxx:581
TMVA::MethodBase::ReadWeightsFromStream
virtual void ReadWeightsFromStream(std::istream &)=0
TMVA::Ranking
Ranking for variables in method (implementation)
Definition: Ranking.h:48
TMVA::MethodCFMlpANN::DataInterface
Int_t DataInterface(Double_t *, Double_t *, Int_t *, Int_t *, Int_t *, Int_t *, Double_t *, Int_t *, Int_t *)
data interface function
Definition: MethodCFMlpANN.cxx:506
TMVA::MethodCFMlpANN::fNodes
Int_t * fNodes
Definition: MethodCFMlpANN.h:161
MethodBase.h
TMVA::MethodCFMlpANN::ReadWeightsFromStream
virtual void ReadWeightsFromStream(std::istream &)=0
TMVA::MethodCFMlpANN::DeclareOptions
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: NCycles=xx :t...
Definition: MethodCFMlpANN.cxx:176
TMVA::MethodCFMlpANN::fLayerSpec
TString fLayerSpec
Definition: MethodCFMlpANN.h:165
TString
Basic string class.
Definition: TString.h:136
TMVA::MethodCFMlpANN::GetHelpMessage
void GetHelpMessage() const
get help message text
Definition: MethodCFMlpANN.cxx:711
TMatrixT
TMatrixT.
Definition: TMatrixT.h:39
TMVA::MethodCFMlpANN::HasAnalysisType
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t)
CFMlpANN can handle classification with 2 classes.
Definition: MethodCFMlpANN.cxx:165
TMVA::MethodCFMlpANN::NN_fonc
Double_t NN_fonc(Int_t, Double_t) const
activation function
Definition: MethodCFMlpANN.cxx:397
TMVA::MethodCFMlpANN::MethodCFMlpANN_nsel
Int_t MethodCFMlpANN_nsel
Definition: MethodCFMlpANN.h:166
TMVA::MethodCFMlpANN_Utils::o
Double_t o[max_nNodes_]
Definition: MethodCFMlpANN_Utils.h:168
TMVA::MethodCFMlpANN::EvalANN
Double_t EvalANN(std::vector< Double_t > &, Bool_t &isOK)
evaluates NN value as function of input variables
Definition: MethodCFMlpANN.cxx:343
bool
TMVA::MethodCFMlpANN::fClass
std::vector< Int_t > * fClass
Definition: MethodCFMlpANN.h:157
TMVA::MethodCFMlpANN::MakeClassSpecificHeader
void MakeClassSpecificHeader(std::ostream &, const TString &="") const
write specific classifier response for header
Definition: MethodCFMlpANN.cxx:701
TMVA::DataSetInfo
Class that contains all the data information.
Definition: DataSetInfo.h:62
TMVA::MethodCFMlpANN_Utils
Implementation of Clermond-Ferrand artificial neural network.
Definition: MethodCFMlpANN_Utils.h:54
TMVA::MethodCFMlpANN::CreateRanking
const Ranking * CreateRanking()
Definition: MethodCFMlpANN.h:131
TMVA::MethodCFMlpANN::PrintWeights
void PrintWeights(std::ostream &o) const
write the weights of the neural net
Definition: MethodCFMlpANN.cxx:630
TMVA::MethodCFMlpANN::AddWeightsXMLTo
void AddWeightsXMLTo(void *parent) const
write weights to xml file
Definition: MethodCFMlpANN.cxx:537
TMVA::Types::EAnalysisType
EAnalysisType
Definition: Types.h:128
MethodCFMlpANN_Utils.h
TMVA::MethodBase
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
TMVA::MethodCFMlpANN::fData
TMatrixF * fData
Definition: MethodCFMlpANN.h:156
unsigned int
TMVA::MethodCFMlpANN::fNcycles
Int_t fNcycles
Definition: MethodCFMlpANN.h:160
TMVA::MethodCFMlpANN::GetMvaValue
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns CFMlpANN output (normalised within [0,1])
Definition: MethodCFMlpANN.cxx:321
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MethodCFMlpANN::GetData
Double_t GetData(Int_t isel, Int_t ivar) const
Definition: MethodCFMlpANN.h:126
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::MethodCFMlpANN::GetClass
Int_t GetClass(Int_t ivar) const
Definition: MethodCFMlpANN.h:127
TMVA::MethodCFMlpANN
Interface to Clermond-Ferrand artificial neural network.
Definition: MethodCFMlpANN.h:95
type
int type
Definition: TGX11.cxx:121
TMVA::MethodCFMlpANN::ProcessOptions
void ProcessOptions()
decode the options in the option string
Definition: MethodCFMlpANN.cxx:185
TMVA::MethodCFMlpANN::~MethodCFMlpANN
virtual ~MethodCFMlpANN(void)
destructor
Definition: MethodCFMlpANN.cxx:269
TMatrixF.h
TMVA::MethodCFMlpANN::MethodCFMlpANN
MethodCFMlpANN(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="3000:N-1:N-2")
standard constructor
Definition: MethodCFMlpANN.cxx:130
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int
TMVA::MethodCFMlpANN::fNlayers
Int_t fNlayers
Definition: MethodCFMlpANN.h:159