Connection.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 * Verve                                                                 *
00003 * Copyright (C) 2004-2006                                               *
00004 * Tyler Streeter  tylerstreeter@gmail.com                               *
00005 * All rights reserved.                                                  *
00006 * Web: http://verve-agents.sourceforge.net                              *
00007 *                                                                       *
00008 * This library is free software; you can redistribute it and/or         *
00009 * modify it under the terms of EITHER:                                  *
00010 *   (1) The GNU Lesser General Public License as published by the Free  *
00011 *       Software Foundation; either version 2.1 of the License, or (at  *
00012 *       your option) any later version. The text of the GNU Lesser      *
00013 *       General Public License is included with this library in the     *
00014 *       file license-LGPL.txt.                                          *
00015 *   (2) The BSD-style license that is included with this library in     *
00016 *       the file license-BSD.txt.                                       *
00017 *                                                                       *
00018 * This library is distributed in the hope that it will be useful,       *
00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00021 * license-LGPL.txt and license-BSD.txt for more details.                *
00022 ************************************************************************/
00023 
00024 #include "Connection.h"
00025 #include "Neuron.h"
00026 
00027 namespace verve
00028 {
00029         Connection::Connection(Neuron* preNeuron, Neuron* postNeuron)
00030         {
00031                 assert(preNeuron && postNeuron);
00032 
00033                 // Note: We don't have to update the post-synaptic Neuron's input 
00034                 // sum here because the weight is intially zero, so it doesn't 
00035                 // affect anything.
00036 
00037                 mPreNeuron = preNeuron;
00038                 mPostNeuron = postNeuron;
00039                 mWeight = 0;
00040         }
00041 
00042         Connection::~Connection()
00043         {
00044         }
00045 
00046         void Connection::resetShortTermMemory()
00047         {
00048         }
00049 
00050         real Connection::getWeight()const
00051         {
00052                 return mWeight;
00053         }
00054 
00055         void Connection::setWeight(real value)
00056         {
00057                 // If nothing has changed, quit early to save time.
00058                 if (value == mWeight)
00059                 {
00060                         return;
00061                 }
00062 
00063                 real deltaWeight = value - mWeight;
00064                 mWeight = value;
00065 
00066                 // If the pre-synaptic Neuron is active, then when need to update 
00067                 // the post-synaptic Neuron's input sum.
00068                 real preFiringRate = mPreNeuron->getFiringRate();
00069                 if (0 != preFiringRate)
00070                 {
00071                         mPostNeuron->addToSynapticInputSum(
00072                                 deltaWeight * preFiringRate);
00073                 }
00074         }
00075 
00076         void Connection::addToWeight(real delta)
00077         {
00078                 // If nothing has changed, quit early to save time.
00079                 if (0 == delta)
00080                 {
00081                         return;
00082                 }
00083 
00084                 mWeight += delta;
00085 
00086                 // If the pre-synaptic Neuron is active, then when need to update 
00087                 // the post-synaptic Neuron's input sum.
00088                 real preFiringRate = mPreNeuron->getFiringRate();
00089                 if (0 != preFiringRate)
00090                 {
00091                         mPostNeuron->addToSynapticInputSum(
00092                                 delta * preFiringRate);
00093                 }
00094         }
00095 
00096         Neuron* Connection::getPreNeuron()const
00097         {
00098                 return mPreNeuron;
00099         }
00100 
00101         Neuron* Connection::getPostNeuron()const
00102         {
00103                 return mPostNeuron;
00104         }
00105 
00106         //void Connection::applyIdealInitialNoise()
00107         //{
00108         //      // Applies Gaussian noise to the Connection weights with standard 
00109         //      // deviation equal to the inverse of the square root of the number 
00110         //      // of dendrites connected to the post-synaptic Neuron.  See Remi 
00111         //      // Coulom's PhD thesis for the reasoning.
00112 
00113         //      // We calculate the variance instead of standard deviation 
00114         //      // since that's what the random function takes as an argument.  
00115         //      // The standard deviation here should be 
00116         //      // 1 / sqrt(# of post-synaptic Neuron dendrites).  Since the 
00117         //      // variance equals the standard deviation squared, we can 
00118         //      // simply use 1 / # of post-synaptic Neuron dendrites.
00119 
00120         //      // A Connection's post-synaptic Neuron will always have at least 
00121         //      // one dendrite (i.e. the Connection in question), so we're safe 
00122         //      // from divide by zero errors here.
00123         //      real variance = 1 / (real)(mPostNeuron->getNumDendrites());
00124         //      addToWeight(globals::randomRealGauss(variance));
00125         //}
00126 }

Generated on Tue Jan 24 21:46:37 2006 for Verve by  doxygen 1.4.6-NO