{ "metadata": {}, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "from architecture_further_formulas import *" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
WeightChangeCalculation
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def WeightChangeCalculation(neuronIndex, spiketimes, time, negativeWeightReinforcement, positiveWeightReinforcement, M, dendObj):\n", "\tfor inputNeuronIndex in range(numberOfPixels):\n", "\t\t## General STDP learning rule implementation ##\n", "\t\t# Find SpikePreSyn if it exists\n", "\t\t# Note: could replace this with use of dictionary data structure for lookups if convenient for processing time later\n", "\t\t# Initial values of pre and post with .001 difference used below as estimation of value to use when no post syn spike is \n", "\t\t# found and weights should decrease. Based on the formulas the weights would not decrease, as they are intended to, unless\n", "\t\t# a close post syn spike is used in a prior to the pre syn spike position\n", "\n", "\t\tSpikePreSyn = time*second\n", "\t\tSpikePostSyn = SpikePreSyn-(.001*second)\n", "\n", "\t\tpreSynSpikeFound = False\n", "\t\tpostSynSpikeFound = False\n", "\n", "\t\tspikeCollection = spiketimes\n", "\t\tNumberOfSpikes = shape(spikeCollection)[0]\n", "\t\tfor i in range(NumberOfSpikes):\n", "\t\t\tCurrentSpikeNueron = spikeCollection[i][0]\n", "\t\t\tCurrentSpikeTime = spikeCollection[i][1]*second\n", "\n", "\t\t\t# exit loop once values below current time elapsed have all been checked\n", "\t\t\tif CurrentSpikeTime > (time*second):\n", "\t\t\t\tbreak\n", "\n", "\t\t\t# (time*second-.1*second) is to check if in relevant time window below.\n", "\t\t\t# Note: that may not be a good cut off and I should check it\n", "\t\t\tif CurrentSpikeNueron == inputNeuronIndex and CurrentSpikeTime > (time*second-.1*second):\n", "\t\t\t\tSpikePreSyn = CurrentSpikeTime\n", "\t\t\t\tpreSynSpikeFound = True\n", "\n", "\t\tspikeCollection = M.it\n", "\t\tNumberOfSpikes = len(spikeCollection[0])\n", "\t\tfor i in range(NumberOfSpikes):\n", "\t\t\tCurrentSpikeNueron = spikeCollection[0][i]\n", "\t\t\tCurrentSpikeTime = spikeCollection[1][i]\n", "\n", "\t\t\t# * Important difference: CurrentSpikeNueron is compared to self.neuronIndex and not inputNeuronIndex here\n", "\t\t\tif CurrentSpikeNueron == neuronIndex and CurrentSpikeTime >= (time*second-(.1+.008)*second) and CurrentSpikeTime <= (time*second):\n", "\t\t\t\tSpikePostSyn = CurrentSpikeTime\t\n", "\t\t\t\tpostSynSpikeFound = True\t\n", "\n", "\t\tif preSynSpikeFound == False or postSynSpikeFound == False:\n", "\t\t\tSpikePostSyn = SpikePreSyn-(.001*second)\n", "\t\t\t'''# Todo: watch more for spikes in a relevant time frame but are actually from different synapses and would\n", "\t\t\t# give different results? could cause unwanted results? brain would know synapse difference?'''\n", "\n", "\t\t# Find DeltaW\n", "\t\tDeltaW, DeltaSpikeTime = returnDeltaW(SpikePreSyn, SpikePostSyn) \n", "\n", "\t\t# Find new weight\n", "\t\tWOld = dendObj[neuronIndex].w[inputNeuronIndex]\n", "\n", "\t\t# if statement below skips W change until initial spikes can be formed\n", "\t\tif time>.1: \n", "\t\t\tNewW = returnNewW(WOld, DeltaW, DeltaSpikeTime, negativeWeightReinforcement, positiveWeightReinforcement)\n", "\t\t\tif NewW < 0: NewW = 0\n", "\t\t\telif NewW > 1: NewW = 1\n", "\t\t\tdendObj[neuronIndex].w[inputNeuronIndex] = NewW*volt\n", "\t\telse: \n", "\t\t\tdendObj[neuronIndex].w[inputNeuronIndex] = WOld*volt" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
returnDeltaW
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def returnDeltaW(SpikePreSyn, SpikePostSyn):\n", "\tDeltaSpikeTime = SpikePreSyn - SpikePostSyn \n", "\tDeltaSpikeTime = DeltaSpikeTime/second # remove second units\n", "\t# In thesis article it explains if DeltaT = 0 then DeltaW = 0\n", "\tDeltaW = 0\n", "\t# changed below line from that content in the article for a workaround/temp fix\n", "\tif DeltaSpikeTime < 0:\n", "\t\tDeltaW = APlus * (e ** (DeltaSpikeTime / (TauPlus)))\n", "\telif DeltaSpikeTime > 0:\n", "\t\tDeltaW = AMinus * (e ** (-DeltaSpikeTime / (TauMinus)))\n", "\n", "\treturn DeltaW, DeltaSpikeTime" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
returnNewW
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def returnNewW(WOld, DeltaW, DeltaSpikeTime, negativeWeightReinforcement, positiveWeightReinforcement):\n", "\tWOld = WOld/volt # remove volt unit\n", "\tWMin = 0;WMax = 1;\n", "\t# Check for inhibition occurence. DeltaSpikeTime > 0 is used to represent inhibition synapse presence\n", "\tif DeltaSpikeTime > 0:\n", "\t\tWMin = -1;WMax = 0;\t\n", "\t## Relaxation rule implementation ##\n", "\tif DeltaW < 0:\t\n", "\t\tWNew = WOld + ((LearningRate * (DeltaW * (WOld - WMin)))*negativeWeightReinforcement)\n", "\t\t\n", "\telif DeltaW >= 0:\t\t\t\t\n", "\t\tWNew = WOld + ((LearningRate * (DeltaW * (WMax - WOld)))*positiveWeightReinforcement)\n", "\n", "\treturn WNew;\n", "\t##\t" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
tauDCalc
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def tauDCalc(neuronIndex, dendObj):\n", "\t# Weight loop\n", "\tfor WIndex in range(numberOfPixels):\n", "\t\tweight = ((dendObj[neuronIndex].w[WIndex])/volt)\n", "\t\tif abs(weight) <= 1:\n", "\t\t\tdendObj[neuronIndex].tau[WIndex] = (tauMax - (abs(weight)*(tauMax-tauMin))) * ms# .001 is scaling factor found in dirac method" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
resistanceCalc
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def resistanceCalc(neuronIndex, dendObj, tauM):\n", "\t#Resistance loop\n", "\tfor RIndex in range(numberOfPixels):\t\t\t\t\n", "\t\tif (dendObj[neuronIndex].tau[RIndex]*.001 == tauM*second):\n", "\t\t\t# avoid a division by 0 issue\n", "\t\t\ttauM = tauM - .000001\n", "\n", "\t\tdendObj[neuronIndex].r[RIndex] = (((((dendObj[neuronIndex].tau[RIndex]*.001)/ms)*neuronFiringThreshold) / Rm) * ((tauM / ((dendObj[neuronIndex].tau[RIndex]/ms)*.001) ) ** (tauM / (tauM - ((dendObj[neuronIndex].tau[RIndex]/ms)*.001) ))))*volt" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
diracCalc
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def diracCalc(IDend, neuronIndex, spiketimes, time, lastSpikeInterval):\n", "\te = math.e\n", "\tdend = IDend\n", "\t# This method only calculates dirac. dirac function helps allow or disallow signal to be sent from input neurons through dendrite nodes or not\n", "\t# converted Dt to units which seem to make more sense for dirac function used, not sure if right to do that though\n", "\n", "\tdendGroup = [None]*len(dend[neuronIndex][:])\n", "\tfor IdIndex in range(len(dend[neuronIndex][:])):\n", "\t\t# set tpresyn initially too far to trigger dirac\n", "\t\ttPreSyn = time + 1\n", "\t\tfor presynInd in range(shape(spiketimes)[0]):\n", "\t\t\tcomparedSpikeTime = spiketimes[presynInd][1]\n", "\n", "\t\t\tif comparedSpikeTime > (lastSpikeInterval + timeAndRefrac.spikeIntervalUnformatted):\n", "\t\t\t\tbreak\n", "\n", "\t\t\tif spiketimes[presynInd][0] == IdIndex and (math.floor(1000*Decimal(format(time, '.3f')))*.001 == math.floor(1000*Decimal(format(comparedSpikeTime, '.3f')))*.001):\n", "\t\t\t\ttPreSyn = comparedSpikeTime\n", "\n", "\t\tDt = Decimal(format(time, '.8f')) - Decimal(format(tPreSyn, '.8f'))\n", "\t\t\n", "\t\t# simplify dirac until later. TODO: try more comple dirac #if (t > -(Dt/2) and t < (Dt/2)):\n", "\t\t# Seems to me what is looked for here is that the post synapse (output neurons) is after the pre synapse (input neurons)\n", "\t\tif Dt >= 0.0:\n", "\t\t\tDiracFun = 1\n", "\t\t\tdendGroup[IdIndex] = float(DiracFun)*volt*diracScaling\n", "\t\telse:\n", "\t\t\tDiracFun = 0\n", "\t\t\tdendGroup[IdIndex] = float(DiracFun)*volt*diracScaling\t\t\t\t\t\t\n", "\n", "\treturn dendGroup\t\t\t\t\t\t\t\t" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }