// @(#)root/mlp:$Id$
// Author: Christophe.Delaere@cern.ch   21/08/2002

/*************************************************************************
 * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

///////////////////////////////////////////////////////////////////////////
//
// TSynapse
//
// This is a simple weighted bidirectionnal connection between
// two neurons.
// A network is built connecting two neurons by a synapse.
// In addition to the value, the synapse can return the DeDw
//
///////////////////////////////////////////////////////////////////////////

#include "TSynapse.h"
#include "TNeuron.h"
#include "Riostream.h"

ClassImp(TSynapse)

//______________________________________________________________________________
TSynapse::TSynapse()
{
   // Default constructor
   fpre    = 0;
   fpost   = 0;
   fweight = 1;
   fDEDw   = 0;
}

//______________________________________________________________________________
TSynapse::TSynapse(TNeuron * pre, TNeuron * post, Double_t w)
{
   // Constructor that connects two neurons
   fpre    = pre;
   fpost   = post;
   fweight = w;
   fDEDw   = 0;
   pre->AddPost(this);
   post->AddPre(this);
}

//______________________________________________________________________________
void TSynapse::SetPre(TNeuron * pre)
{
   // Sets the pre-neuron
   if (pre) {
      Error("SetPre","this synapse is already assigned to a pre-neuron.");
      return;
   }
   fpre = pre;
   pre->AddPost(this);
}

//______________________________________________________________________________
void TSynapse::SetPost(TNeuron * post)
{
   // Sets the post-neuron
   if (post) {
      Error("SetPost","this synapse is already assigned to a post-neuron.");
      return;
   }
   fpost = post;
   post->AddPre(this);
}

//______________________________________________________________________________
Double_t TSynapse::GetValue() const
{
   // Returns the value: weithted input
   if (fpre)
      return (fweight * fpre->GetValue());
   return 0;
}

//______________________________________________________________________________
Double_t TSynapse::GetDeDw() const
{
   // Computes the derivative of the error wrt the synapse weight.
   if (!(fpre && fpost))
      return 0;
   return (fpre->GetValue() * fpost->GetDeDw());
}

//______________________________________________________________________________
void TSynapse::SetWeight(Double_t w)
{
   // Sets the weight of the synapse.
   // This weight is the multiplying factor applied on the
   // output of a neuron in the linear combination given as input
   // of another neuron.
   fweight = w;
}

//______________________________________________________________________________
void TSynapse::SetDEDw(Double_t in)
{
   // Sets the derivative of the total error wrt the synapse weight
   fDEDw = in;
}


 TSynapse.cxx:1
 TSynapse.cxx:2
 TSynapse.cxx:3
 TSynapse.cxx:4
 TSynapse.cxx:5
 TSynapse.cxx:6
 TSynapse.cxx:7
 TSynapse.cxx:8
 TSynapse.cxx:9
 TSynapse.cxx:10
 TSynapse.cxx:11
 TSynapse.cxx:12
 TSynapse.cxx:13
 TSynapse.cxx:14
 TSynapse.cxx:15
 TSynapse.cxx:16
 TSynapse.cxx:17
 TSynapse.cxx:18
 TSynapse.cxx:19
 TSynapse.cxx:20
 TSynapse.cxx:21
 TSynapse.cxx:22
 TSynapse.cxx:23
 TSynapse.cxx:24
 TSynapse.cxx:25
 TSynapse.cxx:26
 TSynapse.cxx:27
 TSynapse.cxx:28
 TSynapse.cxx:29
 TSynapse.cxx:30
 TSynapse.cxx:31
 TSynapse.cxx:32
 TSynapse.cxx:33
 TSynapse.cxx:34
 TSynapse.cxx:35
 TSynapse.cxx:36
 TSynapse.cxx:37
 TSynapse.cxx:38
 TSynapse.cxx:39
 TSynapse.cxx:40
 TSynapse.cxx:41
 TSynapse.cxx:42
 TSynapse.cxx:43
 TSynapse.cxx:44
 TSynapse.cxx:45
 TSynapse.cxx:46
 TSynapse.cxx:47
 TSynapse.cxx:48
 TSynapse.cxx:49
 TSynapse.cxx:50
 TSynapse.cxx:51
 TSynapse.cxx:52
 TSynapse.cxx:53
 TSynapse.cxx:54
 TSynapse.cxx:55
 TSynapse.cxx:56
 TSynapse.cxx:57
 TSynapse.cxx:58
 TSynapse.cxx:59
 TSynapse.cxx:60
 TSynapse.cxx:61
 TSynapse.cxx:62
 TSynapse.cxx:63
 TSynapse.cxx:64
 TSynapse.cxx:65
 TSynapse.cxx:66
 TSynapse.cxx:67
 TSynapse.cxx:68
 TSynapse.cxx:69
 TSynapse.cxx:70
 TSynapse.cxx:71
 TSynapse.cxx:72
 TSynapse.cxx:73
 TSynapse.cxx:74
 TSynapse.cxx:75
 TSynapse.cxx:76
 TSynapse.cxx:77
 TSynapse.cxx:78
 TSynapse.cxx:79
 TSynapse.cxx:80
 TSynapse.cxx:81
 TSynapse.cxx:82
 TSynapse.cxx:83
 TSynapse.cxx:84
 TSynapse.cxx:85
 TSynapse.cxx:86
 TSynapse.cxx:87
 TSynapse.cxx:88
 TSynapse.cxx:89
 TSynapse.cxx:90
 TSynapse.cxx:91
 TSynapse.cxx:92
 TSynapse.cxx:93
 TSynapse.cxx:94
 TSynapse.cxx:95
 TSynapse.cxx:96
 TSynapse.cxx:97
 TSynapse.cxx:98
 TSynapse.cxx:99
 TSynapse.cxx:100
 TSynapse.cxx:101
 TSynapse.cxx:102
 TSynapse.cxx:103
 TSynapse.cxx:104
 TSynapse.cxx:105
 TSynapse.cxx:106
 TSynapse.cxx:107
 TSynapse.cxx:108
 TSynapse.cxx:109
 TSynapse.cxx:110