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 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 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 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
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 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 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()
import pyNN.hardware.spikey as pynn import numpy as np runtime = 500.0 # ms noPops = 9 # chain length popSize = {'exc': 10, 'inh': 10} # size of each chain link # connection probabilities probExcExc = 1.0 probExcInh = 1.0 probInhExc = 1.0 pynn.setup() # define weights in digital hardware values weightStimExcExc = 10 * pynn.minExcWeight() weightStimExcInh = 10 * pynn.minExcWeight() weightExcExc = 5 * pynn.minExcWeight() weightExcInh = 10 * pynn.minExcWeight() weightInhExc = 7 * pynn.minInhWeight() # kick starter stimSpikes = np.array([100.0]) 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)
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
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
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() ##calculate spike-triggered average of membrane potential timeNorm = time - time[0] #number of data points per interval
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 resultCollector = np.array(resultCollector)
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 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)
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)
} HiddenNeuronParams = InputNeuronParams OutNeuronParams = InputNeuronParams i1spkt = concatenate((arange(1000., 2000., 100.), arange(3000., 4000., 100.))) i2spkt = concatenate((arange(2000., 3000., 100.), arange(3000., 4000., 100.))) #################################################################### # procedural experiment description #################################################################### # necessary setup sim.setup() we = sim.minExcWeight() # wi = sim.minInhWeight() # # set up network # I want another neuron, so I need to build some dummy neurons, because sim.Population(193, sim.IF_facets_hardware1, InputNeuronParams) # create & record neurons labels = ['i1', 'i2', 'y1', 'y2', 'h1', 'h2', 'o'] popsize = 1 skipsize = 2 populations = {} parrotsE = {} parrotsI = {}
#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
noStims = 64 # number of stimuli generated on the host computer noNeurons = 32 # number of hardware neurons noInputs = 16 # number for stimuli connected to each neuron weight = 7.0 # synaptic weight in digital values rateStim = 10.0 # rate of each stimulus in 1/s runtime = 10 * 1000.0 # runtime in biological time domain in ms gLeakList = np.arange(2,251,8) # hardware range with calibTauMem turned off: [2,250] micro siemens 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, float(len(neurons.getSpikes())) / noNeurons / runtime * 1e3]) pynn.end() #plot results resultCollector = np.array(resultCollector) plt.figure() plt.plot(resultCollector[:,0], resultCollector[:,1]) plt.xlim(0, np.max(gLeakList)) plt.ylim(0, np.max(resultCollector[:,1]) * 1.05)
def emulate(self, driverIndexExc, driverIndexInh=None, drvirise=None, drvifallExc=None, drvifallInh=None, drvioutExc=None, drvioutInh=None, filename=None, calibSynDrivers=False): '''Run emulations on hardware.''' assert self.stimParams != None, 'specifiy stimulus first' pynn.setup(calibTauMem=True, calibSynDrivers=calibSynDrivers, calibVthresh=False, calibIcb=False, workStationName=self.workstation, writeConfigToFile=False) #create neuron self.neuronList.sort() neuronCollector = [] currentIndex = 0 for neuronIndex in self.neuronList: if neuronIndex > currentIndex: #insert dummy neurons if neuronList not continuous dummyPopSize = neuronIndex - currentIndex dummy = pynn.Population(dummyPopSize, pynn.IF_facets_hardware1, self.neuronParams) currentIndex += dummyPopSize self.logger.debug('inserted ' + str(dummyPopSize) + ' dummy neurons') if neuronIndex == currentIndex: neuron = pynn.Population(1, pynn.IF_facets_hardware1, self.neuronParams) currentIndex += 1 neuron.record() neuronCollector.append(neuron) else: raise Exception('Could not create all neurons') #create input and connect to neuron synDrivers = [[driverIndexExc, 'excitatory'], [driverIndexInh, 'inhibitory']] synDrivers.sort() currentIndex = 0 for synDriver in synDrivers: toInsertIndex = synDriver[0] targetType = synDriver[1] if toInsertIndex == None: self.logger.debug('skipping ' + targetType + ' stimulation') continue if toInsertIndex > currentIndex: dummyPopSize = toInsertIndex - currentIndex dummy = pynn.Population(dummyPopSize, pynn.SpikeSourcePoisson) currentIndex += dummyPopSize self.logger.debug('inserted ' + str(dummyPopSize) + ' dummy synapse drivers') stim = pynn.Population(1, pynn.SpikeSourcePoisson, self.stimParams[targetType]) self.logger.debug('inserted 1 stimulus of type ' + targetType + ' with rate ' + str(self.stimParams[targetType]['rate'])) if targetType == 'excitatory': hardwareWeightTemp = self.hardwareWeight * pynn.minExcWeight() elif targetType == 'inhibitory': hardwareWeightTemp = self.hardwareWeight * pynn.minInhWeight() else: raise Exception('Synapse type not supported!') for neuron in neuronCollector: pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=hardwareWeightTemp), target=targetType) currentIndex += 1 #set custom parameters if drvirise != None: pynn.hardware.hwa.drvirise = drvirise else: pynn.hardware.hwa.drvirise = default.drvirise if drvifallExc != None: pynn.hardware.hwa.drvifall_base['exc'] = drvifallExc else: pynn.hardware.hwa.drvifall_base['exc'] = default.drvifall_base['exc'] if drvifallInh != None: pynn.hardware.hwa.drvifall_base['inh'] = drvifallInh else: pynn.hardware.hwa.drvifall_base['inh'] = default.drvifall_base['inh'] if drvioutExc != None: pynn.hardware.hwa.drviout_base['exc'] = drvioutExc else: pynn.hardware.hwa.drviout_base['exc'] = default.drviout_base['exc'] if drvioutInh != None: pynn.hardware.hwa.drviout_base['inh'] = drvioutInh else: pynn.hardware.hwa.drviout_base['inh'] = default.drviout_base['inh'] #run pynn.run(self.runtime) #temperature = pynn.hardware.hwa.getTemperature() #self.logger.debug('temperature ' + str(temperature) + ' degree Celsius') #obtain firing rate spikes = None neuronCount = 0 for neuron in neuronCollector: spikesNeuron = neuron.getSpikes() neuronCount += neuron.size if spikes == None: spikes = spikesNeuron else: spikes = np.concatenate((spikes, spikesNeuron)) if len(spikes) > 0: spikes = spikes[spikes[:,1] > self.cutfirst] if len(spikes) > 0: spikes = spikes[spikes[:,1] <= self.runtime] if filename != None: np.savetxt(os.path.join(self.folder, filename), spikes) spikesPerNeuron = float(len(spikes)) / neuronCount pynn.end() rate = spikesPerNeuron * 1e3 / (self.runtime - self.cutfirst) return rate
""" # for plotting without X-server import matplotlib as mpl 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"
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)))
arXiv:1411.7916 [q-bio.NC]. ''' # for plotting without X-server import matplotlib as mpl 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()
weight = 15.0 stimParams = {'spike_times': np.concatenate((np.arange(100.0, 401.0, 50.0), [700.0]))} stpParams = {'U': 0.4, 'tau_rec': 100.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)) 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]) plt.xlabel('time (ms)')
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)
import pyNN.hardware.spikey as pynn import numpy as np runtime = 500.0 # ms noPops = 9 # chain length popSize = {'exc': 10, 'inh': 10} # size of each chain link # connection probabilities probExcExc = 1.0 probExcInh = 1.0 probInhExc = 1.0 pynn.setup() # define weights in digital hardware values weightStimExcExc = 10 * pynn.minExcWeight() weightStimExcInh = 10 * pynn.minExcWeight() weightExcExc = 5 * pynn.minExcWeight() weightExcInh = 10 * pynn.minExcWeight() weightInhExc = 7 * pynn.minInhWeight() # kick starter stimSpikes = np.array([100.0]) 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) pop.record()
runtime = 500.0 # ms noPops = 15 # chain length #9 popSize = {'exc': 6, 'inh': 6} # size of each chain link #exc 10, inh 10 # connection probabilities probExcExc = 1.0 probExcInh = 1.0 probInhExc = 1.0 # refractory period of neurons can be tuned for optimal synfire chain bahavior neuronParams = {'tau_refrac': 10.0} pynn.setup() # define weights in digital hardware values # --> these should be tuned first to obtain synfire chain behavior! weightStimExcExc = 12 * pynn.minExcWeight() # 12 weightStimExcInh = 12 * pynn.minExcWeight() # 12 weightExcExc = 13 * pynn.minExcWeight() # 8 weightExcInh = 14 * pynn.minExcWeight() # 10 weightInhExc = 9 * pynn.minInhWeight() # 7 # kick starter input pulse(s) #stimSpikes = np.array([100.0]) # to have several kick starter pulses, use (don't forget to reduce to first entry for closed chain): stimSpikes = np.array([100.0, 200.0, 300.0]) stimExc = pynn.Population(popSize['exc'], pynn.SpikeSourceArray, {'spike_times': stimSpikes}) # create neuron populations
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() ##calculate spike-triggered average of membrane potential timeNorm = time - time[0] #number of data points per interval