Logo ROOT  
Reference Guide
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 #include "TString.h"
38 #include "TObjArray.h"
39 #include "TFormula.h"
40 
41 #include "TMVA/TSynapse.h"
42 #include "TMVA/TActivation.h"
43 #include "TMVA/Types.h"
44 
45 namespace TMVA {
46 
47  class TNeuronInput;
48 
49  class TNeuron : public TObject {
50 
51  public:
52 
54  virtual ~TNeuron();
55 
56  // force the input value
57  void ForceValue(Double_t value);
58 
59  // calculate the input value
60  void CalculateValue();
61 
62  // calculate the activation value
64 
65  // calculate the error field of the neuron
66  void CalculateDelta();
67 
68  // set the activation function
69  void SetActivationEqn(TActivation* activation);
70 
71  // set the input calculator
72  void SetInputCalculator(TNeuronInput* calculator);
73 
74  // add a synapse as a pre-link
75  void AddPreLink(TSynapse* pre);
76 
77  // add a synapse as a post-link
78  void AddPostLink(TSynapse* post);
79 
80  // delete all pre-links
82 
83  // set the error
84  void SetError(Double_t error);
85 
86  // update the error fields of all pre-synapses, batch mode
87  // to actually update the weights, call adjust synapse weights
88  void UpdateSynapsesBatch();
89 
90  // update the error fields and weights of all pre-synapses, sequential mode
92 
93  // update the weights of the all pre-synapses, batch mode
94  //(call UpdateSynapsesBatch first)
95  void AdjustSynapseWeights();
96 
97  // explicitly initialize error fields of pre-synapses, batch mode
98  void InitSynapseDeltas();
99 
100  // print activation equation, for debugging
101  void PrintActivationEqn();
102 
103  // inlined functions
104  Double_t GetValue() const { return fValue; }
106  Double_t GetDelta() const { return fDelta; }
107  Double_t GetDEDw() const { return fDEDw; }
108  Int_t NumPreLinks() const { return NumLinks(fLinksIn); }
109  Int_t NumPostLinks() const { return NumLinks(fLinksOut); }
110  TSynapse* PreLinkAt ( Int_t index ) const { return (TSynapse*)fLinksIn->At(index); }
111  TSynapse* PostLinkAt( Int_t index ) const { return (TSynapse*)fLinksOut->At(index); }
115  void SetDEDw( Double_t DEDw ) { fDEDw = DEDw; }
116  Bool_t IsInputNeuron() const { return fLinksIn == NULL; }
117  Bool_t IsOutputNeuron() const { return fLinksOut == NULL; }
118  void PrintPreLinks() const { PrintLinks(fLinksIn); return; }
119  void PrintPostLinks() const { PrintLinks(fLinksOut); return; }
120 
121  virtual void Print(Option_t* = "") const {
122  std::cout << fValue << std::endl;
123  //PrintPreLinks(); PrintPostLinks();
124  }
125 
126  private:
127 
128  // private helper functions
129  void InitNeuron();
130  void DeleteLinksArray( TObjArray*& links );
131  void PrintLinks ( TObjArray* links ) const;
132  void PrintMessage ( EMsgType, TString message );
133 
134  // inlined helper functions
135  Int_t NumLinks(TObjArray* links) const {
136  if (links == nullptr) return 0;
137  else return links->GetEntriesFast();
138  }
139  void NullifyLinks(TObjArray*& links) {
140  if (links != nullptr) { delete links; links = nullptr; }
141  }
142 
143  // private member variables
144  TObjArray* fLinksIn; // array of input synapses
145  TObjArray* fLinksOut; // array of output synapses
146  Double_t fValue; // input value
147  Double_t fActivationValue; // activation/output value
148  Double_t fDelta; // error field of neuron
149  Double_t fDEDw; // sum of all deltas
150  Double_t fError; // error, only set for output neurons
151  Bool_t fForcedValue; // flag for forced input value
152  TActivation* fActivation; // activation equation
153  TNeuronInput* fInputCalculator; // input calculator
154 
155  MsgLogger& Log() const;
156 
157  ClassDef(TNeuron,0); // Neuron class used by MethodANNBase derivative ANNs
158  };
159 
160 } // namespace TMVA
161 
162 #endif
TMVA::TNeuron::fLinksOut
TObjArray * fLinksOut
Definition: TNeuron.h:145
TMVA::TNeuron::fActivationValue
Double_t fActivationValue
Definition: TNeuron.h:147
TMVA::TNeuron::PrintPostLinks
void PrintPostLinks() const
Definition: TNeuron.h:119
TMVA::TNeuron::InitNeuron
void InitNeuron()
initialize the neuron, most variables still need to be set via setters
Definition: TNeuron.cxx:67
TMVA::TNeuron::fActivation
TActivation * fActivation
Definition: TNeuron.h:152
TMVA::TNeuron::AddPreLink
void AddPreLink(TSynapse *pre)
add synapse as a pre-link to this neuron
Definition: TNeuron.cxx:169
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMVA::TNeuron::PrintPreLinks
void PrintPreLinks() const
Definition: TNeuron.h:118
TMVA::TNeuron::fError
Double_t fError
Definition: TNeuron.h:150
TMVA::TNeuron::UpdateSynapsesSequential
void UpdateSynapsesSequential()
update the pre-synapses for each neuron (input neuron has no pre-synapse) this method should only be ...
Definition: TNeuron.cxx:242
TMVA::TNeuron::CalculateDelta
void CalculateDelta()
calculate error field
Definition: TNeuron.cxx:115
TMVA::TNeuron::GetDelta
Double_t GetDelta() const
Definition: TNeuron.h:106
TMVA::TNeuron::IsOutputNeuron
Bool_t IsOutputNeuron() const
Definition: TNeuron.h:117
TMVA::TNeuron::AddPostLink
void AddPostLink(TSynapse *post)
add synapse as a post-link to this neuron
Definition: TNeuron.cxx:178
TMVA::TNeuronInput
Interface for TNeuron input calculation classes.
Definition: TNeuronInput.h:42
TMVA::TNeuron::fForcedValue
Bool_t fForcedValue
Definition: TNeuron.h:151
TMVA::TNeuron::SetInputNeuron
void SetInputNeuron()
Definition: TNeuron.h:112
TMVA::TActivation
Interface for TNeuron activation function classes.
Definition: TActivation.h:42
TMVA::TNeuron::AdjustSynapseWeights
void AdjustSynapseWeights()
adjust the pre-synapses' weights for each neuron (input neuron has no pre-synapse) this method should...
Definition: TNeuron.cxx:263
TMVA::TNeuron::fValue
Double_t fValue
Definition: TNeuron.h:146
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TString
Basic string class.
Definition: TString.h:136
TString.h
bool
TMVA::TNeuron::TNeuron
TNeuron()
standard constructor
Definition: TNeuron.cxx:50
TMVA::TNeuron::CalculateValue
void CalculateValue()
calculate neuron input
Definition: TNeuron.cxx:93
TMVA::TNeuron::GetValue
Double_t GetValue() const
Definition: TNeuron.h:104
TMVA::TNeuron::SetError
void SetError(Double_t error)
set error, this should only be done for an output neuron
Definition: TNeuron.cxx:212
TActivation.h
TMVA::TNeuron::PostLinkAt
TSynapse * PostLinkAt(Int_t index) const
Definition: TNeuron.h:111
TMVA::TNeuron
Neuron class used by TMVA artificial neural network methods.
Definition: TNeuron.h:49
TMVA::TNeuron::UpdateSynapsesBatch
void UpdateSynapsesBatch()
update and adjust the pre-synapses for each neuron (input neuron has no pre-synapse) this method shou...
Definition: TNeuron.cxx:224
TMVA::TNeuron::PrintActivationEqn
void PrintActivationEqn()
print activation equation, for debugging
Definition: TNeuron.cxx:327
TSynapse.h
TMVA::TNeuron::SetActivationEqn
void SetActivationEqn(TActivation *activation)
set activation equation
Definition: TNeuron.cxx:160
TMVA::TNeuron::fDEDw
Double_t fDEDw
Definition: TNeuron.h:149
TMVA::TSynapse
Synapse class used by TMVA artificial neural network methods.
Definition: TSynapse.h:42
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
TMVA::TNeuron::NumLinks
Int_t NumLinks(TObjArray *links) const
Definition: TNeuron.h:135
TMVA::TNeuron::PrintLinks
void PrintLinks(TObjArray *links) const
print an array of TSynapses, for debugging
Definition: TNeuron.cxx:303
TMVA::TNeuron::SetBiasNeuron
void SetBiasNeuron()
Definition: TNeuron.h:114
TMVA::TNeuron::~TNeuron
virtual ~TNeuron()
destructor
Definition: TNeuron.cxx:58
TMVA::TNeuron::ForceValue
void ForceValue(Double_t value)
force the value, typically for input and bias neurons
Definition: TNeuron.cxx:84
TMVA::TNeuron::fInputCalculator
TNeuronInput * fInputCalculator
Definition: TNeuron.h:153
TMVA::TNeuron::fLinksIn
TObjArray * fLinksIn
Definition: TNeuron.h:144
TMVA::TNeuron::GetDEDw
Double_t GetDEDw() const
Definition: TNeuron.h:107
Types.h
TMVA::TNeuron::Print
virtual void Print(Option_t *="") const
This method must be overridden when a class wants to print itself.
Definition: TNeuron.h:121
TMVA::TNeuron::SetDEDw
void SetDEDw(Double_t DEDw)
Definition: TNeuron.h:115
TMVA::TNeuron::PrintMessage
void PrintMessage(EMsgType, TString message)
print message, for debugging
Definition: TNeuron.cxx:336
TMVA::TNeuron::InitSynapseDeltas
void InitSynapseDeltas()
initialize the error fields of all pre-neurons this method should only be called in batch mode
Definition: TNeuron.cxx:283
TMVA::TNeuron::fDelta
Double_t fDelta
Definition: TNeuron.h:148
TMVA::TNeuron::CalculateActivationValue
void CalculateActivationValue()
calculate neuron activation/output
Definition: TNeuron.cxx:102
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
TMVA::TNeuron::DeletePreLinks
void DeletePreLinks()
delete all pre-links
Definition: TNeuron.cxx:187
TObjArray.h
TMVA::TNeuron::NullifyLinks
void NullifyLinks(TObjArray *&links)
Definition: TNeuron.h:139
TMVA::TNeuron::Log
MsgLogger & Log() const
Definition: TNeuron.cxx:343
TMVA::TNeuron::DeleteLinksArray
void DeleteLinksArray(TObjArray *&links)
delete an array of TSynapses
Definition: TNeuron.cxx:195
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::TNeuron::IsInputNeuron
Bool_t IsInputNeuron() const
Definition: TNeuron.h:116
TMVA::TNeuron::SetOutputNeuron
void SetOutputNeuron()
Definition: TNeuron.h:113
TMVA::TNeuron::GetActivationValue
Double_t GetActivationValue() const
Definition: TNeuron.h:105
TMVA::TNeuron::NumPostLinks
Int_t NumPostLinks() const
Definition: TNeuron.h:109
TMVA::TNeuron::NumPreLinks
Int_t NumPreLinks() const
Definition: TNeuron.h:108
TSynapse
This is a simple weighted bidirectional connection between two neurons.
Definition: TSynapse.h:20
TMVA::TNeuron::SetInputCalculator
void SetInputCalculator(TNeuronInput *calculator)
set input calculator
Definition: TNeuron.cxx:151
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int
TMVA::TNeuron::PreLinkAt
TSynapse * PreLinkAt(Int_t index) const
Definition: TNeuron.h:110