def compareSpikesToMembrane(duration): """ Tests the precise timing of digital spikes and spikes extracted from the membrane potential. The neuron is stimulated with Poisson spike sources. """ np.random.seed(int(time.time())) neuronNo = np.random.random_integers(0, 191) print 'Using neuron number', neuronNo poissonParams = {'start': 100.0, 'duration': duration - 100.0, 'rate': 30.0} # offset of 100 ms to get all spikes weightExc = 4 # digital hardware value weightInh = 15 # digital hardware value freqLimit = 1.0 # 1/s meanLimit = 0.2 # ms stdLimit = 0.2 # ms import pyNN.hardware.spikey as pynn pynn.setup(mappingOffset=neuronNo) stimExc = pynn.Population(64, pynn.SpikeSourcePoisson, poissonParams) stimInh = pynn.Population(192, pynn.SpikeSourcePoisson, poissonParams) neuron = pynn.Population(1, pynn.IF_facets_hardware1) prj = pynn.Projection(stimExc, neuron, pynn.AllToAllConnector( weights=weightExc * pynn.minExcWeight()), target='excitatory') prj = pynn.Projection(stimInh, neuron, pynn.AllToAllConnector( weights=weightInh * pynn.minInhWeight()), target='inhibitory') neuron.record() pynn.record_v(neuron[0], '') pynn.run(duration) spikes = neuron.getSpikes()[:, 1] membrane = pynn.membraneOutput memTime = pynn.timeMembraneOutput spikesMem, deriv, thresh = spikesFromMem(memTime, membrane) pynn.end() #plot(memTime, membrane, spikes, spikesMem, deriv, thresh) print 'Spikes and spikes on membrane:', len(spikes), '/', len(spikesMem) assert len(spikes) / duration * 1e3 >= freqLimit, 'Too less spikes.' assert len(spikes) == len(spikesMem), 'Spikes do not match membrane.' spikesDiff = spikesMem - spikes spikesDiffMean = np.mean(spikesDiff) spikesDiffStd = np.std(spikesDiff) print 'Offset between spikes and membrane:', spikesDiffMean, '+-', spikesDiffStd assert spikesDiffMean < meanLimit, 'Spike and membrane have too large offset.' assert spikesDiffStd < stdLimit, 'Time axes of spikes and membrane are different.'
def test_poisson(): """Test with Poisson source.""" import pyNN.hardware.spikey as pynn duration = 1000.0 # ms rate = 5000.0 # 1/s poissonParam = {'start': 0, 'duration': duration, 'rate': rate} limLost = 1.0 # % pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent, %lost)', lost, sent, float( lost) / sent * 1e2 assert float(lost) / sent * 1e2 < limLost, 'Too many spikes lost!' pynn.end()
def testRegularMaxPacked(): '''Maximum rate with packing: Each clock cycle a full (filled with 3 spikes) spike packet.''' import numpy as np import pyNN.hardware.spikey as pynn duration = 10000.0 # ms h = 1e3 / 5000.0 / 2.0 # 10kHz for each of 3 sources = 30kHz spikeTimes = np.arange(0, duration + h / 2.0, h) pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) stim[0].set_parameters(spike_times=spikeTimes) stim[63].set_parameters(spike_times=spikeTimes) stim[127].set_parameters(spike_times=spikeTimes) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) print 'no out spikes:', len(neuron.getSpikes()) lost, sent = pynn.getInputSpikes() print 'no in spikes (lost, sent)', lost, sent assert lost == 0, 'there should not be any spikes lost!' pynn.end()
def test_regular(): """Maximum rate without packing: Each second clock cycle a minimal loaded (filled with 1 spikes) spike packet.""" import numpy as np import pyNN.hardware.spikey as pynn import time np.random.seed(int(time.time())) lineDriverNo = np.random.random_integers(0, 255) print 'Using line driver number', lineDriverNo duration = 1000.0 # ms h = 1e3 / 5000.0 # 0.2 ms pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) stim[lineDriverNo].set_parameters( spike_times=np.arange(0, duration + h / 2.0, h)) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent)', lost, sent assert lost == 0, 'There should not be any spikes lost!' pynn.end()
def run(noNeurons): runtime = 1000.0 import numpy as np import pyNN.hardware.spikey as pynn pynn.setup() neurons = pynn.Population(noNeurons, pynn.IF_facets_hardware1) neurons.record() stim = pynn.Population(10, pynn.SpikeSourcePoisson, { 'rate': 20.0, 'duration': runtime }) prj = pynn.Projection(stim, neurons, pynn.AllToAllConnector()) prj.setWeights(pynn.maxExcWeight()) pynn.run(runtime) spikes = neurons.getSpikes([]) # for neuron in np.unique(spikes[:,0]): # print 'neuron', int(neuron), 'has', len(spikes[spikes[:,0] == # neuron]), 'spikes' noSpikes = len(spikes) lost, sent = pynn.getInputSpikes() pynn.end() print 'no neurons / spikes in / lost / out:', noNeurons + 1, sent, lost, noSpikes return noSpikes
def test_regular_packed(): """Maximum rate with packing: Each clock cycle a full (filled with 3 spikes) spike packet.""" import numpy as np import pyNN.hardware.spikey as pynn duration = 1000.0 # ms h = 1e3 / 5000.0 / 2.0 # 0.1 ms spikeTimes = np.arange(0, duration + h / 2.0, h) pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) # spikes have to be distributed over blocks of line drivers for efficient # packing stim[0].set_parameters(spike_times=spikeTimes) stim[64].set_parameters(spike_times=spikeTimes) stim[128].set_parameters(spike_times=spikeTimes) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent)', lost, sent assert lost == 0, 'There should not be any spikes lost!' pynn.end()
def test(): '''mapping of bio index to hardware index should work for networks where not all neurons are recorded''' pynn.setup() if mappingOffset > 0: dummy = pynn.Population(mappingOffset, pynn.IF_facets_hardware1) neuronList = [] for i in range(noNeurons): neuronList.append(pynn.Population(1, pynn.IF_facets_hardware1)) neuronList[-1].record() dummy = pynn.Population(1, pynn.IF_facets_hardware1) stim = pynn.Population(1, pynn.SpikeSourcePoisson) for neuron in neuronList: pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minExcWeight())) pynn.run(1000.0) pynn.end() f = open('spikeyconfig.out') for line in f: for i in range(mappingOffset + 2 * noNeurons): if line.find('w ' + str(192 + i)) >= 0: weight = int(line.split(' ')[256 + 2 - 1]) print 192 + i, weight assert (weight == shouldPatternWeights[i] ), 'results do not fit expectation' f.close()
def test_spikey5_allneurons(): ''' Tests mapping and firing of all 384 neurons. ''' runtime = 1000.0 stimRate = 10.0 weight = 7 pynn.setup() neurons = pynn.Population(384, pynn.IF_facets_hardware1) stim = pynn.Population(10, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': stimRate }) prj = pynn.Projection( stim, neurons, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weight), target='excitatory') pynn.run(runtime) spikes = neurons.getSpikes() print 'spikes from', len(np.unique(spikes)), 'different neurons' # TODO: check for spikes from all neurons pynn.end()
def maxRuntime(runtime): '''Maximum runtime: Limited by wrap around of counter (after approx. 6600s). Can be extended to infinitly long runtimes by considering wrap around. Subtract/Add offset to in/out spike times for each wrap around.''' rate = 1.0 weight = 1.0 poissonParam = {'start': 0, 'duration': runtime, 'rate': rate} pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(1, pynn.IF_facets_hardware1) prj = pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minInhWeight() * weight), target='inhibitory') neuron.record() pynn.run(runtime) spikes = neuron.getSpikes() lost, sent = pynn.getInputSpikes() print 'spikes in / out', sent, len(spikes) pynn.end()
def maxSpikesIn(runtime): '''Maximum number of spikes that can be sent: Should be limited by memory size on FPGA board (256MB => 256x1024x1024x8/32x3 approx. 200e6 spikes).''' rate = 10.0 weight = 1.0 poissonParam = {'start': 0, 'duration': runtime, 'rate': rate} pynn.setup() stim = pynn.Population(256, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(192, pynn.IF_facets_hardware1) prj = pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minInhWeight() * weight), target='inhibitory') neuron.record() pynn.run(runtime) spikes = neuron.getSpikes() lost, sent = pynn.getInputSpikes() print 'spikes in / out', sent, len(spikes) pynn.end()
def run(lowThreshold): runtime = 1000.0 pynn.setup() # set STDP params for low threshold -> fails when vcthigh-vctlow < 0.04 if lowThreshold: pynn.hardware.hwa.setSTDPParams(0.0, default.tpcsec, default.tpcorperiod, 1.0, 1.0, 1.0, 0.98, 2.5) else: pynn.hardware.hwa.setSTDPParams(0.0, default.tpcsec, default.tpcorperiod, 1.0, 1.0, 1.0, 0.85, 2.5) neuron = pynn.Population(1, pynn.IF_facets_hardware1) spikeArray = pynn.Population(1, pynn.SpikeSourceArray) stdp_model = pynn.STDPMechanism( timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) prj = pynn.Projection( spikeArray, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * 0), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) pynn.run(runtime) pynn.end()
def emulation(doesWork): numberSynapses = 10 runtime = 1000.0 weights = range(0, numberSynapses * numberSynapses) pynn.setup() pre = pynn.Population(numberSynapses, pynn.SpikeSourcePoisson) post = pynn.Population(numberSynapses, pynn.IF_facets_hardware1) if doesWork: conn = pynn.Projection(pre, post, method=pynn.AllToAllConnector()) conn.setWeights(weights) else: conn = pynn.Projection(pre, post, method=pynn.AllToAllConnector(weights=weights)) pynn.run(runtime) pynn.end()
def build(rateIn): global neurons, stim poissonParams = {'start': 0, 'duration': runtime, 'rate': rateIn} stim = pynn.Population(32, pynn.SpikeSourcePoisson, poissonParams) neurons = pynn.Population(numNeurons, pynn.IF_facets_hardware1) pynn.Projection(stim, neurons, pynn.AllToAllConnector(weights=pynn.minExcWeight() * 5.0), target='excitatory') neurons.record()
def run_network(mappingOffset=0, neuronPermutation=[], noNeurons=-1): pynn.setup(mappingOffset=mappingOffset, neuronPermutation=neuronPermutation) if noNeurons == -1: noNeurons = 384 if pynn.getChipVersion() == 4: noNeurons = 192 a = pynn.Population(noNeurons, pynn.IF_facets_hardware1) b = pynn.Population(10, pynn.SpikeSourcePoisson) prj = pynn.Projection(b, a, method=pynn.AllToAllConnector()) pynn.run(1.0)
def emulate(): # pynn.setup(useUsbAdc=True) pynn.setup() stimI = pynn.Population(40, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': rate }) stimE = pynn.Population(20, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': rate }) neuron = pynn.Population(192, pynn.IF_facets_hardware1) prjI = pynn.Projection(stimI, neuron, pynn.AllToAllConnector(weights=weight * pynn.minInhWeight()), target='inhibitory') prjE = pynn.Projection(stimE, neuron, pynn.AllToAllConnector(weights=weight * pynn.minExcWeight()), target='excitatory') stimI.record() stimE.record() neuron.record() pynn.record_v(neuron[0], '') pynn.run(runtime) spikesInI = stimI.getSpikes() spikesInE = stimE.getSpikes() spikes = neuron.getSpikes() mem = pynn.membraneOutput print 'spikes out', len(spikes) print 'spikes in', len(spikesInI), len(spikesInE) print 'mem data points', len(mem) pynn.end()
def run(withSTDP): runtime = 1000.0 pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': 100.0}) neuron = pynn.Population(1, pynn.IF_facets_hardware1) if withSTDP: stdp_model = pynn.STDPMechanism(timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector( weights=pynn.maxExcWeight()), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) else: pynn.Projection(stim, neuron, method=pynn.AllToAllConnector( weights=pynn.maxExcWeight()), target='excitatory') pynn.run(runtime) pynn.end()
def emulation(seed, connType=0, returnValue=None): numberNeurons = 192 noInputs = 15 pynn.setup() rngPrj = pynn.random.NumpyRNG(seed=seed, parallel_safe=True) # this may not work?! neurons = pynn.Population(numberNeurons, pynn.IF_facets_hardware1) connector = None if connType == 0: connector = pynn.FixedNumberPreConnector(noInputs, weights=pynn.minExcWeight()) elif connType == 1: connector = pynn.FixedNumberPostConnector(noInputs, weights=pynn.minExcWeight()) elif connType == 2: connector = pynn.FixedProbabilityConnector(float(noInputs) / numberNeurons, weights=pynn.minExcWeight()) else: assert False, 'invalid connector type' prj = pynn.Projection(neurons, neurons, method=connector, target='inhibitory', rng=rngPrj) connList = [] for conn in prj.connections(): connList.append(conn) assert len(connList) > 0, 'no connections' assert len(connList) < numberNeurons * \ (numberNeurons - 1), 'all-to-all connection' pynn.run(1.0) pynn.end() if returnValue != None: returnValue = connList else: return connList
stimExc = pynn.Population(popSize['exc'], pynn.SpikeSourceArray, {'spike_times': stimSpikes}) # create neuron populations popCollector = {'exc': [], 'inh': []} for synType in ['exc', 'inh']: for popIndex in range(noPops): pop = pynn.Population(popSize[synType], pynn.IF_facets_hardware1, neuronParams) pop.record() popCollector[synType].append(pop) # connect stimulus pynn.Projection(stimExc, popCollector['exc'][0], pynn.FixedProbabilityConnector(p_connect=probExcExc, weights=weightStimExcExc), target='excitatory') pynn.Projection(stimExc, popCollector['inh'][0], pynn.FixedProbabilityConnector(p_connect=probExcInh, weights=weightStimExcInh), target='excitatory') # connect synfire chain populations # see figure ... in script for the illustration of the network topology # for closing the loop you need to change the for loop range # i.e. if popIndex < noPops - 1: open chain # noPops : closed chain for popIndex in range(noPops): pynn.Projection(popCollector['exc'][popIndex],
def runTest(self): import numpy as np column = 4 row = 4 n = 20 # number of spike pairs deltaTList = [-1.0, 1.0] # ms deltaTLimit = 0.3 # allowed deviation delay = 2.9 # ms (between stimulus and post) # at beginning in ms (should be larger than max deltaT) experimentOffset = 100.0 deltaTPairs = 100.0 # time between pre-post-pairs in ms noStimulators = 3 weightStimulator = 15 # weight for stimulator neurons weightMeasure = 0 # weight for measured neuron procCorrOffset = 100.0 # time after experiment until correlations are processed in ms for deltaT in deltaTList: stimulus = np.arange(experimentOffset, (n - 0.5) * deltaTPairs + experimentOffset, deltaTPairs) self.assertTrue(len(stimulus) == n) stimulusMeasure = stimulus + delay - deltaT import pyNN.hardware.spikey as pynn import hwconfig_default_s1v2 as default pynn.setup() if column > 0: pynn.Population(column, pynn.IF_facets_hardware1) # stimulated neuron neuron = pynn.Population(1, pynn.IF_facets_hardware1) spikeSourceStim = None spikeSourceMeasure = None # stimulators above measured synapse if row < noStimulators: if row > 0: dummy = pynn.Population(row, pynn.SpikeSourceArray) spikeSourceMeasure = pynn.Population( 1, pynn.SpikeSourceArray, {'spike_times': stimulusMeasure}) spikeSourceStim = pynn.Population(noStimulators, pynn.SpikeSourceArray, {'spike_times': stimulus}) # stimulators below measured synapse if row >= noStimulators: if row > noStimulators: dummy = pynn.Population(row - noStimulators, pynn.SpikeSourceArray) spikeSourceMeasure = pynn.Population( 1, pynn.SpikeSourceArray, {'spike_times': stimulusMeasure}) # connect and record stdp_model = pynn.STDPMechanism( timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) pynn.Projection( spikeSourceStim, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightStimulator), target='excitatory') prj = pynn.Projection( spikeSourceMeasure, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightMeasure), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) neuron.record() ####### # RUN # ####### # correlation flags: # 0: no weight change # 1: causal weight change # 2: anti-causal weight change pynn.hardware.hwa.setLUT( [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) lastInputSpike = np.max(np.concatenate( (stimulus, stimulusMeasure))) runtime = lastInputSpike + procCorrOffset pynn.hardware.hwa.autoSTDPFrequency = runtime print 'runtime: ' + str(runtime) + '; last input spike: ' + str( lastInputSpike) + '; STDP readout: ' + str(runtime) pynn.run(runtime) # get flag and spikes corrFlag = ( np.array(prj.getWeightsHW(readHW=True, format='list')) / pynn.minExcWeight())[0] spikes = neuron.getSpikes()[:, 1] print 'stimulus:', stimulus print 'measure:', stimulusMeasure print 'post:', spikes self.assertTrue( len(stimulusMeasure) == len(spikes), 'No proper spiking!') print 'correlation flag: ' + str(corrFlag) print 'deltaT (is / should / limit):', np.mean( spikes - stimulusMeasure), '/', deltaT, '/', deltaTLimit self.assertTrue( abs(np.mean(spikes - stimulusMeasure) - deltaT) <= deltaTLimit, 'No precise spiking!') if deltaT > 0: # causal self.assertTrue(corrFlag == 1, 'Wrong correlation flag!') else: # anti-causal self.assertTrue(corrFlag == 2, 'Wrong correlation flag!') pynn.end()
def runTest(self): with_figure = False import numpy import pyNN.hardware.spikey as pynn if with_figure: import pylab # some test parameters neuron_param_even = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': -62.0 # mV } neuron_param_uneven = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': 0.0 # mV } stim_offset = 100.0 # ms stim_isi = 500.0 # ms stim_num = 10 # Number of external input spikes stim_weight = 8.0 # in units of pyn.minExcWeight stim_pop_size = 10 # size of stimulating population duration = stim_offset + ((stim_num + 1) * stim_isi) # neuron order: {0, 2, ..., 190, 1, 3, ..., 191, 192, 193, ... 343} neuron_order = range(0, 191, 2) + range(1, 192, 2) + range(192, 384, 1) if with_figure: pynn.setup(neuronPermutation=neuron_order, useUsbAdc=True) else: pynn.setup(neuronPermutation=neuron_order) # create the population with an even hardware neuron index even_population = pynn.Population(96, pynn.IF_facets_hardware1, neuron_param_even) # create the population with an uneven hardware neuron index uneven_population = pynn.Population(96, pynn.IF_facets_hardware1, neuron_param_uneven) if with_figure: pynn.record_v(even_population[0], '') # create the external stimulus stim_times = numpy.arange(stim_offset, stim_num * stim_isi, stim_isi) stim_pop = pynn.Population(stim_pop_size, pynn.SpikeSourceArray, {'spike_times': stim_times}) # connect the external simulus stim_con = pynn.AllToAllConnector(weights=stim_weight * pynn.minExcWeight()) stim_prj_even = pynn.Projection(stim_pop, even_population, stim_con) stim_prj_uneven = pynn.Projection(stim_pop, uneven_population, stim_con) # record spikes of all involved neurons even_population.record() uneven_population.record() # run the emulation pynn.run(duration) # get the spike data pre_swap_spikes_even = even_population.getSpikes() pre_swap_spikes_uneven = uneven_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pre_swap_spikes_even, pre_swap_spikes_uneven) # swap the configurations pynn.set(even_population[0], pynn.IF_facets_hardware1, {'v_thresh': 0.0}) pynn.set(uneven_population[0], pynn.IF_facets_hardware1, {'v_thresh': -62.0}) # run the emulation pynn.run(duration) # get the spike data pst_swap_spikes_even = even_population.getSpikes() pst_swap_spikes_uneven = uneven_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pst_swap_spikes_even, pst_swap_spikes_uneven) pre_spikes_count_even = float(len(pre_swap_spikes_even[:, 0])) pre_spikes_count_uneven = float(len(pre_swap_spikes_uneven[:, 0])) pst_spikes_count_even = float(len(pst_swap_spikes_even[:, 0])) pst_spikes_count_uneven = float(len(pst_swap_spikes_uneven[:, 0])) # let's see what we've got assert (pre_spikes_count_even > 0) assert (pst_spikes_count_uneven > 0) assert (pre_spikes_count_uneven / pre_spikes_count_even < 0.01) assert (pst_spikes_count_even / pst_spikes_count_uneven < 0.01) assert (pre_spikes_count_uneven / pst_spikes_count_uneven < 0.01) assert (pst_spikes_count_even / pre_spikes_count_even < 0.01)
def runTest(self): with_figure = False import numpy import pyNN.hardware.spikey as pynn if with_figure: import pylab # some test parameters neuron_param = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': -62.0 # mV } stim_offset = 100.0 # ms stim_isi = 500.0 # ms stim_num = 10 # Number of external input spikes stim_weight = 8.0 # in units of pyn.minExcWeight stim_pop_size = 10 # size of stimulating population duration = stim_offset + ((stim_num + 1) * stim_isi) # neuron order: {0, 2, ..., 190, 1, 3, ..., 191, 192, 193, .., 383} neuron_order = range(0, 191, 2) + range(1, 192, 2) + range(192, 384, 1) if with_figure: pynn.setup(neuronPermutation=neuron_order, useUsbAdc=True) else: pynn.setup(neuronPermutation=neuron_order) # create first population with an even hardware neuron index fst_population = pynn.Population(48, pynn.IF_facets_hardware1, neuron_param) # create second population with an even hardware neuron index snd_population = pynn.Population(48, pynn.IF_facets_hardware1, neuron_param) if with_figure: pynn.record_v(fst_population[0], '') # create the external stimulus stim_times = numpy.arange(stim_offset, stim_num * stim_isi, stim_isi) stim_pop = pynn.Population(stim_pop_size, pynn.SpikeSourceArray, {'spike_times': stim_times}) # connect the external simulus stim_con = pynn.AllToAllConnector(weights=stim_weight * pynn.minExcWeight()) stim_prj_fst = pynn.Projection(stim_pop, fst_population, stim_con) stim_prj_snd = pynn.Projection(stim_pop, snd_population, stim_con) # record spikes of all involved neurons fst_population.record() snd_population.record() # run the emulation pynn.run(duration) # get the spike data pre_change_spikes_fst = fst_population.getSpikes() pre_change_spikes_snd = snd_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pre_change_spikes_fst, pre_change_spikes_snd, nrn_idx_lim=[0, 96]) # change the configuration for the first group # desired behaviour: change the configuration for all even neurons # "set" should be stronger than "previous setting in even/uneven group" pynn.set(fst_population[0], pynn.IF_facets_hardware1, {'v_thresh': 0.0}) # run the emulation pynn.run(duration) # get the spike data lidx_change_spikes_fst = fst_population.getSpikes() lidx_change_spikes_snd = snd_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, lidx_change_spikes_fst, lidx_change_spikes_snd, nrn_idx_lim=[0, 96]) pre_spikes_count_fst = float(len(pre_change_spikes_fst[:, 0])) pre_spikes_count_snd = float(len(pre_change_spikes_snd[:, 0])) lidx_spikes_count_fst = float(len(lidx_change_spikes_fst[:, 0])) lidx_spikes_count_snd = float(len(lidx_change_spikes_snd[:, 0])) # let's see what we've got assert (pre_spikes_count_fst > 0) assert (pre_spikes_count_snd > 0) assert (lidx_spikes_count_fst / pre_spikes_count_fst < 0.01) assert (lidx_spikes_count_snd / pre_spikes_count_snd < 0.01)
sim.Population(skipsize, sim.IF_facets_hardware1, InputNeuronParams) # now the excitatory parrot neurons parrotsE[label] = sim.Population(popsize, sim.IF_facets_hardware1, InputNeuronParams) # skip some neurons to reduce crosstalk sim.Population(skipsize, sim.IF_facets_hardware1, InputNeuronParams) # now the inhibitory parrot neurons parrotsI[label] = sim.Population(popsize, sim.IF_facets_hardware1, InputNeuronParams) # skip some neurons to reduce crosstalk sim.Population(skipsize, sim.IF_facets_hardware1, InputNeuronParams) # parrot neuron connections for label in labels[2:]: sim.Projection(populations[label], parrotsE[label], sim.AllToAllConnector(weights=15 * we), target="excitatory") sim.Projection(populations[label], parrotsI[label], sim.AllToAllConnector(weights=15 * we), target="excitatory") sim.Projection(parrotsI[label], populations[label], sim.AllToAllConnector(weights=15 * wi), target="inhibitory") sim.Projection(parrotsI[label], parrotsE[label], sim.AllToAllConnector(weights=15 * wi), target="inhibitory") # inhibitory parrots kill themselves sim.Projection(parrotsI[label],
mpl.use('Agg') import pyNN.hardware.spikey as pynn import numpy as np pynn.setup() # set resting potential over spiking threshold runtime = 1000.0 #ms popSize = 192 weight = 7.0 * pynn.minExcWeight() neuronParams = {'v_rest': -40.0} neurons = pynn.Population(popSize, pynn.IF_facets_hardware1, neuronParams) pynn.Projection(neurons, neurons, pynn.FixedNumberPreConnector(15, weights=weight), target='inhibitory') neurons.record() pynn.run(runtime) spikes = neurons.getSpikes() pynn.end() # visualize print 'mean firing rate:', round(len(spikes) / runtime / popSize * 1000.0, 1), '1/s' import matplotlib.pyplot as plt
def testNeuron(neuronNr, tau_ref_target, calibIcb=True, tries=5, workstation=None, seededParams=False): # measured tau_ref values tau = [] # failed fits failed_tries = 0 # short membrane time constant for good results tau_mem = 1.0 # ms # time interval between two subsequently stimulated spikes meanISI = 300. # ms # number of test runs for each neuron and icb value runs = 30 # seeded neuron parameters; neurons were calibrated with v_rest = -60.0 mV if seededParams: v_rest = random.randint(-70, -60) v_thresh = random.randint(-55, -50) v_reset = random.randint(-90, -85) else: v_reset = -90.0 v_rest = -65.0 v_thresh = -55.0 neuronParams = { 'v_reset': v_reset, # mV 'e_rev_I': -90.0, # mV 'v_rest': v_rest, # mV 'v_thresh': v_thresh, # mV 'g_leak': 0.2 / (tau_mem / 1000.), # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 10.0, # ms 'tau_refrac': tau_ref_target, # ms } # experiment duration duration = (runs + 1) * meanISI # stimulating population inputParameters = { 'numInputs': 10, # number of spike sources connected to observed neuron 'weight': 0.012, # uS 'weightIncrement': 0.003, # uS 'duration': duration, # ms # ms 'inputSpikes': { 'spike_times': np.arange(10, duration, meanISI) }, } # hardware setup p.setup(useUsbAdc=True, calibTauMem=True, calibVthresh=False, calibSynDrivers=False, calibIcb=calibIcb, mappingOffset=neuronNr - 192, workStationName=workstation) # observed neuron neuron = p.Population(1, p.IF_facets_hardware1, neuronParams) # stimulating population input = p.Population(inputParameters['numInputs'], p.SpikeSourceArray, inputParameters['inputSpikes']) # connect input and neuron conn = p.AllToAllConnector(allow_self_connections=False, weights=inputParameters['weight']) proj = p.Projection(input, neuron, conn, synapse_dynamics=None, target='excitatory') # record spikes and membrane potential neuron.record() p.record_v(neuron[0], '') # run experiment p.run(duration) # evaluate results spikesDig = neuron.getSpikes()[:, 1] # change weight if too few or too many spikes occured tries = 0 while tries < 5 and (len(spikesDig) < runs - 1 or len(spikesDig) > runs + 1): if len(spikesDig) < runs - 1: inputParameters['weight'] += inputParameters['weightIncrement'] print 'increasing weight to {0}, try {1}'.format( inputParameters['weight'], tries) else: inputParameters['weight'] -= inputParameters['weightIncrement'] print 'decreasing weight to {0}, try {1}'.format( inputParameters['weight'], tries) conn = p.AllToAllConnector(allow_self_connections=False, weights=inputParameters['weight']) proj = p.Projection(input, neuron, conn, synapse_dynamics=None, target='excitatory') p.run(duration) spikesDig = neuron.getSpikes()[:, 1] tries += 1 membrane = p.membraneOutput time = p.timeMembraneOutput # clean up p.end() # determine sampling bins timestep = time[1] - time[0] # detect analog spikes spikesAna, isiAna = utils.find_spikes(membrane, time, spikesDig, reportFile=reportFile) # determine refractory period from measurement of analog spikes tau_ref, tau_ref_err, doubles_spikes = utils.fit_tau_refrac( membrane, timestep, spikesAna, isiAna, noDigSpikes=len(spikesDig), debugPlot=debugPlot) return tau_ref, tau_ref_err
#stpParams = {'U': 1.4, 'tau_rec': 1.8, 'tau_facil': 0.0} runtime = 1000.0 pynn.setup(mappingOffset=column) neuron = pynn.Population(1, pynn.IF_facets_hardware1) dummy = pynn.Population(row, pynn.SpikeSourceArray, stimParams) stimulus = pynn.Population(1, pynn.SpikeSourceArray, stimParams) # enable and configure STP stp_model = pynn.TsodyksMarkramMechanism(**stpParams) pynn.Projection( stimulus, neuron, method=pynn.AllToAllConnector(weights=weight * pynn.minExcWeight()), target='excitatory', synapse_dynamics=pynn.SynapseDynamics( fast=stp_model) #hier auskommentieren ) pynn.record_v(neuron[0], '') pynn.run(runtime) membrane = np.array(zip(pynn.timeMembraneOutput, pynn.membraneOutput)) pynn.end() # plot import matplotlib.pyplot as plt plt.plot(membrane[:, 0], membrane[:, 1])
def route(connection): """ Connect synapse driver to each neuron individually and stimulate. Check other neurons for spontaneous activity. To take care of "ghost spikes", one neuron in each 64-block of neurons is stimulated. """ synDriverIndex, neuronIndexBlock = connection print 'testing route:', synDriverIndex, '->', neuronIndexBlock neuronParam = copy.copy(pynn.IF_facets_hardware1.default_parameters) neuronParam['v_thresh'] = neuronParam['v_rest'] + 10.0 neuronParam['g_leak'] = 40.0 # TODO: to avoid warnings of tau_mem calib # one neuron in each block of 64 neurons is stimulated pynn.setup() chipVersion = pynn.getChipVersion() noNeuronBlocks = 6 if chipVersion == 4: noNeuronBlocks = 3 # use only one half of chip # create stimulus if synDriverIndex > 0: stimDummy = pynn.Population(synDriverIndex, pynn.SpikeSourceArray) stim = pynn.Population(1, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': stimRate }) # create neurons neuronList = [] dummyNeuronsList = [] if neuronIndexBlock > 0: dummyNeurons = pynn.Population(neuronIndexBlock, pynn.IF_facets_hardware1, neuronParam) dummyNeurons.record() dummyNeuronsList.append(dummyNeurons) for neuronBlock in range(noNeuronBlocks): neuron = pynn.Population(1, pynn.IF_facets_hardware1, neuronParam) neuron.record() neuronList.append(neuron) if neuronBlock < noNeuronBlocks - 1: dummyNeurons = pynn.Population(63, pynn.IF_facets_hardware1, neuronParam) dummyNeurons.record() dummyNeuronsList.append(dummyNeurons) if neuronIndexBlock < 63: dummyNeurons = pynn.Population(63 - neuronIndexBlock, pynn.IF_facets_hardware1, neuronParam) dummyNeurons.record() dummyNeuronsList.append(dummyNeurons) # connect stimulus to neurons for neuron in neuronList: pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=weight * pynn.minExcWeight()), target='excitatory') pynn.run(runtime) def getRate(spikes): return len(spikes) / runtime * 1e3 rateList = [] rateDummyList = [] for neuronIndex, neuron in enumerate(neuronList): neuronIndexGlobal = neuronIndex * 64 + neuronIndexBlock spikes = neuron.getSpikes() if len(spikes) > 0: assert (neuronIndexGlobal == np.squeeze(np.unique( spikes[:, 0]))).all() rate = getRate(spikes) rateList.append([neuronIndexGlobal, rate]) for dummyNeurons in dummyNeuronsList: rateDummyList.append(getRate(dummyNeurons.getSpikes())) print 'rate neurons:', rateList print 'rate dummy neurons', rateDummyList pynn.end() # evaluate firing rates def addFail(): if not connection in failList: failList.append(connection) def didFire(rate): addFail() return 'Neurons did fire with rate ' + str(round( rate, 2)) + ' although not connected and stimulated.' def didNotFire(neuronIndexGlobal, rate): addFail() return 'Neuron ' + str( neuronIndexGlobal) + ' did fire with too low rate ' + str( round(rate, 2)) + ' although connected and stimulated.' for neuronIndexGlobal, rate in rateList: if rate < limitActive: print didNotFire(neuronIndexGlobal, rate) for rate in rateDummyList: if rate > limitSilence: print didFire(rate) # save data for collecting statistics with open(filename, 'a') as myfile: myfile.write( '%i %i %i\n' % (synDriverIndex, neuronIndexBlock, int(connection in failList)))
mappingOffset=neuronIndex, calibSynDrivers=False) #turn off calibration of synapse line drivers ##build network neurons = pynn.Population(1, pynn.IF_facets_hardware1) neurons.set({'v_thresh': 20.0}) pynn.record_v(neurons[0], '') print(synapseDriverIndex) #allocate dummy synapse drivers sending no spikes if synapseDriverIndex > 0: stimuliDummy = pynn.Population(synapseDriverIndex, pynn.SpikeSourceArray, {'spike_times': []}) prj = pynn.Projection(stimuliDummy, neurons, pynn.AllToAllConnector(weights=0), target='inhibitory') #allocate synapse driver and configure spike times stimProp = { 'spike_times': np.arange(durationInterval, runtime - durationInterval, durationInterval) } stimuli = pynn.Population(1, pynn.SpikeSourceArray, stimProp) prj = pynn.Projection(stimuli, neurons, pynn.AllToAllConnector(weights=weight * pynn.minInhWeight()), target='inhibitory') # modify properties of synapse driver
resultCollector = [] pynn.setup( calibTauMem=False) #turn off calibration of membrane time constant tau_mem #build network stimuli = pynn.Population(noStims, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': rateStim }) neurons = pynn.Population(noNeurons, pynn.IF_facets_hardware1) pynn.Projection(stimuli, neurons, pynn.FixedNumberPreConnector(noInputs, weights=weight * pynn.minExcWeight()), target='excitatory') neurons.record() #sweep over g_leak values, emulate network and record spikes for gLeakValue in gLeakList: neurons.set({'g_leak': gLeakValue}) pynn.run(runtime) resultCollector.append([ gLeakValue, old_div(float(len(neurons.getSpikes())) / noNeurons, runtime) * 1e3 ]) pynn.end() #plot results
# set up network # create neurons neuronA = pynn.Population(1, pynn.IF_facets_hardware1, neuronParams) neuronB = pynn.Population(1, pynn.IF_facets_hardware1, neuronParams) # create stimuli stimExc = pynn.Population(numExcInputs, pynn.SpikeSourcePoisson, stimParams) stimInh = pynn.Population(numInhInputs, pynn.SpikeSourcePoisson, stimParams) connExc = pynn.AllToAllConnector(weights=weightExc) connInh = pynn.AllToAllConnector(weights=weightInh) connExc_strong = pynn.FixedProbabilityConnector(p_connect=1.0, weights=weightExc * 2) # 1st neuron is stimulated by background pynn.Projection(stimExc, neuronA, connExc, target="excitatory") pynn.Projection(stimInh, neuronA, connInh, target="inhibitory") # 2nd neuron is stimulated by 1st neuron pynn.Projection(neuronA, neuronB, connExc_strong, synapse_dynamics=None, target="excitatory") # define which observables to record # spike times neuronA.record() # membrane potential pynn.record_v(neuronB[0], '') # execute the experiment pynn.run(runtime)
if row >= noStim: if row > noStim: dummy = pynn.Population(row - noStim, pynn.SpikeSourceArray) spikeSourcePlastic = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': stimulusPlastic}) assert (spikeSourceStim != None) assert (spikeSourcePlastic != None) # configure STDP stdp_model = pynn.STDPMechanism( timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) # connect stimulus pynn.Projection(spikeSourceStim, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightStim), target='excitatory') # create plastic synapse prj = pynn.Projection( spikeSourcePlastic, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightPlastic), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) neuron.record() ## custom correlation flags: ## 0: no weight change ## 1: one (or multiple) weight changes triggered by pre-post spike pairs