def setupLayerAN(params, settings, neuronModel, cell_params, popClassActivation, popPoissionNoiseSource, populationsPN, populationsAN,learning,projectionsPNAN): #create an Association Neuron AN cluster population per class #this will be fed by: #1) PN clusters via plastic synapses #2) Class activation to innervate the correct AN cluster for a given input #3) laterally inhibit between AN clusters numClasses = params['NUM_CLASSES'] anClusterSize = int(params['CLUSTER_SIZE']) #* params['NETWORK_SCALE'] for an in range(numClasses): popName = 'popClusterAN_' + str(an) ; popClusterAN = spynnaker.Population(anClusterSize, neuronModel, cell_params, label=popName) populationsAN.append(popClusterAN) #connect neurons in every PN popn to x% (e.g 50%) neurons in this AN cluster for pn in range(len(populationsPN)): if learning: projLabel = 'Proj_PN' + str(pn) + '_AN' + str(an) projClusterPNToClusterAN = connectClusterPNtoAN(params,populationsPN[pn],popClusterAN,float(settings['OBSERVATION_EXPOSURE_TIME_MS']),projLabel) projectionsPNAN.append(projClusterPNToClusterAN) #keep handle to use later for saving off weights at end of learning else: #Without plasticity, create PNAN FromList connectors using weights saved during learning stage connections = utils.loadListFromFile(getWeightsFilename(settings,'PNAN',pn,an)) #print 'Loaded weightsList[',pn,',',an,']',connections tupleList = utils.createListOfTuples(connections) #new version only accepts list of tuples not list of lists #print 'tupleList[',pn,',',an,']',tupleList conn = spynnaker.FromListConnector(tupleList) projClusterPNToClusterAN = spynnaker.Projection(populationsPN[pn], popClusterAN,conn, target='excitatory') if learning: #use the class activity input neurons to create correlated activity during learining in the corresponding class cluster weight = params['WEIGHT_CLASS_EXCITATION_TO_CLUSTER_AN'] connections = utils.fromList_SpecificNeuronToAll(an,anClusterSize,weight,params['MIN_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN'],params['MAX_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN']) projClassActivityToClusterAN = spynnaker.Projection(popClassActivation, popClusterAN, spynnaker.FromListConnector(connections), target='excitatory') else: #testing #send spikes on these outputs back to correct host port , these will be used to determine winner etc anHostReceivePort = int(settings['AN_HOST_RECEIVE_PORT']) ExternalDevices.activate_live_output_for(popClusterAN,port=anHostReceivePort) #connect each AN cluster to inhibit every other AN cluster utils.createInterPopulationWTA(populationsAN,params['WEIGHT_WTA_AN_AN'],params['DELAY_WTA_AN_AN'],float(params['CONNECTIVITY_WTA_AN_AN'])) #inhibit other non-corresponding class clusters if learning: weight = params['WEIGHT_CLASS_INHIBITION_TO_CLUSTER_AN'] for activeCls in range(numClasses): connections = utils.fromList_SpecificNeuronToAll(activeCls,anClusterSize,weight,params['MIN_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN'],params['MAX_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN']) for an in range(numClasses): if an != activeCls: projClassActivityToClusterAN = spynnaker.Projection(popClassActivation, populationsAN[an], spynnaker.FromListConnector(connections), target='inhibitory')
def setupLayerAN(params, settings, neuronModel, cell_params, popClassActivation, popPoissionNoiseSource, populationsPN, populationsAN,learning,projectionsPNAN): #create an Association Neuron AN cluster population per class #this will be fed by: #1) PN clusters via plastic synapses #2) Class activation to innervate the correct AN cluster for a given input #3) laterally inhibit between AN clusters numClasses = params['NUM_CLASSES'] anClusterSize = params['CLUSTER_SIZE'] * params['NETWORK_SCALE'] for an in range(numClasses): popName = 'popClusterAN_' + str(an) ; popClusterAN = spynnaker.Population(anClusterSize, neuronModel, cell_params, label=popName) populationsAN.append(popClusterAN) #connect neurons in every PN popn to x% (e.g 50%) neurons in this AN cluster for pn in range(len(populationsPN)): if learning: projLabel = 'Proj_PN' + str(pn) + '_AN' + str(an) projClusterPNToClusterAN = connectClusterPNtoAN(params,populationsPN[pn],popClusterAN,projLabel) projectionsPNAN.append(projClusterPNToClusterAN) #keep handle to use later for saving off weights at end of learning else: #Without plasticity, create PNAN FromList connectors using weights saved during learning stage connections = utils.loadListFromFile(getWeightsFilename(settings,'PNAN',pn,an)) #print 'Loaded weightsList[',pn,',',an,']',connections projClusterPNToClusterAN = spynnaker.Projection(populationsPN[pn], popClusterAN,spynnaker.FromListConnector(connections), target='excitatory') if learning: #use the class activity input neurons to create correlated activity during learining in the corresponding class cluster weight = params['WEIGHT_CLASS_ACTIVITY_TO_CLUSTER_AN'] connections = utils.fromList_SpecificNeuronToAll(an,anClusterSize,weight,params['MIN_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN'],params['MAX_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN']) projClassActivityToClusterAN = spynnaker.Projection(popClassActivation, popClusterAN, spynnaker.FromListConnector(connections), target='excitatory') #connect each AN cluster to inhibit every other AN cluster utils.createInterPopulationWTA(populationsAN,params['WEIGHT_WTA_AN_AN'],params['DELAY_WTA_AN_AN'],float(params['CONNECTIVITY_WTA_AN_AN']))
def calculateWinnersAN(settings,populationsAN): numClasses = len(populationsAN) numObservations = settings['NUM_OBSERVATIONS'] observationExposureTimeMs = float(settings['OBSERVATION_EXPOSURE_TIME_MS']) #classActivationExposureFraction = settings['CLASS_ACTIVATION_EXPOSURE_FRACTION'] #set up lists to hold highest spike count and current winning class so far for each observation winningSpikeCount = [0] * numObservations winningClass = [-1] * numObservations spikeInputStartMs = 10000.0 #set spike count window to most , not all the exposure time allSpikesByClass = list() ''' This approach is faling during Test. There are much earlier ghost spikes in AN Try setting up mini pop fed by all of spike injection neurons with strong weigting. Any true injected spikes will trigger this pop, use it to mark start of true input ''' #we don't know when first live input spikes will appear as the model takes a varying amount of time to startup #assume that first spike in whole AN layer is very close to the start of input from the spike sender #Go thorugh all AN spikes and mark the earliest for cls in range(numClasses): allSpikes = populationsAN[cls].getSpikes(compatible_output=True) allSpikesByClass.append(allSpikes) spikeTimeMs = utils.getFirstSpikeTime(allSpikes) if spikeTimeMs < spikeInputStartMs: spikeInputStartMs = spikeTimeMs print 'class ' , cls, 'spikeInputStartMs updated to ' , spikeInputStartMs presentationStartTimes = utils.loadListFromFile("PresentationTimes.txt") print 'Loaded presentation times from file:', presentationStartTimes for cls in range(numClasses): allSpikes = allSpikesByClass[cls] #get ptr to spikes extracted for this class over whole duration for observation in range(numObservations): observationStartMs = presentationStartTimes[observation] ''' #don't set to whole observationExposureTimeMs because first spike may not be right at the start therefore could catch spikes from next observation observationWindowMs = float(0.9 * observationExposureTimeMs) offsetMs = spikeInputStartMs + 0.5 * (observationExposureTimeMs-observationWindowMs) startMs = offsetMs + (observation * observationExposureTimeMs) ''' startMs = spikeInputStartMs + observationStartMs endMs = startMs + observationExposureTimeMs observationSpikes = utils.getSpikesBetween(startMs,endMs,allSpikes) spikeCount= observationSpikes.shape[0] print 'Observation:', observation, 'StartMs:', startMs, 'EndMs:', endMs, 'Class:' , cls, 'Spikes:' , spikeCount if spikeCount > winningSpikeCount[observation]: winningSpikeCount[observation] = spikeCount winningClass[observation] = cls print 'Winning Class for each observation:' print winningClass return winningClass