ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TNeuron.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Matt Jachowski
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TMVA::TNeuron *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Neuron class to be used in MethodANNBase and its derivatives. *
12  * *
13  * Authors (alphabetical): *
14  * Matt Jachowski <jachowski@stanford.edu> - Stanford University, USA *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * *
19  * Redistribution and use in source and binary forms, with or without *
20  * modification, are permitted according to the terms listed in LICENSE *
21  * (http://tmva.sourceforge.net/LICENSE) *
22  **********************************************************************************/
23 
24 #ifndef ROOT_TMVA_TNeuron
25 #define ROOT_TMVA_TNeuron
26 
27 //////////////////////////////////////////////////////////////////////////
28 // //
29 // TNeuron //
30 // //
31 // Neuron used by derivatives of MethodANNBase //
32 // //
33 //////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 
37 #ifndef ROOT_TString
38 #include "TString.h"
39 #endif
40 #ifndef ROOT_TObjArray
41 #include "TObjArray.h"
42 #endif
43 #ifndef ROOT_TFormula
44 #include "TFormula.h"
45 #endif
46 
47 #ifndef ROOT_TMVA_TSynapse
48 #include "TMVA/TSynapse.h"
49 #endif
50 #ifndef ROOT_TMVA_TActivation
51 #include "TMVA/TActivation.h"
52 #endif
53 #ifndef ROOT_TMVA_Types
54 #include "TMVA/Types.h"
55 #endif
56 
57 namespace TMVA {
58 
59  class TNeuronInput;
60 
61  class TNeuron : public TObject {
62 
63  public:
64 
65  TNeuron();
66  virtual ~TNeuron();
67 
68  // force the input value
70 
71  // calculate the input value
72  void CalculateValue();
73 
74  // calculate the activation value
76 
77  // calculate the error field of the neuron
78  void CalculateDelta();
79 
80  // set the activation function
81  void SetActivationEqn(TActivation* activation);
82 
83  // set the input calculator
84  void SetInputCalculator(TNeuronInput* calculator);
85 
86  // add a synapse as a pre-link
87  void AddPreLink(TSynapse* pre);
88 
89  // add a synapse as a post-link
90  void AddPostLink(TSynapse* post);
91 
92  // delete all pre-links
94 
95  // set the error
96  void SetError(Double_t error);
97 
98  // update the error fields of all pre-synapses, batch mode
99  // to actually update the weights, call adjust synapse weights
102  // update the error fields and weights of all pre-synapses, sequential mode
105  // update the weights of the all pre-synapses, batch mode
106  //(call UpdateSynapsesBatch first)
109  // explicitly initialize error fields of pre-synapses, batch mode
111 
112  // print activation equation, for debugging
113  void PrintActivationEqn();
114 
115  // inlined functions
116  Double_t GetValue() const { return fValue; }
118  Double_t GetDelta() const { return fDelta; }
119  Double_t GetDEDw() const { return fDEDw; }
120  Int_t NumPreLinks() const { return NumLinks(fLinksIn); }
121  Int_t NumPostLinks() const { return NumLinks(fLinksOut); }
122  TSynapse* PreLinkAt ( Int_t index ) const { return (TSynapse*)fLinksIn->At(index); }
123  TSynapse* PostLinkAt( Int_t index ) const { return (TSynapse*)fLinksOut->At(index); }
127  void SetDEDw( Double_t DEDw ) { fDEDw = DEDw; }
128  Bool_t IsInputNeuron() const { return fLinksIn == NULL; }
129  Bool_t IsOutputNeuron() const { return fLinksOut == NULL; }
130  void PrintPreLinks() const { PrintLinks(fLinksIn); return; }
131  void PrintPostLinks() const { PrintLinks(fLinksOut); return; }
132 
133  virtual void Print(Option_t* = "") const {
134  std::cout << fValue << std::endl;
135  //PrintPreLinks(); PrintPostLinks();
136  }
137 
138  private:
139 
140  // prviate helper functions
141  void InitNeuron();
142  void DeleteLinksArray( TObjArray*& links );
143  void PrintLinks ( TObjArray* links ) const;
145 
146  // inlined helper functions
147  Int_t NumLinks(TObjArray* links) const {
148  if (links == NULL) return 0; return links->GetEntriesFast();
149  }
150  void NullifyLinks(TObjArray*& links) {
151  if (links != NULL) delete links; links = NULL;
152  }
153 
154  // private member variables
155  TObjArray* fLinksIn; // array of input synapses
156  TObjArray* fLinksOut; // array of output synapses
157  Double_t fValue; // input value
158  Double_t fActivationValue; // activation/output value
159  Double_t fDelta; // error field of neuron
160  Double_t fDEDw; // sum of all deltas
161  Double_t fError; // error, only set for output neurons
162  Bool_t fForcedValue; // flag for forced input value
163  TActivation* fActivation; // activation equation
164  TNeuronInput* fInputCalculator; // input calculator
165 
166  MsgLogger& Log() const;
167 
168  ClassDef(TNeuron,0) // Neuron class used by MethodANNBase derivative ANNs
169  };
170 
171 } // namespace TMVA
172 
173 #endif
Double_t GetDelta() const
Definition: TNeuron.h:118
An array of TObjects.
Definition: TObjArray.h:39
void SetDEDw(Double_t DEDw)
Definition: TNeuron.h:127
Bool_t fForcedValue
Definition: TNeuron.h:162
void ForceValue(Double_t value)
force the value, typically for input and bias neurons
Definition: TNeuron.cxx:87
const char Option_t
Definition: RtypesCore.h:62
Double_t GetValue() const
Definition: TNeuron.h:116
void PrintLinks(TObjArray *links) const
print an array of TSynapses, for debugging
Definition: TNeuron.cxx:308
void SetInputNeuron()
Definition: TNeuron.h:124
Basic string class.
Definition: TString.h:137
Double_t fError
Definition: TNeuron.h:161
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void PrintPostLinks() const
Definition: TNeuron.h:131
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
Bool_t IsOutputNeuron() const
Definition: TNeuron.h:129
void SetActivationEqn(TActivation *activation)
set activation equation
Definition: TNeuron.cxx:165
void InitSynapseDeltas()
initialize the error fields of all pre-neurons this method should only be called in batch mode ...
Definition: TNeuron.cxx:288
void NullifyLinks(TObjArray *&links)
Definition: TNeuron.h:150
void DeleteLinksArray(TObjArray *&links)
delete an array of TSynapses
Definition: TNeuron.cxx:200
virtual void Print(Option_t *="") const
This method must be overridden when a class wants to print itself.
Definition: TNeuron.h:133
void AdjustSynapseWeights()
adjust the pre-synapses' weights for each neuron (input neuron has no pre-synapse) this method should...
Definition: TNeuron.cxx:268
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t NumLinks(TObjArray *links) const
Definition: TNeuron.h:147
Double_t GetActivationValue() const
Definition: TNeuron.h:117
Int_t NumPostLinks() const
Definition: TNeuron.h:121
Double_t GetDEDw() const
Definition: TNeuron.h:119
Double_t fDEDw
Definition: TNeuron.h:160
Double_t fActivationValue
Definition: TNeuron.h:158
EMsgType
Definition: Types.h:61
void PrintActivationEqn()
print activation equation, for debugging
Definition: TNeuron.cxx:332
TObjArray * fLinksIn
Definition: TNeuron.h:155
void SetBiasNeuron()
Definition: TNeuron.h:126
Bool_t IsInputNeuron() const
Definition: TNeuron.h:128
void PrintPreLinks() const
Definition: TNeuron.h:130
TObjArray * fLinksOut
Definition: TNeuron.h:156
TActivation * fActivation
Definition: TNeuron.h:163
virtual ~TNeuron()
Definition: TNeuron.cxx:62
void SetError(Double_t error)
set error, this should only be done for an output neuron
Definition: TNeuron.cxx:217
double Double_t
Definition: RtypesCore.h:55
Double_t fDelta
Definition: TNeuron.h:159
void SetOutputNeuron()
Definition: TNeuron.h:125
void CalculateValue()
calculate neuron input
Definition: TNeuron.cxx:96
void PrintMessage(EMsgType, TString message)
print message, for debugging
Definition: TNeuron.cxx:341
void UpdateSynapsesSequential()
update the pre-synapses for each neuron (input neuron has no pre-synapse) this method should only be ...
Definition: TNeuron.cxx:247
void UpdateSynapsesBatch()
update and adjust the pre-synapses for each neuron (input neuron has no pre-synapse) this method shou...
Definition: TNeuron.cxx:229
Mother of all ROOT objects.
Definition: TObject.h:58
void CalculateActivationValue()
calculate neuron activation/output
Definition: TNeuron.cxx:105
void AddPostLink(TSynapse *post)
add synapse as a post-link to this neuron
Definition: TNeuron.cxx:183
MsgLogger & Log() const
Definition: TNeuron.cxx:348
#define NULL
Definition: Rtypes.h:82
TSynapse * PostLinkAt(Int_t index) const
Definition: TNeuron.h:123
Int_t NumPreLinks() const
Definition: TNeuron.h:120
Double_t fValue
Definition: TNeuron.h:157
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
string message
Definition: ROOT.py:94
void AddPreLink(TSynapse *pre)
add synapse as a pre-link to this neuron
Definition: TNeuron.cxx:174
void DeletePreLinks()
delete all pre-links
Definition: TNeuron.cxx:192
void CalculateDelta()
calculate error field
Definition: TNeuron.cxx:119
float value
Definition: math.cpp:443
void SetInputCalculator(TNeuronInput *calculator)
set input calculator
Definition: TNeuron.cxx:156
TNeuronInput * fInputCalculator
Definition: TNeuron.h:164
TSynapse * PreLinkAt(Int_t index) const
Definition: TNeuron.h:122
void InitNeuron()
Definition: TNeuron.cxx:69