12 #ifndef ROOT_TMultiLayerPerceptron
13 #define ROOT_TMultiLayerPerceptron
24 class TTreeFormulaManager;
26 class TMultiLayerPerceptron :
public TObject {
27 friend class TMLPAnalyzer;
30 enum ELearningMethod { kStochastic, kBatch, kSteepestDescent,
31 kRibierePolak, kFletcherReeves, kBFGS };
32 enum EDataSet { kTraining, kTest };
33 TMultiLayerPerceptron();
34 TMultiLayerPerceptron(
const char* layout, TTree* data = 0,
35 const char* training =
"Entry$%2==0",
36 const char* test =
"",
37 TNeuron::ENeuronType type = TNeuron::kSigmoid,
38 const char* extF =
"",
const char* extD =
"");
39 TMultiLayerPerceptron(
const char* layout,
40 const char* weight, TTree* data = 0,
41 const char* training =
"Entry$%2==0",
42 const char* test =
"",
43 TNeuron::ENeuronType type = TNeuron::kSigmoid,
44 const char* extF =
"",
const char* extD =
"");
45 TMultiLayerPerceptron(
const char* layout, TTree* data,
48 TNeuron::ENeuronType type = TNeuron::kSigmoid,
49 const char* extF =
"",
const char* extD =
"");
50 TMultiLayerPerceptron(
const char* layout,
51 const char* weight, TTree* data,
54 TNeuron::ENeuronType type = TNeuron::kSigmoid,
55 const char* extF =
"",
const char* extD =
"");
56 virtual ~TMultiLayerPerceptron();
58 void SetTrainingDataSet(TEventList* train);
59 void SetTestDataSet(TEventList* test);
60 void SetTrainingDataSet(
const char* train);
61 void SetTestDataSet(
const char* test);
62 void SetLearningMethod(TMultiLayerPerceptron::ELearningMethod method);
63 void SetEventWeight(
const char*);
64 void Train(Int_t nEpoch, Option_t* option =
"text", Double_t minE=0);
65 Double_t Result(Int_t event, Int_t index = 0)
const;
66 Double_t GetError(Int_t event)
const;
67 Double_t GetError(TMultiLayerPerceptron::EDataSet set)
const;
68 void ComputeDEDw()
const;
69 void Randomize()
const;
70 void SetEta(Double_t eta);
71 void SetEpsilon(Double_t eps);
72 void SetDelta(Double_t delta);
73 void SetEtaDecay(Double_t ed);
74 void SetTau(Double_t tau);
75 void SetReset(Int_t reset);
76 inline Double_t GetEta()
const {
return fEta; }
77 inline Double_t GetEpsilon()
const {
return fEpsilon; }
78 inline Double_t GetDelta()
const {
return fDelta; }
79 inline Double_t GetEtaDecay()
const {
return fEtaDecay; }
80 TMultiLayerPerceptron::ELearningMethod GetLearningMethod()
const {
return fLearningMethod; }
81 inline Double_t GetTau()
const {
return fTau; }
82 inline Int_t GetReset()
const {
return fReset; }
83 inline TString GetStructure()
const {
return fStructure; }
84 inline TNeuron::ENeuronType GetType()
const {
return fType; }
85 void DrawResult(Int_t index = 0, Option_t* option =
"test")
const;
86 Bool_t DumpWeights(Option_t* filename =
"-")
const;
87 Bool_t LoadWeights(Option_t* filename =
"");
88 Double_t Evaluate(Int_t index, Double_t* params)
const;
89 void Export(Option_t* filename =
"NNfunction", Option_t* language =
"C++")
const;
90 virtual void Draw(Option_t *option=
"");
95 void GetEntry(Int_t)
const;
97 void MLP_Stochastic(Double_t*);
98 void MLP_Batch(Double_t*);
99 Bool_t LineSearch(Double_t*, Double_t*);
100 void SteepestDir(Double_t*);
101 void ConjugateGradientsDir(Double_t*, Double_t);
102 void SetGammaDelta(TMatrixD&, TMatrixD&, Double_t*);
103 bool GetBFGSH(TMatrixD&, TMatrixD &, TMatrixD&);
104 void BFGSDir(TMatrixD&, Double_t*);
105 Double_t DerivDir(Double_t*);
106 Double_t GetCrossEntropyBinary()
const;
107 Double_t GetCrossEntropy()
const;
108 Double_t GetSumSquareError()
const;
111 TMultiLayerPerceptron(
const TMultiLayerPerceptron&);
112 TMultiLayerPerceptron& operator=(
const TMultiLayerPerceptron&);
113 void ExpandStructure();
114 void BuildFirstLayer(TString&);
115 void BuildHiddenLayers(TString&);
116 void BuildOneHiddenLayer(
const TString& sNumNodes, Int_t& layer,
117 Int_t& prevStart, Int_t& prevStop,
119 void BuildLastLayer(TString&, Int_t);
120 void Shuffle(Int_t*, Int_t)
const;
121 void MLP_Line(Double_t*, Double_t*, Double_t);
125 Double_t fCurrentTreeWeight;
127 TObjArray fFirstLayer;
128 TObjArray fLastLayer;
132 TNeuron::ENeuronType fType;
133 TNeuron::ENeuronType fOutType;
136 TEventList *fTraining;
138 ELearningMethod fLearningMethod;
139 TTreeFormula* fEventWeight;
140 TTreeFormulaManager* fManager;
148 Bool_t fTrainingOwner;
151 ClassDef(TMultiLayerPerceptron, 4)