def setupLayerInput(params, settings, populationsInput):

    numVR = params["NUM_VR"]
    numRatecodeNeurons = numVR
    spikeSourceVrResponsePath = settings["SPIKE_SOURCE_VR_RESPONSE_TRAIN"]
    spikeSourceVrResponsePathTest = settings["SPIKE_SOURCE_VR_RESPONSE_TEST"]
    spikeSourceActiveClassPath = settings["SPIKE_SOURCE_CLASS_ACTIVATIONS"]
    learning = settings["LEARNING"]

    if learning:
        # Create a population, one neuron per VR,
        # where each neuron wil be loaded with the rate code spikes for the
        # VR response over the training set
        spikeDataVR = utils.readSpikeSourceDataFile(spikeSourceVrResponsePath)
        popRateCodeSpikes = spynnaker.Population(
            numRatecodeNeurons, spynnaker.SpikeSourceArray, spikeDataVR, label="popRateCodeSpikes"
        )
        populationsInput.append(popRateCodeSpikes)

        # Create a population, one neuron per class,
        # During training the neuron representing the current class will be
        # active with significant spikes, the others will be quiet.
        #
        # The purpose is to innervate the relevant output class cluster/population
        # so that fire-together-wire-together hebbian learning (via STDP)
        # stregthens synapses from active PN clusters
        #
        # During testing all these neurons will be silent, leaving
        # the strengthened synapses to trigger activity direct from PN layer
        # in the correct output cluster.
        spikeDataClass = utils.readSpikeSourceDataFile(spikeSourceActiveClassPath)
        numNeurons = params["NUM_CLASSES"]

        popClassActivationSpikes = spynnaker.Population(
            numNeurons, spynnaker.SpikeSourceArray, spikeDataClass, label="popClassActivationSpikes"
        )

        populationsInput.append(popClassActivationSpikes)

    else:
        # Create a population, one neuron per VR,
        # where each neuron wil be loaded with the rate code spikes for
        # the VR response over the test set
        spikeDataVRTest = utils.readSpikeSourceDataFile(spikeSourceVrResponsePathTest)

        popRateCodeSpikesTest = spynnaker.Population(
            numRatecodeNeurons, spynnaker.SpikeSourceArray, spikeDataVRTest, label="popRateCodeSpikes"
        )
        populationsInput.append(popRateCodeSpikesTest)

        # create an orphan dummy popn of 1 neuron to take the place of the now
        # unused spike source pop used in learning
        # This is to ensure that the freed up core does not get co-opted by the
        # PN layer config routine
        # as this would makae the learning and testing configurations different
        # in PN which would likely make the saved PNAN weight arrays incorrect
        popClassActivationSpikes = spynnaker.Population(
            1, neuronModel, cell_params, label="dummy_popClassActivationSpikes"
        )
        populationsInput.append(popClassActivationSpikes)
Пример #2
0
def setupLayerInput(params, spikeSourceVrResponsePath, spikeSourceActiveClassPath, populationsInput,learning):
    
    
    #Create a population, one neuron per VR, 
    #where each neuron wil be loaded with the rate code spikes for the VR response over the training and/or test set
     
    spikeData = utils.readSpikeSourceDataFile(spikeSourceVrResponsePath)
    numVR = params['NUM_VR']
    numRatecodeNeurons = numVR
    popRateCodeSpikes = spynnaker.Population(numRatecodeNeurons, spynnaker.SpikeSourceArray, spikeData, label='popRateCodeSpikes')
    populationsInput.append(popRateCodeSpikes)

    if learning:
        
        #Create a population, one neuron per class, 
        #During training the neuron representing the current class will be active with significant spikes, the others will be quiet
        #The purpose is to innervate the relevant ouptut class cluster/population so that fire-together-wire-together hebbian learning (via STDP) stregthens synapses from active PN clusters
        #During testing all these neurons will be silent, leaving the strengthened synapses to trigger activity direct from PN layer in the correct ouptpu cluster
         
        spikeData = utils.readSpikeSourceDataFile(spikeSourceActiveClassPath)
        numNeurons = params['NUM_CLASSES']
        popClassActivationSpikes = spynnaker.Population(numNeurons, spynnaker.SpikeSourceArray, spikeData, label='popClassActivationSpikes')
        populationsInput.append(popClassActivationSpikes)
        
    else:
        #create an orphan dummy popn of 1 neuron to take the place of the now unused spike source pop used in learning
        #This is to ensure that the freed up core does not get co-opted by the PN layer config routine
        # as this would makae the learning and testing configurations different in PN which would likely make the saved PNAN weight arrays incorrect
        popClassActivationSpikes = spynnaker.Population(1, neuronModel, cell_params, label='dummy_popClassActivationSpikes') 
        populationsInput.append(popClassActivationSpikes)
