Logo ROOT   6.10/09
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 ///////////////////////////////////////////////////////////////////////////
13 //
14 // TSynapse
15 //
16 // This is a simple weighted bidirectionnal connection between
17 // two neurons.
18 // A network is built connecting two neurons by a synapse.
19 // In addition to the value, the synapse can return the DeDw
20 //
21 ///////////////////////////////////////////////////////////////////////////
22 
23 #include "TSynapse.h"
24 #include "TNeuron.h"
25 #include "Riostream.h"
26 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Default constructor
31 
33 {
34  fpre = 0;
35  fpost = 0;
36  fweight = 1;
37  fDEDw = 0;
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor that connects two neurons
42 
44 {
45  fpre = pre;
46  fpost = post;
47  fweight = w;
48  fDEDw = 0;
49  pre->AddPost(this);
50  post->AddPre(this);
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Sets the pre-neuron
55 
57 {
58  if (pre) {
59  Error("SetPre","this synapse is already assigned to a pre-neuron.");
60  return;
61  }
62  fpre = pre;
63  pre->AddPost(this);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Sets the post-neuron
68 
70 {
71  if (post) {
72  Error("SetPost","this synapse is already assigned to a post-neuron.");
73  return;
74  }
75  fpost = post;
76  post->AddPre(this);
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Returns the value: weithted input
81 
83 {
84  if (fpre)
85  return (fweight * fpre->GetValue());
86  return 0;
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Computes the derivative of the error wrt the synapse weight.
91 
93 {
94  if (!(fpre && fpost))
95  return 0;
96  return (fpre->GetValue() * fpost->GetDeDw());
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Sets the weight of the synapse.
101 /// This weight is the multiplying factor applied on the
102 /// output of a neuron in the linear combination given as input
103 /// of another neuron.
104 
106 {
107  fweight = w;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Sets the derivative of the total error wrt the synapse weight
112 
114 {
115  fDEDw = in;
116 }
117 
118 
TNeuron * fpre
Definition: TSynapse.h:47
Double_t fweight
Definition: TSynapse.h:49
Double_t GetValue() const
Returns the value: weithted input.
Definition: TSynapse.cxx:82
Double_t GetDeDw() const
Computes the derivative of the error wrt the synapse weight.
Definition: TSynapse.cxx:92
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:834
Double_t GetValue() const
Computes the output using the appropriate function and all the weighted inputs, or uses the branch as...
Definition: TNeuron.cxx:948
void SetPre(TNeuron *pre)
Sets the pre-neuron.
Definition: TSynapse.cxx:56
TSynapse()
Default constructor.
Definition: TSynapse.cxx:32
void SetPost(TNeuron *post)
Sets the post-neuron.
Definition: TSynapse.cxx:69
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
TNeuron * fpost
Definition: TSynapse.h:48
void SetWeight(Double_t w)
Sets the weight of the synapse.
Definition: TSynapse.cxx:105
#define ClassImp(name)
Definition: Rtypes.h:336
void SetDEDw(Double_t in)
Sets the derivative of the total error wrt the synapse weight.
Definition: TSynapse.cxx:113
double Double_t
Definition: RtypesCore.h:55
Double_t GetDeDw() const
Computes the derivative of the error wrt the neuron weight.
Definition: TNeuron.cxx:1084
Double_t fDEDw
Definition: TSynapse.h:50
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:846