def attachStimulus( fname, rdes ): compts = rdes.elecid.compartments heads = [] lookupSpineIndexFromCompt = [] for i in compts: sl = rdes.elecid.spinesOnCompartment[i] lookupSpineIndexFromCompt.append( len( heads ) ) heads.extend( sl[1::2] ) ampar = moose.wildcardFind( '/model/elec/#/glu' ) assert( len(ampar) == len( heads ) ) moose.RandSpike( '/model/elec/spike', len( heads ) ) spikes = moose.vec( '/model/elec/spike' ) spikes.rate = params['meanSpikeRate'] spikes.refractT = params['refractoryPeriod'] amparSynWeight = params['amparSynapseWeight'] nmdarSynWeight = params['nmdarSynapseWeight'] for j in zip( heads, range( len( heads ) ) ): sh = moose.element( j[0].path + '/glu/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = amparSynWeight moose.connect( spikes[j[1]], 'spikeOut', sh.synapse[0], 'addSpike' ) sh = moose.element( j[0].path + '/NMDA/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = nmdarSynWeight moose.connect( spikes[j[1]], 'spikeOut', sh.synapse[0], 'addSpike' ) thetaGaba = moose.Function( '/model/elec/thetaGabaRhythm' ) timeExpr = 'cos( 6.283 * t * ' + str(params['thetaFreq']/2.0) + ' )^2' rateExpr = str( 2.0 * params['thetaGabaSpikeRate']) thetaGaba.expr = str( params['baseGabaSpikeRate']) + ' + ' + rateExpr + ' * ' + timeExpr print thetaGaba.expr, gabar = moose.wildcardFind( '/model/elec/#/GABA' ) print " NUM-GABA = ", len(gabar) rsGabar = moose.RandSpike( '/model/elec/gabaSpike', len( gabar ) ) moose.connect( thetaGaba, 'valueOut', rsGabar, 'setRate', 'OneToAll' ) gabaSpikes = moose.vec( '/model/elec/gabaSpike' ) #spikes.rate = params['meanSpikeRate'] gabaSpikes.refractT = params['refractoryPeriod'] gabarSynWeight = params['gabarSynapseWeight'] for i in range( len(gabar) ): sh = moose.element( gabar[i].path + '/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = gabarSynWeight moose.connect( gabaSpikes[i], 'spikeOut', sh.synapse[0], 'addSpike' ) return lookupSpineIndexFromCompt
def example(): """ The RandSpike class generates spike events from a Poisson process and sends out a trigger via its `spikeOut` message. It is very common to approximate the spiking in many neurons as a Poisson process, i.e., the probability of `k` spikes in any interval `t` is given by the Poisson distribution: exp(-ut)(ut)^k/k! for k = 0, 1, 2, ... u is the rate of spiking (the mean of the Poisson distribution). See `wikipedia <http://en.wikipedia.org/wiki/Poisson_process>`__ for details. Many cortical neuron types spontaneously fire action potentials. These are called ectopic spikes. In this example we simulate this with a RandSpike object with rate 10 spikes/s and send this to a single compartmental neuron via a synapse. In this model the synaptic conductance is set so high that each incoming spike evokes an action potential. """ ectopic = moose.RandSpike('ectopic_input') ectopic.rate = 10.0 cellmodel = create_cell() moose.connect(ectopic, 'spikeOut', cellmodel['synhandler'].synapse[0], 'addSpike') tab_vm = moose.Table('/Vm') moose.connect(tab_vm, 'requestOut', cellmodel['neuron'], 'getVm') moose.reinit() moose.start(SIMTIME) return tab_vm
def createRandSpike(spikeParams, synHandler): pre_syn = moose.RandSpike(spikeParams['name']) pre_syn.rate = spikeParams['rate'] pre_syn.refractT = spikeParams['refractT'] index = synHandler.synapse.num synHandler.synapse.num = synHandler.synapse.num + 1 synHandler.synapse[index].delay = spikeParams['delay'] moose.connect(pre_syn, 'spikeOut', synHandler.synapse[index], 'addSpike') return pre_syn
def make_synInput(name='RandSpike', parent='/library'): if moose.exists('/library/' + name): return rs = moose.RandSpike(parent + '/' + name + '_rs') rs.rate = 0 # mean firing rate rs.refractT = 5e-3 # 5 ms. # Connect rand spike to channel that it is sitting on. addmsg1 = moose.Mstring(rs.path + '/addmsg1') addmsg1.value = '. spikeOut ../sh/synapse[0] addSpike' return rs
def make_model(): sinePeriod = 50 maxFiringRate = 10 refractT = 0.05 for i in range(20): moose.setClock(i, dt) ############### Create objects ############### stim = moose.StimulusTable('stim') spike = moose.RandSpike('spike') syn = moose.SimpleSynHandler('syn') fire = moose.IntFire('fire') stats1 = moose.SpikeStats('stats1') stats2 = moose.Stats('stats2') plots = moose.Table('plots') plot1 = moose.Table('plot1') plot2 = moose.Table('plot2') plotf = moose.Table('plotf') ############### Set up parameters ############### stim.vector = [ maxFiringRate * numpy.sin(x * 2 * numpy.pi / sinePeriod) for x in range(sinePeriod) ] stim.startTime = 0 stim.stopTime = sinePeriod stim.loopTime = sinePeriod stim.stepSize = 0 stim.stepPosition = 0 stim.doLoop = 1 spike.refractT = refractT syn.synapse.num = 1 syn.synapse[0].weight = 1 syn.synapse[0].delay = 0 fire.thresh = 100 # Don't want it to spike, just to integrate fire.tau = 1.0 / maxFiringRate stats1.windowLength = int(1 / dt) stats2.windowLength = int(1 / dt) ############### Connect up circuit ############### moose.connect(stim, 'output', spike, 'setRate') moose.connect(spike, 'spikeOut', syn.synapse[0], 'addSpike') moose.connect(spike, 'spikeOut', stats1, 'addSpike') moose.connect(syn, 'activationOut', fire, 'activation') moose.connect(stats2, 'requestOut', fire, 'getVm') moose.connect(plots, 'requestOut', stim, 'getOutputValue') moose.connect(plot1, 'requestOut', stats1, 'getWmean') moose.connect(plot2, 'requestOut', stats2, 'getWmean') moose.connect(plotf, 'requestOut', fire, 'getVm')
def create_spikegen(name, type, refractory_period, rate=None, threshold=None): ''' Create spikegen which is used as pre synaptic trigger. ''' if not moose.exists('/spikegens'): spikelib = moose.Neutral('/spikegens') if type.lower() in "random" and rate is not None: spikegen = moose.RandSpike('/spikegens/' + name) spikegen.rate = np.float(rate) elif type.lower() in "linear" and threshold is not None: spikegen = moose.SpikeGen('/spikegens/' + name) spikegen.threshold = np.float(threshold) spikegen.refractT = np.float(refractory_period) return spikegen
def attachStimulus2( fname ): ampar = moose.wildcardFind( '/model/elec/#/glu' ) nmdar = moose.wildcardFind( '/model/elec/#/NMDA' ) numSyn = len( ampar ) assert( numSyn == len( nmdar ) ); moose.le( '/model' ) moose.RandSpike( '/model/elec/spike', len( ampar ) ) spikes = moose.vec( '/model/elec/spike' ) spikes.rate = params['meanSpikeRate'] spikes.refractT = params['refractoryPeriod'] amparSynWeight = params['amparSynapseWeight'] nmdarSynWeight = params['nmdarSynapseWeight'] for i in range( numSyn ): sh = moose.element( ampar[i].path + '/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = amparSynWeight moose.connect( spikes[i], 'spikeOut', sh.synapse[0], 'addSpike' ) sh = moose.element( nmdar[i].path + '/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = nmdarSynWeight moose.connect( spikes[i], 'spikeOut', sh.synapse[0], 'addSpike' )
gammaP = 725.085 # factor for potentiation term J = 5e-3 # V # delta function synapse, adds to Vm weight = 0.43 # initial synaptic weight # gammaP/(gammaP+gammaD) = eq weight w/o noise # see eqn (22), noiseSD also appears # but doesn't work here, # weights away from 0.4 - 0.5 screw up the STDP rule!! bistable = True # if bistable is True, use bistable potential for weights noisy = True # use noisy weight updates given by noiseSD noiseSD = 3.3501 # if noisy, use noiseSD (3.3501 from Higgins et al 2014) ########################################## prePoisson = moose.RandSpike('/pre') prePoisson.rate = frate postPoisson = moose.RandSpike('/post') postPoisson.rate = frate syn = moose.GraupnerBrunel2012CaPlasticitySynHandler('/syn') syn.numSynapses = 1 # 1 synapse # many pre-synaptic inputs can connect to a synapse # spikes from presynaptic Poisson generator moose.connect(prePoisson, 'spikeOut', syn.synapse[0], 'addSpike') # post-synaptic spikes from postsynaptic Poisson generator moose.connect(postPoisson, 'spikeOut', syn, 'addPostSpike') syn.synapse[0].delay = 0.0
import moose simtime = 0.1 simdt = 0.25e-5 plotdt = 0.25e-3 for i in range(10): moose.setClock(i, simdt) moose.setClock(8, plotdt) spike = moose.RandSpike("/spike0") spike.rate = 1300 spike.refractT = 1e-3 tab = moose.Table("/pre0") moose.connect(spike, "spikeOut", tab, "spike") moose.reinit() moose.start(simtime) print(tab.vector)
def createRandSpike(path, rate): spike = moose.RandSpike(path) spike.rate = rate spike.refractT = 1e-3 return spike
def makeGlobalBalanceNetwork(): stim = moose.RandSpike('/model/stim', params['numInputs']) inhib = moose.LIF('/model/inhib', params['numInhib']) insyn = moose.SimpleSynHandler(inhib.path + '/syns', params['numInhib']) moose.connect(insyn, 'activationOut', inhib, 'activation', 'OneToOne') output = moose.LIF('/model/output', params['numOutput']) outsyn = moose.SimpleSynHandler(output.path + '/syns', params['numOutput']) moose.connect(outsyn, 'activationOut', output, 'activation', 'OneToOne') outInhSyn = moose.SimpleSynHandler(output.path + '/inhsyns', params['numOutput']) moose.connect(outInhSyn, 'activationOut', output, 'activation', 'OneToOne') iv = moose.vec(insyn.path + '/synapse') ov = moose.vec(outsyn.path + '/synapse') oiv = moose.vec(outInhSyn.path + '/synapse') assert len(iv) == 0 assert len(ov) == 0 assert len(oiv) == 0 temp = moose.connect(stim, 'spikeOut', iv, 'addSpike', 'Sparse') inhibMatrix = moose.element(temp) inhibMatrix.setRandomConnectivity(params['stimToInhProb'], params['stimToInhSeed']) cl = inhibMatrix.connectionList # This can change when random-number generator changes. # This was before we used c++11 <random> to generate random numbers. This # test has changes on Tuesday 31 July 2018 11:12:35 AM IST # expectedCl = [ 1,4,13,13,26,42,52,56,80,82,95,97,4,9,0,9,4,8,0,6,1,6,6,7] expectedCl = [0, 6, 47, 50, 56, 67, 98, 2, 0, 3, 5, 4, 8, 3] assert list(cl) == expectedCl, "Expected %s, got %s" % (expectedCl, cl) temp = moose.connect(stim, 'spikeOut', ov, 'addSpike', 'Sparse') excMatrix = moose.element(temp) excMatrix.setRandomConnectivity(params['stimToOutProb'], params['stimToOutSeed']) temp = moose.connect(inhib, 'spikeOut', oiv, 'addSpike', 'Sparse') negFFMatrix = moose.element(temp) negFFMatrix.setRandomConnectivity(params['inhToOutProb'], params['inhToOutSeed']) # print("ConnMtxEntries: ", inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) got = (inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) expected = (7, 62, 55) assert expected == got, "Expected %s, Got %s" % (expected, got) cl = negFFMatrix.connectionList numInhSyns = [] niv = 0 nov = 0 noiv = 0 for i in moose.vec(insyn): niv += i.synapse.num numInhSyns.append(i.synapse.num) if i.synapse.num > 0: i.synapse.weight = params['wtStimToInh'] # expected = [2,1,0,0,2,0,3,1,1,2] expected = [1, 0, 1, 2, 1, 1, 0, 0, 1, 0] assert numInhSyns == expected, "Expected %s, got %s" % (expected, numInhSyns) for i in moose.vec(outsyn): print('111', i) nov += i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtStimToOut'] for i in moose.vec(outInhSyn): noiv += i.synapse.num #print i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtInhToOut'] print("SUMS: ", sum(iv.numField), sum(ov.numField), sum(oiv.numField)) assert [1, 64, 25] == [sum(iv.numField), sum(ov.numField), sum(oiv.numField)] print("SUMS2: ", niv, nov, noiv) assert [7, 62, 55] == [niv, nov, noiv] print("SUMS3: ", sum(insyn.vec.numSynapses), sum(outsyn.vec.numSynapses), sum(outInhSyn.vec.numSynapses)) assert [7, 62, 55] == [ sum(insyn.vec.numSynapses), sum(outsyn.vec.numSynapses), sum(outInhSyn.vec.numSynapses) ] # print(oiv.numField) # print(insyn.vec[1].synapse.num) # print(insyn.vec.numSynapses) # print(sum( insyn.vec.numSynapses )) # niv = iv.numSynapses # ov = iv.numSynapses sv = moose.vec(stim) sv.rate = params['randInputRate'] sv.refractT = params['randRefractTime'] #moose.showfield( sv[7] ) inhib.vec.thresh = params['inhibThresh'] inhib.vec.Rm = params['Rm'] inhib.vec.Cm = params['Cm'] inhib.vec.vReset = params['inhVreset'] inhib.vec.refractoryPeriod = params['inhibRefractTime'] output.vec.thresh = params['outputThresh'] output.vec.Rm = params['Rm'] output.vec.Cm = params['Cm'] output.vec.refractoryPeriod = params['outputRefractTime'] otab = moose.Table('/model/otab', params['numOutput']) moose.connect(otab, 'requestOut', output, 'getVm', 'OneToOne') itab = moose.Table('/model/itab', params['numInhib']) moose.connect(itab, 'requestOut', inhib, 'getVm', 'OneToOne') return inhib, output
synchan.tau2 = 2E-3 synchan.Ek = -10E-3 # Connections moose.connect(soma, 'axialOut', dend, 'handleAxial') moose.connect(dend, 'channel', synchan, 'channel') sh = moose.SimpleSynHandler(synchan.path + '/synhandler') moose.connect(sh, 'activationOut', synchan, 'activation') sh.synapse.num = 1 sh.synapse[0].delay = 1E-3 moose.showmsg(sh) presyn = moose.RandSpike('presyn_input') presyn.rate = 1.3 presyn.refractT = 1E-3 moose.connect(presyn, 'spikeOut', sh.synapse[0], 'addSpike') sh.synapse.num = 2 sh.synapse[1].delay = 0.1E-3 presyn2 = moose.RandSpike('presyn_input2') presyn2.rate = 3.5 presyn2.refractT = 1E-3 moose.connect(presyn2, 'spikeOut', sh.synapse[1], 'addSpike') spiketable1 = moose.Table('spikes1') moose.connect(presyn, 'spikeOut', spiketable1, 'spike') spiketable2 = moose.Table('spikes2')
def main(): """ Simulate pre and post Poisson firing for a synapse with Ca plasticity of Graupner and Brunel 2012. See the trace over time (lifetime) for the synaptic efficacy, similar to figure 2A of Higgins, Graupner, Brunel, 2014. Author: Aditya Gilra, NCBS, Bangalore, October, 2014. """ numrepeats = 10 # repeat runtime for numrepeats frate = 1.0 # pre- and post-synaptic firing rate # 1 Hz gives ~300s lifetime, ~0.2 efficacy (weight) # 10 Hz gives ~10s lifetime, ~0.5 efficacy (weight) # high firing rates make synaptic efficacy go to 0.5. runtime = 600.0 / frate # s ############################################# # Ca Plasticity parameters: synapses (not for ExcInhNetBase) ############################################# ## Cortical slice values -- Table Suppl 2 in Graupner & Brunel 2012 ## Also used in Higgins et al 2014 tauCa = 22.6936e-3 # s # Ca decay time scale tauSyn = 346.3615 # s # synaptic plasticity time scale ## in vitro values in Higgins et al 2014, faster plasticity CaPre = 0.56175 # mM CaPost = 1.2964 # mM ## in vivo values in Higgins et al 2014, slower plasticity #CaPre = 0.33705 # mM #CaPost = 0.74378 # mM delayD = 4.6098e-3 # s # CaPre is added to Ca after this delay # proxy for rise-time of NMDA thetaD = 1.0 # mM # depression threshold for Ca thetaP = 1.3 # mM # potentiation threshold for Ca gammaD = 331.909 # factor for depression term gammaP = 725.085 # factor for potentiation term J = 5e-3 # V # delta function synapse, adds to Vm weight = 0.43 # initial synaptic weight # gammaP/(gammaP+gammaD) = eq weight w/o noise # see eqn (22), noiseSD also appears # but doesn't work here, # weights away from 0.4 - 0.5 screw up the STDP rule!! bistable = True # if bistable is True, use bistable potential for weights noisy = True # use noisy weight updates given by noiseSD noiseSD = 3.3501 # if noisy, use noiseSD (3.3501 from Higgins et al 2014) ########################################## prePoisson = moose.RandSpike('/pre') prePoisson.rate = frate postPoisson = moose.RandSpike('/post') postPoisson.rate = frate syn = moose.GraupnerBrunel2012CaPlasticitySynHandler('/syn') syn.numSynapses = 1 # 1 synapse # many pre-synaptic inputs can connect to a synapse # spikes from presynaptic Poisson generator moose.connect(prePoisson, 'spikeOut', syn.synapse[0], 'addSpike') # post-synaptic spikes from postsynaptic Poisson generator moose.connect(postPoisson, 'spikeOut', syn, 'addPostSpike') syn.synapse[0].delay = 0.0 syn.synapse[0].weight = 1.0 # starting weight to decay from syn.CaInit = 0.0 syn.tauCa = tauCa syn.tauSyn = tauSyn syn.CaPre = CaPre syn.CaPost = CaPost syn.delayD = delayD syn.thetaD = thetaD syn.thetaP = thetaP syn.gammaD = gammaD syn.gammaP = gammaP syn.weightMax = 1.0 # bounds on the weight syn.weightMin = 0. syn.noisy = noisy syn.noiseSD = noiseSD syn.bistable = bistable # ########################################### # Setting up tables # ########################################### CaTable = moose.Table('/plotCa', 1) moose.connect(CaTable, 'requestOut', syn, 'getCa') WtTable = moose.Table('/plotWeight', 1) moose.connect(WtTable, 'requestOut', syn.synapse[0], 'getWeight') # ########################################### # Simulate # ########################################### dt = 1e-3 # s # moose simulation #moose.useClock( 0, '/syn', 'process' ) #moose.useClock( 1, '/pre', 'process' ) #moose.useClock( 1, '/post', 'process' ) # I think MOOSE uses a different clock than 3 for Tables # anyway, we use the default one and set all clocks to dt below #moose.useClock( 3, '/plotCa', 'process' ) #moose.useClock( 3, '/plotWeight', 'process' ) ## use setClock to set the dt different from default dt for i in range(10): moose.setClock(i, dt) moose.seed(100) moose.reinit() # function to make the aPlus and aMinus settle to equilibrium values print(("Rates of pre- and post-syanptic neurons =", frate)) WtSeries = [] numsteps = int(runtime / dt) for i in range(numrepeats): syn.synapse[0].weight = 1.0 # starting weight to decay from syn.Ca = 0.0 print(("Repeat number", i, "running...")) moose.start(runtime) WtSeries.append(WtTable.vector[i * numsteps:(i + 1) * numsteps]) WtSeries = array(WtSeries) WtMean = mean(WtSeries, axis=0) print("plotting...") # ########################################### # Plot the simulated weights and Ca vs time # ########################################### timeseries = linspace(0.0, runtime, numsteps) # Ca plots for the synapse # only the first repeat figure(facecolor='w') plot(timeseries, CaTable.vector[:numsteps], color='r') plot((timeseries[0],timeseries[-1]),(thetaP,thetaP),color='k',\ linestyle='dashed',label='pot thresh') plot((timeseries[0],timeseries[-1]),(thetaD,thetaD),color='b',\ linestyle='dashed',label='dep thresh') legend() xlabel('time (s)') ylabel('Ca (arb)') title("Ca conc in the synapse @ " + str(frate) + " Hz firing") # Weight plots for the synapse figure(facecolor='w') for i in range(numrepeats): plot(timeseries, WtSeries[i], alpha=0.5) plot(timeseries, WtMean, color='k', linewidth=2) xlabel('time (s)') ylabel('Efficacy') title("Efficacy of the synapse @ " + str(frate) + " Hz firing") show()
def main(): """ Simulate pre and post Poisson firing for a synapse with Ca plasticity of Graupner and Brunel 2012. See the trace over time (lifetime) for the synaptic efficacy, similar to figure 2A of Higgins, Graupner, Brunel, 2014. Author: Aditya Gilra, NCBS, Bangalore, October, 2014. """ prePoisson = moose.RandSpike('/pre') prePoisson.rate = frate postPoisson = moose.RandSpike('/post') postPoisson.rate = frate syn = moose.GraupnerBrunel2012CaPlasticitySynHandler( '/syn' ) syn.numSynapses = 1 # 1 synapse # many pre-synaptic inputs can connect to a synapse # spikes from presynaptic Poisson generator moose.connect( prePoisson,'spikeOut', syn.synapse[0], 'addSpike') # post-synaptic spikes from postsynaptic Poisson generator moose.connect( postPoisson, 'spikeOut', syn, 'addPostSpike') syn.synapse[0].delay = 0.0 syn.synapse[0].weight = 1.0 # starting weight to decay from syn.CaInit = 0.0 syn.tauCa = tauCa syn.tauSyn = tauSyn syn.CaPre = CaPre syn.CaPost = CaPost syn.delayD = delayD syn.thetaD = thetaD syn.thetaP = thetaP syn.gammaD = gammaD syn.gammaP = gammaP syn.weightMax = 1.0 # bounds on the weight syn.weightMin = 0. syn.noisy = noisy syn.noiseSD = noiseSD syn.bistable = bistable # ########################################### # Setting up tables # ########################################### CaTable = moose.Table( '/plotCa', 1 ) moose.connect( CaTable, 'requestOut', syn, 'getCa') WtTable = moose.Table( '/plotWeight', 1 ) moose.connect( WtTable, 'requestOut', syn.synapse[0], 'getWeight') # ########################################### # Simulate # ########################################### dt = 1e-3 # s # moose simulation #moose.useClock( 0, '/syn', 'process' ) #moose.useClock( 1, '/pre', 'process' ) #moose.useClock( 1, '/post', 'process' ) # I think MOOSE uses a different clock than 3 for Tables # anyway, we use the default one and set all clocks to dt below #moose.useClock( 3, '/plotCa', 'process' ) #moose.useClock( 3, '/plotWeight', 'process' ) ## use setClock to set the dt different from default dt for i in range(10): moose.setClock( i, dt ) moose.seed(100) moose.reinit() # function to make the aPlus and aMinus settle to equilibrium values print(("Rates of pre- and post-syanptic neurons =",frate)) WtSeries = [] numsteps = int(runtime/dt) for i in range(numrepeats): syn.synapse[0].weight = 1.0 # starting weight to decay from syn.Ca = 0.0 print(("Repeat number",i,"running...")) moose.start(runtime) WtSeries.append(WtTable.vector[i*numsteps:(i+1)*numsteps]) WtSeries = array(WtSeries) WtMean = mean(WtSeries,axis=0) print("plotting...") # ########################################### # Plot the simulated weights and Ca vs time # ########################################### timeseries = linspace(0.0,runtime,numsteps) # Ca plots for the synapse # only the first repeat figure(facecolor='w') plot(timeseries,CaTable.vector[:numsteps],color='r') plot((timeseries[0],timeseries[-1]),(thetaP,thetaP),color='k',\ linestyle='dashed',label='pot thresh') plot((timeseries[0],timeseries[-1]),(thetaD,thetaD),color='b',\ linestyle='dashed',label='dep thresh') legend() xlabel('time (s)') ylabel('Ca (arb)') title("Ca conc in the synapse @ "+str(frate)+" Hz firing") # Weight plots for the synapse figure(facecolor='w') for i in range(numrepeats): plot(timeseries,WtSeries[i],alpha=0.5) plot(timeseries,WtMean,color='k',linewidth=2) xlabel('time (s)') ylabel('Efficacy') title("Efficacy of the synapse @ "+str(frate)+" Hz firing") show()
def makeGlobalBalanceNetwork(): stim = moose.RandSpike('/model/stim', params['numInputs']) inhib = moose.LIF('/model/inhib', params['numInhib']) insyn = moose.SimpleSynHandler(inhib.path + '/syns', params['numInhib']) moose.connect(insyn, 'activationOut', inhib, 'activation', 'OneToOne') output = moose.LIF('/model/output', params['numOutput']) outsyn = moose.SimpleSynHandler(output.path + '/syns', params['numOutput']) moose.connect(outsyn, 'activationOut', output, 'activation', 'OneToOne') outInhSyn = moose.SimpleSynHandler(output.path + '/inhsyns', params['numOutput']) moose.connect(outInhSyn, 'activationOut', output, 'activation', 'OneToOne') iv = moose.vec(insyn.path + '/synapse') ov = moose.vec(outsyn.path + '/synapse') oiv = moose.vec(outInhSyn.path + '/synapse') temp = moose.connect(stim, 'spikeOut', iv, 'addSpike', 'Sparse') inhibMatrix = moose.element(temp) inhibMatrix.setRandomConnectivity(params['stimToInhProb'], params['stimToInhSeed']) cl = inhibMatrix.connectionList expectedCl = [ 1, 4, 13, 13, 26, 42, 52, 56, 80, 82, 95, 97, 4, 9, 0, 9, 4, 8, 0, 6, 1, 6, 6, 7 ] assert list(cl) == expectedCl, "Expected %s, got %s" % (expectedCl, cl) temp = moose.connect(stim, 'spikeOut', ov, 'addSpike', 'Sparse') excMatrix = moose.element(temp) excMatrix.setRandomConnectivity(params['stimToOutProb'], params['stimToOutSeed']) temp = moose.connect(inhib, 'spikeOut', oiv, 'addSpike', 'Sparse') negFFMatrix = moose.element(temp) negFFMatrix.setRandomConnectivity(params['inhToOutProb'], params['inhToOutSeed']) # print("ConnMtxEntries: ", inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) assert (12, 57, 48) == (inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) cl = negFFMatrix.connectionList numInhSyns = [] niv = 0 nov = 0 noiv = 0 for i in moose.vec(insyn): niv += i.synapse.num numInhSyns.append(i.synapse.num) if i.synapse.num > 0: i.synapse.weight = params['wtStimToInh'] assert numInhSyns == [2, 1, 0, 0, 2, 0, 3, 1, 1, 2] for i in moose.vec(outsyn): nov += i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtStimToOut'] for i in moose.vec(outInhSyn): noiv += i.synapse.num #print i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtInhToOut'] # print("SUMS: ", sum( iv.numField ), sum( ov.numField ), sum( oiv.numField )) assert [4, 49, 9] == [sum(iv.numField), sum(ov.numField), sum(oiv.numField)] # print("SUMS2: ", niv, nov, noiv) assert [12, 57, 48] == [niv, nov, noiv] # print("SUMS3: ", sum( insyn.vec.numSynapses ), sum( outsyn.vec.numSynapses ), sum( outInhSyn.vec.numSynapses )) assert [12, 57, 48] == [ sum(insyn.vec.numSynapses), sum(outsyn.vec.numSynapses), sum(outInhSyn.vec.numSynapses) ] # print(oiv.numField) # print(insyn.vec[1].synapse.num) # print(insyn.vec.numSynapses) # print(sum( insyn.vec.numSynapses )) # niv = iv.numSynapses # ov = iv.numSynapses sv = moose.vec(stim) sv.rate = params['randInputRate'] sv.refractT = params['randRefractTime'] #moose.showfield( sv[7] ) inhib.vec.thresh = params['inhibThresh'] inhib.vec.Rm = params['Rm'] inhib.vec.Cm = params['Cm'] inhib.vec.vReset = params['inhVreset'] inhib.vec.refractoryPeriod = params['inhibRefractTime'] output.vec.thresh = params['outputThresh'] output.vec.Rm = params['Rm'] output.vec.Cm = params['Cm'] output.vec.refractoryPeriod = params['outputRefractTime'] otab = moose.Table('/model/otab', params['numOutput']) moose.connect(otab, 'requestOut', output, 'getVm', 'OneToOne') itab = moose.Table('/model/itab', params['numInhib']) moose.connect(itab, 'requestOut', inhib, 'getVm', 'OneToOne') return inhib, output