Logo ROOT  
Reference Guide
TSynapse.cxx
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 : TSynapse *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
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 /*! \class TMVA::TSynapse
25 \ingroup TMVA
26 Synapse class used by TMVA artificial neural network methods
27 */
28 
29 #include "TMVA/TSynapse.h"
30 
31 #include "TMVA/TNeuron.h"
32 
33 #include "TMVA/MsgLogger.h"
34 
35 #include "TMVA/Types.h"
36 
37 #include "ThreadLocalStorage.h"
38 
39 static const Int_t fgUNINITIALIZED = -1;
40 
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// constructor
45 
47  : fWeight( 0 ),
48  fLearnRate( 0 ),
49  fDelta( 0 ),
50  fDEDw( 0 ),
51  fCount( 0 ),
52  fPreNeuron( NULL ),
53  fPostNeuron( NULL )
54 {
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// destructor
60 
62 {
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// set synapse weight
67 
69 {
70  fWeight = weight;
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// get output of pre-neuron weighted by synapse weight
75 
77 {
78  if (fPreNeuron == NULL)
79  Log() << kFATAL << "<GetWeightedValue> synapse not connected to neuron" << Endl;
80 
81  return (fWeight * fPreNeuron->GetActivationValue());
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// get error field of post-neuron weighted by synapse weight
86 
88 {
89  if (fPostNeuron == NULL)
90  Log() << kFATAL << "<GetWeightedDelta> synapse not connected to neuron" << Endl;
91 
92  return fWeight * fPostNeuron->GetDelta();
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// adjust the weight based on the error field all ready calculated by CalculateDelta
97 
99 {
100  Double_t wDelta = fDelta / fCount;
101  fWeight += -fLearnRate * wDelta;
102  InitDelta();
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// calculate/adjust the error field for this synapse
107 
109 {
110  fDelta += fPostNeuron->GetDelta() * fPreNeuron->GetActivationValue();
111  fCount++;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 
117 {
118  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"TSynapse"); //! message logger, static to save resources
119  return logger;
120 }
TMVA::TSynapse::fWeight
Double_t fWeight
Definition: TSynapse.h:91
TMVA::TSynapse::GetWeightedDelta
Double_t GetWeightedDelta()
get error field of post-neuron weighted by synapse weight
Definition: TSynapse.cxx:87
TMVA::TSynapse::SetWeight
void SetWeight(Double_t weight)
set synapse weight
Definition: TSynapse.cxx:68
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TMath::Log
Double_t Log(Double_t x)
Definition: TMath.h:760
Int_t
int Int_t
Definition: RtypesCore.h:45
TMVA::TSynapse::~TSynapse
virtual ~TSynapse()
destructor
Definition: TSynapse.cxx:61
TMVA::TSynapse::CalculateDelta
void CalculateDelta()
calculate/adjust the error field for this synapse
Definition: TSynapse.cxx:108
TMVA::TSynapse::TSynapse
TSynapse()
constructor
Definition: TSynapse.cxx:46
TSynapse.h
MsgLogger.h
TMVA::TSynapse::GetWeightedValue
Double_t GetWeightedValue()
get output of pre-neuron weighted by synapse weight
Definition: TSynapse.cxx:76
TMVA::TSynapse
Synapse class used by TMVA artificial neural network methods.
Definition: TSynapse.h:42
TMVA::TSynapse::Log
MsgLogger & Log() const
Definition: TSynapse.cxx:116
Types.h
TMVA::Endl
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
ThreadLocalStorage.h
fgUNINITIALIZED
static const Int_t fgUNINITIALIZED
Definition: TSynapse.cxx:39
TMVA::TSynapse::AdjustWeight
void AdjustWeight()
adjust the weight based on the error field all ready calculated by CalculateDelta
Definition: TSynapse.cxx:98
TNeuron.h