00001 // @(#)root/tmva $Id: TSynapse.cxx 33928 2010-06-15 16:19:31Z stelzer $ 00002 // Author: Matt Jachowski 00003 00004 /********************************************************************************** 00005 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis * 00006 * Package: TMVA * 00007 * Class : TSynapse * 00008 * Web : http://tmva.sourceforge.net * 00009 * * 00010 * Description: * 00011 * Implementation (see header for description) * 00012 * * 00013 * Authors (alphabetical): * 00014 * Matt Jachowski <jachowski@stanford.edu> - Stanford University, USA * 00015 * * 00016 * Copyright (c) 2005: * 00017 * CERN, Switzerland * 00018 * * 00019 * Redistribution and use in source and binary forms, with or without * 00020 * modification, are permitted according to the terms listed in LICENSE * 00021 * (http://tmva.sourceforge.net/LICENSE) * 00022 **********************************************************************************/ 00023 00024 //_______________________________________________________________________ 00025 // 00026 // Synapse class used by TMVA artificial neural network methods 00027 //_______________________________________________________________________ 00028 00029 #include "TMVA/TSynapse.h" 00030 00031 #ifndef ROOT_TMVA_TNeuron 00032 #include "TMVA/TNeuron.h" 00033 #endif 00034 00035 #ifndef ROOT_TMVA_MsgLogger 00036 #include "TMVA/MsgLogger.h" 00037 #endif 00038 00039 static const Int_t fgUNINITIALIZED = -1; 00040 00041 ClassImp(TMVA::TSynapse); 00042 00043 TMVA::MsgLogger* TMVA::TSynapse::fgLogger = 0; 00044 00045 //______________________________________________________________________________ 00046 TMVA::TSynapse::TSynapse() 00047 : fWeight( 0 ), 00048 fLearnRate( 0 ), 00049 fDelta( 0 ), 00050 fDEDw( 0 ), 00051 fCount( 0 ), 00052 fPreNeuron( NULL ), 00053 fPostNeuron( NULL ) 00054 { 00055 // constructor 00056 fWeight = fgUNINITIALIZED; 00057 if (!fgLogger) fgLogger = new MsgLogger("TSynapse"); 00058 } 00059 00060 00061 //______________________________________________________________________________ 00062 TMVA::TSynapse::~TSynapse() 00063 { 00064 // destructor 00065 } 00066 00067 //______________________________________________________________________________ 00068 void TMVA::TSynapse::SetWeight(Double_t weight) 00069 { 00070 // set synapse weight 00071 fWeight = weight; 00072 } 00073 00074 //______________________________________________________________________________ 00075 Double_t TMVA::TSynapse::GetWeightedValue() 00076 { 00077 // get output of pre-neuron weighted by synapse weight 00078 if (fPreNeuron == NULL) 00079 Log() << kFATAL << "<GetWeightedValue> synapse not connected to neuron" << Endl; 00080 00081 return (fWeight * fPreNeuron->GetActivationValue()); 00082 } 00083 00084 //______________________________________________________________________________ 00085 Double_t TMVA::TSynapse::GetWeightedDelta() 00086 { 00087 // get error field of post-neuron weighted by synapse weight 00088 00089 if (fPostNeuron == NULL) 00090 Log() << kFATAL << "<GetWeightedDelta> synapse not connected to neuron" << Endl; 00091 00092 return fWeight * fPostNeuron->GetDelta(); 00093 } 00094 00095 //______________________________________________________________________________ 00096 void TMVA::TSynapse::AdjustWeight() 00097 { 00098 // adjust the weight based on the error field all ready calculated by CalculateDelta 00099 Double_t wDelta = fDelta / fCount; 00100 fWeight += -fLearnRate * wDelta; 00101 InitDelta(); 00102 } 00103 00104 //______________________________________________________________________________ 00105 void TMVA::TSynapse::CalculateDelta() 00106 { 00107 // calculate/adjust the error field for this synapse 00108 fDelta += fPostNeuron->GetDelta() * fPreNeuron->GetActivationValue(); 00109 fCount++; 00110 }