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 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_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 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 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 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 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 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 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()
weight = 7.0 # synaptic weight in digital values runtime = 10 * 1000.0 # runtime in biological time domain in ms durationInterval = 200.0 # interval between input spikes in ms neuronIndex = 42 # choose neuron on chip in range(384) synapseDriverIndex = 42 # choose synapse driver in range(256) pynn.setup(mappingOffset=neuronIndex, calibSynDrivers=False) #turn off calibration of synapse line drivers ##build network neurons = pynn.Population(1, pynn.IF_facets_hardware1) pynn.record_v(neurons[0], '') #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='excitatory') #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.minExcWeight()), target='excitatory') #modify properties of synapse driver print('Range of calibration factors of drvifall for excitatory connections', prj.getDrvifallFactorsRange('exc')) prj.setDrvifallFactors([0.8]) #prj.setDrvioutFactors([1.0]) ##run network pynn.run(runtime) mem = pynn.membraneOutput time = pynn.timeMembraneOutput pynn.end()
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)
def runTest(self): with_figure = False import numpy import pyNN.hardware.spikey as pynn if with_figure: import pylab # some test parameters weight = 12.0 # in units of pyn.minExcWeight neuron_params = { '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': -63.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 # set up the test network where pre_neuron and pst_neuron are on different # blocks #====================================================================== # pre_neuron ==> pst_neuron # # stim ==> sil_neuron #====================================================================== # there shouldn't be a connection between sil_neuron and pst_neuron neuron_order = range(0, 384, 1) if with_figure: pynn.setup(neuronPermutation=neuron_order, useUsbAdc=True) else: pynn.setup(neuronPermutation=neuron_order) # create the populations pre_neuron = pynn.Population(1, pynn.IF_facets_hardware1) sil_neuron = pynn.Population(1, pynn.IF_facets_hardware1) pst_neuron = pynn.Population(1, pynn.IF_facets_hardware1) if with_figure: pynn.record_v(pst_neuron[0], '') # create the connection pre_pst_con = pynn.AllToAllConnector(weights=weight * pynn.minExcWeight()) pre_pst_prj = pynn.Projection(pre_neuron, pst_neuron, pre_pst_con) # 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 = pynn.Projection(stim_pop, sil_neuron, stim_con) # record spikes of all involved neurons pre_neuron.record() pst_neuron.record() sil_neuron.record() # run the emulation pynn.run(stim_offset + ((stim_num + 1) * stim_isi)) if with_figure: pylab.figure() pylab.plot(pynn.timeMembraneOutput, pynn.membraneOutput) pylab.show() # let's see what we've got, accept up to 1 ghost spike assert (len(pre_neuron.getSpikes()) < 2) assert (len(pst_neuron.getSpikes()) < 2) assert (len(sil_neuron.getSpikes()) >= 10) assert (len(sil_neuron.getSpikes()) < 12)
# 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],
#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
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
def test_zero_projection(self): #====================================================================== # set up the following network and record the membrane potential of neuron0 # for three different combination of weights: # run 0: w0 = 0 | w1 = 0 # run 1: w0 = w | w1 = w # run 2: w0 = w | w1 = 0 #====================================================================== # inh weight w0 # --> neuron 0 # / # stim # \ # --> neuron 1 # inh weight w1 #====================================================================== # TODO: write test with call of connect() instead of projection as well import numpy import pyNN.hardware.spikey as pynn if self.with_figures: import pylab duration = 1000.0 # ms w = 10.0 # in units of pynn.minInhWeight stim_rate = 40.0 # Hz neuron_params = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -80.0, # mV 'e_rev_I': -80.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': 0.0 # mV // no spiking } # call setup with enabled oscilloscope pynn.setup(useUsbAdc=True) # create the populations nrn0 = pynn.Population(1, pynn.IF_facets_hardware1) nrn1 = pynn.Population(1, pynn.IF_facets_hardware1) stim_params = {'start': 0., 'duration': duration, 'rate': stim_rate} stim = pynn.Population(1, pynn.SpikeSourcePoisson, stim_params) # record the membrane potential of neuron0 pynn.record_v(nrn0[0], '') # create the connectors w_con = pynn.AllToAllConnector(weights=w * pynn.minInhWeight()) zero_con = pynn.AllToAllConnector(weights=0.0 * pynn.minInhWeight()) # run the first time nrn0_prj = pynn.Projection(stim, nrn0, zero_con, target='inhibitory') nrn1_prj = pynn.Projection(stim, nrn1, zero_con, target='inhibitory') pynn.run(duration) u_run0 = numpy.mean(pynn.membraneOutput) du_run0 = numpy.std(pynn.membraneOutput) if self.with_figures: pylab.figure() pylab.plot(pynn.timeMembraneOutput, pynn.membraneOutput) pylab.show() # second time nrn0_prj = pynn.Projection(stim, nrn0, w_con, target='inhibitory') nrn1_prj = pynn.Projection(stim, nrn1, w_con, target='inhibitory') pynn.run(duration) u_run1 = numpy.mean(pynn.membraneOutput) du_run1 = numpy.std(pynn.membraneOutput) if self.with_figures: pylab.figure() pylab.plot(pynn.timeMembraneOutput, pynn.membraneOutput) pylab.show() # third time nrn0_prj = pynn.Projection(stim, nrn0, w_con, target='inhibitory') nrn1_prj = pynn.Projection(stim, nrn1, zero_con, target='inhibitory') pynn.run(duration) u_run2 = numpy.mean(pynn.membraneOutput) du_run2 = numpy.std(pynn.membraneOutput) if self.with_figures: pylab.figure() pylab.plot(pynn.timeMembraneOutput, pynn.membraneOutput) pylab.show() # plot and evaluate if self.with_figures: x_val = numpy.arange(1, 4, 1) y_val = [u_run0, u_run1, u_run2] y_err = [du_run0, du_run1, du_run2] pylab.figure() pylab.xlim([0, 4]) pylab.xlabel("Run") pylab.ylabel("Mean membrane voltage [mV]") pylab.errorbar(x_val, y_val, yerr=y_err, fmt='o') pylab.show() assert (((u_run0 - u_run1) / du_run0) > 0.2) assert (((u_run0 - u_run2) / du_run0) > 0.2) assert (abs((u_run2 - u_run1) / du_run0) < 0.2)
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)))
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 ## 2: one (or multiple) weight changes triggered by post-pre spike pairs
# load PyNN interface for the Spikey neuromorphic hardware import pyNN.hardware.spikey as pynn # necessary setup pynn.setup() # 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
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