def plot_spike_sources(filePath, fileName, nrInputNeurons, nrVR,
                         observationTime, totalSimulationTime,
                        classLabels, odourNames):
    '''Plot the Poisson spike source matrix
    Input:
        -path of the spike times file
        -name of the spike times file
        -number of input neurons (= number of sensors)
        -number of virtual receptors
        -length of the Poisson spike train for each sample
        -maximum simulation time for each recording
         (number of samples for each recording) 
         x (length of Poisson spike train for each sample)
        -class labels
        -names of the odours used
    '''
    bckndNames =[[]]*len(odourNames)
    
    spikeTimes = utils.readSpikeSourceDataFile(os.path.join(filePath,
                                                     fileName))['spike_times']
    plt.figure(figsize=(20,20))
    for idx, line in enumerate(spikeTimes):
        for x in line:
            plt.plot(x, idx, 'ko', markersize = 2)
    for j in range(idx, nrVR):
        plt.plot(0, j, 'k,')


    for j, classLabel in enumerate(classLabels):
        plt.axvspan(j*observationTime, j*observationTime+observationTime,
                     facecolor=colors[int(classLabel)], alpha=0.3)
        
    for idxO, odour in enumerate(odourNames):
        bckndNames[idxO] = mpatches.Patch(color=colors[idxO], label=odour)

    
    plt.legend(handles=bckndNames, loc ='best', prop={'size':20}) 
    plt.xlabel('Simulation time[ms]', fontsize=20)
    plt.ylabel('%i Virtual receptors per sensor'%(nrVR/nrInputNeurons),
                 fontsize=20)
    plt.tick_params(labelsize=20)
    plt.title('VR spike times for classes %s'%str(classLabels), fontsize=20)
    
    
    plt.savefig(fileName+'.pdf')

    plt.close()
def setupLayerInput(params, settings, populationsInput):

    numVR = params['NUM_VR']
    numRatecodeNeurons = numVR
    spikeSourceVrResponsePath = settings['SPIKE_SOURCE_VR_RESPONSE_TRAIN']
    spikeSourceVrResponsePathTest = settings['SPIKE_SOURCE_VR_RESPONSE_TEST']
    spikeSourceActiveClassPath = settings['SPIKE_SOURCE_CLASS_ACTIVATIONS']
    learning = settings['LEARNING']

    if learning:
        #Create a population, one neuron per VR,
        #where each neuron wil be loaded with the rate code spikes for the
        #VR response over the training set
        spikeDataVR = utils.readSpikeSourceDataFile(spikeSourceVrResponsePath)
        popRateCodeSpikes = spynnaker.Population(numRatecodeNeurons,
                                                 spynnaker.SpikeSourceArray,
                                                 spikeDataVR,
                                                 label='popRateCodeSpikes')
        populationsInput.append(popRateCodeSpikes)

        #Create a population, one neuron per class,
        #During training the neuron representing the current class will be
        #active with significant spikes, the others will be quiet.
        #
        #The purpose is to innervate the relevant output class cluster/population
        #so that fire-together-wire-together hebbian learning (via STDP)
        #stregthens synapses from active PN clusters
        #
        #During testing all these neurons will be silent, leaving
        #the strengthened synapses to trigger activity direct from PN layer
        #in the correct output cluster.
        spikeDataClass = utils.readSpikeSourceDataFile(
            spikeSourceActiveClassPath)
        numNeurons = params['NUM_CLASSES']

        popClassActivationSpikes = spynnaker.Population(
            numNeurons,
            spynnaker.SpikeSourceArray,
            spikeDataClass,
            label='popClassActivationSpikes')

        populationsInput.append(popClassActivationSpikes)

    else:
        #Create a population, one neuron per VR,
        #where each neuron wil be loaded with the rate code spikes for
        #the VR response over the test set
        spikeDataVRTest = utils.readSpikeSourceDataFile(
            spikeSourceVrResponsePathTest)

        popRateCodeSpikesTest = spynnaker.Population(
            numRatecodeNeurons,
            spynnaker.SpikeSourceArray,
            spikeDataVRTest,
            label='popRateCodeSpikes')
        populationsInput.append(popRateCodeSpikesTest)

        #create an orphan dummy popn of 1 neuron to take the place of the now
        #unused spike source pop used in learning
        #This is to ensure that the freed up core does not get co-opted by the
        #PN layer config routine
        # as this would makae the learning and testing configurations different
        #in PN which would likely make the saved PNAN weight arrays incorrect
        popClassActivationSpikes = spynnaker.Population(
            1,
            neuronModel,
            cell_params,
            label='dummy_popClassActivationSpikes')
        populationsInput.append(popClassActivationSpikes)