ROOT  6.06/09
Reference Guide
TNeuron.h
Go to the documentation of this file.
1 // @(#)root/mlp:$Id$
2 // Author: Christophe.Delaere@cern.ch 20/07/03
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TNeuron
13 #define ROOT_TNeuron
14 
15 #ifndef ROOT_TNamed
16 #include "TNamed.h"
17 #endif
18 #ifndef ROOT_TObjArray
19 #include "TObjArray.h"
20 #endif
21 
22 class TTreeFormula;
23 class TSynapse;
24 class TBranch;
25 class TTree;
26 class TFormula;
27 
28 //____________________________________________________________________
29 //
30 // TNeuron
31 //
32 // This class decribes an elementary neuron, which is the basic
33 // element for a Neural Network.
34 // A network is build connecting neurons by synapses.
35 // There are different types of neurons: linear (a+bx),
36 // sigmoid (1/(1+exp(-x)), tanh or gaussian.
37 // In a Multi Layer Perceptron, the input layer is made of
38 // inactive neurons (returning the normalized input), hidden layers
39 // are made of sigmoids and output neurons are linear.
40 //
41 // This implementation contains several methods to compute the value,
42 // the derivative, the DeDw, ...
43 // Values are stored in local buffers. The SetNewEvent() method is
44 // there to inform buffered values are outdated.
45 //
46 //____________________________________________________________________
47 
48 class TNeuron : public TNamed {
49  friend class TSynapse;
50 
51  public:
53 
55  const char* name = "", const char* title = "",
56  const char* extF = "", const char* extD = "" );
57  virtual ~TNeuron() {}
58  inline TSynapse* GetPre(Int_t n) const { return (TSynapse*) fpre.At(n); }
59  inline TSynapse* GetPost(Int_t n) const { return (TSynapse*) fpost.At(n); }
60  inline TNeuron* GetInLayer(Int_t n) const { return (TNeuron*) flayer.At(n); }
61  TTreeFormula* UseBranch(TTree*, const char*);
62  Double_t GetInput() const;
63  Double_t GetValue() const;
64  Double_t GetDerivative() const;
65  Double_t GetError() const;
66  Double_t GetTarget() const;
67  Double_t GetDeDw() const;
68  Double_t GetBranch() const;
69  ENeuronType GetType() const;
70  void SetWeight(Double_t w);
71  inline Double_t GetWeight() const { return fWeight; }
73  inline const Double_t* GetNormalisation() const { return fNorm; }
74  void SetNewEvent() const;
75  void SetDEDw(Double_t in);
76  inline Double_t GetDEDw() const { return fDEDw; }
78  void AddInLayer(TNeuron*);
79 
80  protected:
81  Double_t Sigmoid(Double_t x) const;
82  Double_t DSigmoid(Double_t x) const;
83  void AddPre(TSynapse*);
84  void AddPost(TSynapse*);
85 
86  private:
87  TNeuron(const TNeuron&); // Not implemented
88  TNeuron& operator=(const TNeuron&); // Not implemented
89 
90  TObjArray fpre; // pointers to the previous level in a network
91  TObjArray fpost; // pointers to the next level in a network
92  TObjArray flayer; // pointers to the current level in a network (neurons, not synapses)
93  Double_t fWeight; // weight used for computation
94  Double_t fNorm[2]; // normalisation to mean=0, RMS=1.
95  ENeuronType fType; // neuron type
96  TFormula* fExtF; // function (external mode)
97  TFormula* fExtD; // derivative (external mode)
98  //buffers
99  //should be mutable when supported by all compilers
100  TTreeFormula* fFormula;//! formula to be used for inputs and outputs
101  Int_t fIndex; //! index in the formula
102  Bool_t fNewInput; //! do we need to compute fInput again ?
103  Double_t fInput; //! buffer containing the last neuron input
104  Bool_t fNewValue; //! do we need to compute fValue again ?
105  Double_t fValue; //! buffer containing the last neuron output
106  Bool_t fNewDeriv; //! do we need to compute fDerivative again ?
107  Double_t fDerivative; //! buffer containing the last neuron derivative
108  Bool_t fNewDeDw; //! do we need to compute fDeDw again ?
109  Double_t fDeDw; //! buffer containing the last derivative of the error
110  Double_t fDEDw; //! buffer containing the sum over all examples of DeDw
111 
112  ClassDef(TNeuron, 4) // Neuron for MultiLayerPerceptrons
113 };
114 
115 #endif
An array of TObjects.
Definition: TObjArray.h:39
void ForceExternalValue(Double_t value)
Uses the branch type to force an external value.
Definition: TNeuron.cxx:1125
TObjArray flayer
Definition: TNeuron.h:92
TNeuron * GetInLayer(Int_t n) const
Definition: TNeuron.h:60
ENeuronType
Definition: TNeuron.h:52
Double_t GetError() const
Computes the error for output neurons.
Definition: TNeuron.cxx:1063
Bool_t fNewDeDw
buffer containing the last neuron derivative
Definition: TNeuron.h:108
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t DSigmoid(Double_t x) const
The Derivative of the Sigmoid.
Definition: TNeuron.cxx:818
TFormula * fExtD
Definition: TNeuron.h:97
void AddPre(TSynapse *)
Adds a synapse to the neuron as an input This method is used by the TSynapse while connecting two neu...
Definition: TNeuron.cxx:834
Double_t GetTarget() const
Computes the normalized target pattern for output neurons.
Definition: TNeuron.cxx:1074
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:916
Double_t x[n]
Definition: legend1.C:17
TSynapse * GetPre(Int_t n) const
Definition: TNeuron.h:58
#define ClassDef(name, id)
Definition: Rtypes.h:254
Double_t fDerivative
do we need to compute fDerivative again ?
Definition: TNeuron.h:107
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
const Double_t * GetNormalisation() const
Definition: TNeuron.h:73
TTreeFormula * UseBranch(TTree *, const char *)
Sets a formula that can be used to make the neuron an input.
Definition: TNeuron.cxx:878
TObjArray fpost
Definition: TNeuron.h:91
Double_t GetWeight() const
Definition: TNeuron.h:71
Double_t GetDeDw() const
Computes the derivative of the error wrt the neuron weight.
Definition: TNeuron.cxx:1084
Double_t fWeight
Definition: TNeuron.h:93
Double_t GetInput() const
Returns neuron input.
Definition: TNeuron.cxx:925
Bool_t fNewDeriv
buffer containing the last neuron output
Definition: TNeuron.h:106
void SetWeight(Double_t w)
Sets the neuron weight to w.
Definition: TNeuron.cxx:1148
Used to pass a selection expression to the Tree drawing routine.
Definition: TTreeFormula.h:64
Double_t GetBranch() const
Returns the formula value.
Definition: TNeuron.cxx:914
Double_t fDEDw
buffer containing the last derivative of the error
Definition: TNeuron.h:110
Double_t fValue
do we need to compute fValue again ?
Definition: TNeuron.h:105
Double_t fInput
do we need to compute fInput again ?
Definition: TNeuron.h:103
void AddInLayer(TNeuron *)
Tells a neuron which neurons form its layer (including itself).
Definition: TNeuron.cxx:857
void SetNormalisation(Double_t mean, Double_t RMS)
Sets the normalization variables.
Definition: TNeuron.cxx:1137
TNeuron & operator=(const TNeuron &)
Double_t Sigmoid(Double_t x) const
The Sigmoid.
Definition: TNeuron.cxx:95
The F O R M U L A class.
Definition: TFormula.h:89
TSynapse * GetPost(Int_t n) const
Definition: TNeuron.h:59
TTreeFormula * fFormula
Definition: TNeuron.h:100
Double_t GetDEDw() const
Definition: TNeuron.h:76
void SetDEDw(Double_t in)
Sets the derivative of the total error wrt the neuron weight.
Definition: TNeuron.cxx:1168
TNeuron(ENeuronType type=kSigmoid, const char *name="", const char *title="", const char *extF="", const char *extD="")
Bool_t fNewValue
buffer containing the last neuron input
Definition: TNeuron.h:104
double Double_t
Definition: RtypesCore.h:55
ENeuronType fType
Definition: TNeuron.h:95
int type
Definition: TGX11.cxx:120
Int_t fIndex
formula to be used for inputs and outputs
Definition: TNeuron.h:101
Double_t GetValue() const
Computes the output using the appropriate function and all the weighted inputs, or uses the branch as...
Definition: TNeuron.cxx:948
TObjArray fpre
Definition: TNeuron.h:90
#define name(a, b)
Definition: linkTestLib0.cpp:5
Bool_t fNewInput
index in the formula
Definition: TNeuron.h:102
Double_t fDeDw
do we need to compute fDeDw again ?
Definition: TNeuron.h:109
TFormula * fExtF
Definition: TNeuron.h:96
void AddPost(TSynapse *)
Adds a synapse to the neuron as an output This method is used by the TSynapse while connecting two ne...
Definition: TNeuron.cxx:846
A TTree object has a header with a name and a title.
Definition: TTree.h:94
void SetNewEvent() const
Inform the neuron that inputs of the network have changed, so that the buffered values have to be rec...
Definition: TNeuron.cxx:1157
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
Double_t fNorm[2]
Definition: TNeuron.h:94
A TTree is a list of TBranches.
Definition: TBranch.h:58
Double_t GetDerivative() const
computes the derivative for the appropriate function at the working point
Definition: TNeuron.cxx:1011
virtual ~TNeuron()
Definition: TNeuron.h:57
float value
Definition: math.cpp:443
ENeuronType GetType() const
Returns the neuron type.
Definition: TNeuron.cxx:867