Logo ROOT   6.16/01
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#include "TNamed.h"
16#include "TObjArray.h"
17
18class TTreeFormula;
19class TSynapse;
20class TBranch;
21class TTree;
22class TFormula;
23
24//____________________________________________________________________
25//
26// TNeuron
27//
28// This class decribes an elementary neuron, which is the basic
29// element for a Neural Network.
30// A network is build connecting neurons by synapses.
31// There are different types of neurons: linear (a+bx),
32// sigmoid (1/(1+exp(-x)), tanh or gaussian.
33// In a Multi Layer Perceptron, the input layer is made of
34// inactive neurons (returning the normalized input), hidden layers
35// are made of sigmoids and output neurons are linear.
36//
37// This implementation contains several methods to compute the value,
38// the derivative, the DeDw, ...
39// Values are stored in local buffers. The SetNewEvent() method is
40// there to inform buffered values are outdated.
41//
42//____________________________________________________________________
43
44class TNeuron : public TNamed {
45 friend class TSynapse;
46
47 public:
49
51 const char* name = "", const char* title = "",
52 const char* extF = "", const char* extD = "" );
53 virtual ~TNeuron() {}
54 inline TSynapse* GetPre(Int_t n) const { return (TSynapse*) fpre.At(n); }
55 inline TSynapse* GetPost(Int_t n) const { return (TSynapse*) fpost.At(n); }
56 inline TNeuron* GetInLayer(Int_t n) const { return (TNeuron*) flayer.At(n); }
57 TTreeFormula* UseBranch(TTree*, const char*);
58 Double_t GetInput() const;
59 Double_t GetValue() const;
60 Double_t GetDerivative() const;
61 Double_t GetError() const;
62 Double_t GetTarget() const;
63 Double_t GetDeDw() const;
64 Double_t GetBranch() const;
65 ENeuronType GetType() const;
66 void SetWeight(Double_t w);
67 inline Double_t GetWeight() const { return fWeight; }
69 inline const Double_t* GetNormalisation() const { return fNorm; }
70 void SetNewEvent() const;
71 void SetDEDw(Double_t in);
72 inline Double_t GetDEDw() const { return fDEDw; }
73 void ForceExternalValue(Double_t value);
74 void AddInLayer(TNeuron*);
75
76 protected:
79 void AddPre(TSynapse*);
80 void AddPost(TSynapse*);
81
82 private:
83 TNeuron(const TNeuron&); // Not implemented
84 TNeuron& operator=(const TNeuron&); // Not implemented
85
86 TObjArray fpre; // pointers to the previous level in a network
87 TObjArray fpost; // pointers to the next level in a network
88 TObjArray flayer; // pointers to the current level in a network (neurons, not synapses)
89 Double_t fWeight; // weight used for computation
90 Double_t fNorm[2]; // normalisation to mean=0, RMS=1.
91 ENeuronType fType; // neuron type
92 TFormula* fExtF; // function (external mode)
93 TFormula* fExtD; // derivative (external mode)
94 //buffers
95 //should be mutable when supported by all compilers
96 TTreeFormula* fFormula;//! formula to be used for inputs and outputs
97 Int_t fIndex; //! index in the formula
98 Bool_t fNewInput; //! do we need to compute fInput again ?
99 Double_t fInput; //! buffer containing the last neuron input
100 Bool_t fNewValue; //! do we need to compute fValue again ?
101 Double_t fValue; //! buffer containing the last neuron output
102 Bool_t fNewDeriv; //! do we need to compute fDerivative again ?
103 Double_t fDerivative; //! buffer containing the last neuron derivative
104 Bool_t fNewDeDw; //! do we need to compute fDeDw again ?
105 Double_t fDeDw; //! buffer containing the last derivative of the error
106 Double_t fDEDw; //! buffer containing the sum over all examples of DeDw
107
108 ClassDef(TNeuron, 4) // Neuron for MultiLayerPerceptrons
109};
110
111#endif
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassDef(name, id)
Definition: Rtypes.h:324
int type
Definition: TGX11.cxx:120
A TTree is a list of TBranches.
Definition: TBranch.h:64
The Formula class.
Definition: TFormula.h:84
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Double_t GetDerivative() const
computes the derivative for the appropriate function at the working point
Definition: TNeuron.cxx:1011
Double_t fWeight
Definition: TNeuron.h:89
TObjArray fpost
Definition: TNeuron.h:87
Double_t GetWeight() const
Definition: TNeuron.h:67
void SetWeight(Double_t w)
Sets the neuron weight to w.
Definition: TNeuron.cxx:1148
TNeuron(ENeuronType type=kSigmoid, const char *name="", const char *title="", const char *extF="", const char *extD="")
Usual constructor.
Definition: TNeuron.cxx:51
TObjArray flayer
Definition: TNeuron.h:88
TFormula * fExtD
Definition: TNeuron.h:93
Double_t fDerivative
do we need to compute fDerivative again ?
Definition: TNeuron.h:103
Bool_t fNewInput
index in the formula
Definition: TNeuron.h:98
TTreeFormula * fFormula
Definition: TNeuron.h:96
Double_t GetDEDw() const
Definition: TNeuron.h:72
Int_t fIndex
formula to be used for inputs and outputs
Definition: TNeuron.h:97
Double_t fDEDw
buffer containing the last derivative of the error
Definition: TNeuron.h:106
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
Double_t Sigmoid(Double_t x) const
The Sigmoid.
Definition: TNeuron.cxx:95
Double_t fDeDw
do we need to compute fDeDw again ?
Definition: TNeuron.h:105
void SetDEDw(Double_t in)
Sets the derivative of the total error wrt the neuron weight.
Definition: TNeuron.cxx:1168
Double_t GetDeDw() const
Computes the derivative of the error wrt the neuron weight.
Definition: TNeuron.cxx:1084
Double_t GetBranch() const
Returns the formula value.
Definition: TNeuron.cxx:914
TNeuron * GetInLayer(Int_t n) const
Definition: TNeuron.h:56
Double_t GetError() const
Computes the error for output neurons.
Definition: TNeuron.cxx:1063
Bool_t fNewValue
buffer containing the last neuron input
Definition: TNeuron.h:100
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
TTreeFormula * UseBranch(TTree *, const char *)
Sets a formula that can be used to make the neuron an input.
Definition: TNeuron.cxx:878
TSynapse * GetPre(Int_t n) const
Definition: TNeuron.h:54
Bool_t fNewDeriv
buffer containing the last neuron output
Definition: TNeuron.h:102
void ForceExternalValue(Double_t value)
Uses the branch type to force an external value.
Definition: TNeuron.cxx:1125
Double_t fInput
do we need to compute fInput again ?
Definition: TNeuron.h:99
TSynapse * GetPost(Int_t n) const
Definition: TNeuron.h:55
Double_t GetTarget() const
Computes the normalized target pattern for output neurons.
Definition: TNeuron.cxx:1074
Double_t fNorm[2]
Definition: TNeuron.h:90
Double_t GetInput() const
Returns neuron input.
Definition: TNeuron.cxx:925
virtual ~TNeuron()
Definition: TNeuron.h:53
const Double_t * GetNormalisation() const
Definition: TNeuron.h:69
Double_t DSigmoid(Double_t x) const
The Derivative of the Sigmoid.
Definition: TNeuron.cxx:818
ENeuronType fType
Definition: TNeuron.h:91
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
TNeuron & operator=(const TNeuron &)
TFormula * fExtF
Definition: TNeuron.h:92
ENeuronType GetType() const
Returns the neuron type.
Definition: TNeuron.cxx:867
Bool_t fNewDeDw
buffer containing the last neuron derivative
Definition: TNeuron.h:104
Double_t fValue
do we need to compute fValue again ?
Definition: TNeuron.h:101
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
void SetNormalisation(Double_t mean, Double_t RMS)
Sets the normalization variables.
Definition: TNeuron.cxx:1137
void AddInLayer(TNeuron *)
Tells a neuron which neurons form its layer (including itself).
Definition: TNeuron.cxx:857
ENeuronType
Definition: TNeuron.h:48
@ kLinear
Definition: TNeuron.h:48
@ kSigmoid
Definition: TNeuron.h:48
@ kExternal
Definition: TNeuron.h:48
@ kSoftmax
Definition: TNeuron.h:48
@ kGauss
Definition: TNeuron.h:48
@ kOff
Definition: TNeuron.h:48
@ kTanh
Definition: TNeuron.h:48
TObjArray fpre
Definition: TNeuron.h:86
An array of TObjects.
Definition: TObjArray.h:37
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
Used to pass a selection expression to the Tree drawing routine.
Definition: TTreeFormula.h:58
A TTree object has a header with a name and a title.
Definition: TTree.h:71
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Return the Standard Deviation of an array a with length n.
Definition: TMath.h:1155