Logo ROOT  
Reference Guide
TSynapse.cxx
Go to the documentation of this file.
1// @(#)root/mlp:$Id$
2// Author: Christophe.Delaere@cern.ch 21/08/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TSynapse
13
14This is a simple weighted bidirectional connection between
15two neurons.
16A network is built connecting two neurons by a synapse.
17In addition to the value, the synapse can return the DeDw
18
19*/
20
21#include "TSynapse.h"
22#include "TNeuron.h"
23#include "Riostream.h"
24
26
27////////////////////////////////////////////////////////////////////////////////
28/// Default constructor
29
31{
32 fpre = 0;
33 fpost = 0;
34 fweight = 1;
35 fDEDw = 0;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor that connects two neurons
40
42{
43 fpre = pre;
44 fpost = post;
45 fweight = w;
46 fDEDw = 0;
47 pre->AddPost(this);
48 post->AddPre(this);
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Sets the pre-neuron
53
55{
56 if (fpre) {
57 Error("SetPre","this synapse is already assigned to a pre-neuron.");
58 return;
59 }
60 fpre = pre;
61 pre->AddPost(this);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Sets the post-neuron
66
68{
69 if (fpost) {
70 Error("SetPost","this synapse is already assigned to a post-neuron.");
71 return;
72 }
73 fpost = post;
74 post->AddPre(this);
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Returns the value: weighted input
79
81{
82 if (fpre)
83 return (fweight * fpre->GetValue());
84 return 0;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Computes the derivative of the error wrt the synapse weight.
89
91{
92 if (!(fpre && fpost))
93 return 0;
94 return (fpre->GetValue() * fpost->GetDeDw());
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Sets the weight of the synapse.
99/// This weight is the multiplying factor applied on the
100/// output of a neuron in the linear combination given as input
101/// of another neuron.
102
104{
105 fweight = w;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Sets the derivative of the total error wrt the synapse weight
110
112{
113 fDEDw = in;
114}
115
116
double Double_t
Definition: RtypesCore.h:57
#define ClassImp(name)
Definition: Rtypes.h:361
This class describes an elementary neuron, which is the basic element for a Neural Network.
Definition: TNeuron.h:25
Double_t GetValue() const
Computes the output using the appropriate function and all the weighted inputs, or uses the branch as...
Definition: TNeuron.cxx:946
Double_t GetDeDw() const
Computes the derivative of the error wrt the neuron weight.
Definition: TNeuron.cxx:1082
void AddPost(TSynapse *)
Adds a synapse to the neuron as an output This method is used by the TSynapse while connecting two ne...
Definition: TNeuron.cxx:844
void AddPre(TSynapse *)
Adds a synapse to the neuron as an input This method is used by the TSynapse while connecting two neu...
Definition: TNeuron.cxx:832
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
This is a simple weighted bidirectional connection between two neurons.
Definition: TSynapse.h:20
TNeuron * fpre
the neuron before the synapse
Definition: TSynapse.h:37
void SetPre(TNeuron *pre)
Sets the pre-neuron.
Definition: TSynapse.cxx:54
Double_t GetDeDw() const
Computes the derivative of the error wrt the synapse weight.
Definition: TSynapse.cxx:90
TNeuron * fpost
the neuron after the synapse
Definition: TSynapse.h:38
void SetPost(TNeuron *post)
Sets the post-neuron.
Definition: TSynapse.cxx:67
Double_t fDEDw
! the derivative of the total error wrt the synapse weight
Definition: TSynapse.h:40
Double_t fweight
the weight of the synapse
Definition: TSynapse.h:39
void SetWeight(Double_t w)
Sets the weight of the synapse.
Definition: TSynapse.cxx:103
Double_t GetValue() const
Returns the value: weighted input.
Definition: TSynapse.cxx:80
void SetDEDw(Double_t in)
Sets the derivative of the total error wrt the synapse weight.
Definition: TSynapse.cxx:111
TSynapse()
Default constructor.
Definition: TSynapse.cxx:30