Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TObject.h"
39 
40 static const Int_t fgUNINITIALIZED = -1;
41 
42 ClassImp(TMVA::TSynapse);
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// constructor
46 
47 TMVA::TSynapse::TSynapse()
48  : fWeight( 0 ),
49  fLearnRate( 0 ),
50  fDelta( 0 ),
51  fDEDw( 0 ),
52  fCount( 0 ),
53  fPreNeuron( NULL ),
54  fPostNeuron( NULL )
55 {
56  fWeight = fgUNINITIALIZED;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// destructor
61 
62 TMVA::TSynapse::~TSynapse()
63 {
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// set synapse weight
68 
69 void TMVA::TSynapse::SetWeight(Double_t weight)
70 {
71  fWeight = weight;
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// get output of pre-neuron weighted by synapse weight
76 
77 Double_t TMVA::TSynapse::GetWeightedValue()
78 {
79  if (fPreNeuron == NULL)
80  Log() << kFATAL << "<GetWeightedValue> synapse not connected to neuron" << Endl;
81 
82  return (fWeight * fPreNeuron->GetActivationValue());
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// get error field of post-neuron weighted by synapse weight
87 
88 Double_t TMVA::TSynapse::GetWeightedDelta()
89 {
90  if (fPostNeuron == NULL)
91  Log() << kFATAL << "<GetWeightedDelta> synapse not connected to neuron" << Endl;
92 
93  return fWeight * fPostNeuron->GetDelta();
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// adjust the weight based on the error field all ready calculated by CalculateDelta
98 
99 void TMVA::TSynapse::AdjustWeight()
100 {
101  Double_t wDelta = fDelta / fCount;
102  fWeight += -fLearnRate * wDelta;
103  InitDelta();
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// calculate/adjust the error field for this synapse
108 
109 void TMVA::TSynapse::CalculateDelta()
110 {
111  fDelta += fPostNeuron->GetDelta() * fPreNeuron->GetActivationValue();
112  fCount++;
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 
117 TMVA::MsgLogger& TMVA::TSynapse::Log() const
118 {
119  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"TSynapse"); //! message logger, static to save resources
120  return logger;
121 }