Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
14 This is a simple weighted bidirectional connection between
15 two neurons.
16 A network is built connecting two neurons by a synapse.
17 In 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 
25 ClassImp(TSynapse);
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Default constructor
29 
30 TSynapse::TSynapse()
31 {
32  fpre = 0;
33  fpost = 0;
34  fweight = 1;
35  fDEDw = 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor that connects two neurons
40 
41 TSynapse::TSynapse(TNeuron * pre, TNeuron * post, Double_t w)
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 
54 void TSynapse::SetPre(TNeuron * pre)
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 
67 void TSynapse::SetPost(TNeuron * post)
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 
80 Double_t TSynapse::GetValue() const
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 
90 Double_t TSynapse::GetDeDw() const
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 
103 void TSynapse::SetWeight(Double_t w)
104 {
105  fweight = w;
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Sets the derivative of the total error wrt the synapse weight
110 
111 void TSynapse::SetDEDw(Double_t in)
112 {
113  fDEDw = in;
114 }
115 
116