Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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.'
Exemplo n.º 4
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()
Exemplo n.º 5
0
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
popCollector = {'exc': [], 'inh': []}
for synType in ['exc', 'inh']:
    for popIndex in range(noPops):
        pop = pynn.Population(popSize[synType], pynn.IF_facets_hardware1,
Exemplo n.º 6
0
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 = {}

# stimuli
Exemplo n.º 7
0
w = 8
k = 9


pynn.setup()

# set resting potential over spiking threshold
runtime = 1000.0 #ms
popSize = 192

# the following three parameters can be tuned for "optimal decorrelation"
#w = 12.0
#k = 18

weight = w * pynn.minInhWeight() #default 4.0
numInhPerNeuron = k #default 25
neuronParams = {
	'v_reset'   : -80.0, # mV  # default
	'e_rev_I'   : -80.0, # mV  # default
	'v_rest'    : -35.0, # mV  # for const-current emulation set to > v_thresh #-30.0 default
	'v_thresh'  : -55.0, # mV  # default
	'g_leak'    :  20.0  # nS  -> tau_mem = 0.2nF / 20nS = 10ms
}


neurons = pynn.Population(popSize, pynn.IF_facets_hardware1, neuronParams)

# the inhibitory projection of the complete population to itself, with identical number
# of presynaptic neurons. Enable after measuring the regular-firing case.
pynn.Projection(neurons, neurons, pynn.FixedNumberPreConnector(numInhPerNeuron, weights=weight), target='inhibitory')
Exemplo n.º 8
0
                                   {'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
# drvifall controls the slope of the falling edge of the PSP shape.
# smaller values increase the length, thus the total charge transmitted by the synapse, thus the PSP height.
print 'Range of calibration factors of drvifall for excitatory connections', prj.getDrvifallFactorsRange(
    'inh')
prj.setDrvifallFactors([drvifallFactors])
prj.setDrvioutFactors([drvioutFactors])

##run network
pynn.run(runtime)
mem = pynn.membraneOutput
time = pynn.timeMembraneOutput
pynn.end()
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()
        popCollector[synType].append(pop)

# connect stimulus
pynn.Projection(stimExc, popCollector['exc'][0], pynn.FixedProbabilityConnector(p_connect=probExcExc, weights=weightStimExcExc), target='excitatory')
Exemplo n.º 10
0
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()
        popCollector[synType].append(pop)

# connect stimulus
    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
Exemplo n.º 12
0
    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)