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 setupLayerPN(params, neuronModel, cell_params, populationsRN, populationsPN): # create a projection neuron PN cluster population per VR # this will be fed by the equivalent RN population and will laterally # inhibit between clusters numVR = int(params["NUM_VR"]) # print 'PN layer, no. VR: ' , numVR pnClusterSize = int(params["CLUSTER_SIZE"] * params["NETWORK_SCALE"]) maxNeuronsPerCore = int(params["MAX_NEURONS_PER_CORE"]) maxVrPerPop = maxNeuronsPerCore / pnClusterSize # how many cores were needed to accomodate RN layer (1 pynn pop in this case) numCoresRN = utils.coresRequired(populationsRN, maxNeuronsPerCore) # print 'The RN layer is taking up ', numCoresRN, ' cores' coresAvailablePN = int( params["CORES_ON_BOARD"] - params["NUM_CLASSES"] - numCoresRN - 3 ) # 2 x input, 1 x noise source # print 'PN layer, no. cores available:' , coresAvailablePN vrPerPop = int(ceil(float(numVR) / float(coresAvailablePN))) if vrPerPop > maxVrPerPop: print "The number of VR and/or cluster size stipulated for \ this model are too a large for the capacity of this board." quit # print 'PN layer, no. VRs per population will be: ', vrPerPop pnPopSize = pnClusterSize * vrPerPop # print 'PN layer, neurons per population will be: ', pnPopSize numPopPN = int(ceil(float(numVR) / float(vrPerPop))) # print 'PN layer, number of populations(cores) used will be: ', numPopPN # print 'PN layer, spare (unused) cores : ', coresAvailablePN - numPopPN weightPNPN = float(params["WEIGHT_WTA_PN_PN"]) delayPNPN = int(params["DELAY_WTA_PN_PN"]) connectivityPNPN = float(params["CONNECTIVITY_WTA_PN_PN"]) for p in range(numPopPN): popName = "popPN_" + str(p) popPN = spynnaker.Population(pnPopSize, neuronModel, cell_params, label=popName) # print 'created population ', popName populationsPN.append(popPN) # create a FromList to feed each PN neuron in this popn from its # corresponding RN neuron in the single monolithic RN popn weightRNPN = float(params["WEIGHT_RN_PN"]) delayRNPN = int(params["DELAY_RN_PN"]) rnStartIdx = p * pnPopSize rnEndIdx = rnStartIdx + pnPopSize - 1 # The last PN popn will often have unneeded 'ghost' clusters at # the end due to imperfect dstribution of VRs among cores # As there is no RN cluster that feeds these (RN is one pop of the # correct total size) so the connections must stop at the end of RN rnMaxIdx = populationsRN[0]._size - 1 if rnEndIdx > rnMaxIdx: rnEndIdx = rnMaxIdx # clamp to the end of the RN population pnEndIdx = rnEndIdx - rnStartIdx connections = utils.fromList_OneToOne_fromRangeToRange( rnStartIdx, rnEndIdx, 0, pnEndIdx, weightRNPN, delayRNPN, delayRNPN ) projClusterRNToClusterPN = spynnaker.Projection( populationsRN[0], popPN, spynnaker.FromListConnector(connections), target="excitatory" ) # within this popn only, connect each PN sub-population VR # "cluster" to inhibit every other if vrPerPop > 1: utils.createIntraPopulationWTA(popPN, vrPerPop, weightPNPN, delayPNPN, connectivityPNPN, True) # Also connect each PN cluster to inhibit every other cluster utils.createInterPopulationWTA(populationsPN, weightPNPN, delayPNPN, connectivityPNPN)
def setupLayerPN(params, neuronModel, cell_params, populationsRN, populationsPN): #create a projection neuron PN cluster population per VR #this will be fed by the equivalent RN population and will laterally #inhibit between clusters numVR = int(params['NUM_VR']) #print 'PN layer, no. VR: ' , numVR pnClusterSize = int(params['CLUSTER_SIZE'] * params['NETWORK_SCALE']) maxNeuronsPerCore = int(params['MAX_NEURONS_PER_CORE']) maxVrPerPop = maxNeuronsPerCore / pnClusterSize #how many cores were needed to accomodate RN layer (1 pynn pop in this case) numCoresRN = utils.coresRequired(populationsRN, maxNeuronsPerCore) #print 'The RN layer is taking up ', numCoresRN, ' cores' coresAvailablePN = int(params['CORES_ON_BOARD'] - params['NUM_CLASSES'] - numCoresRN - 3) # 2 x input, 1 x noise source #print 'PN layer, no. cores available:' , coresAvailablePN vrPerPop = int(ceil(float(numVR) / float(coresAvailablePN))) if vrPerPop > maxVrPerPop: print 'The number of VR and/or cluster size stipulated for \ this model are too a large for the capacity of this board.' quit #print 'PN layer, no. VRs per population will be: ', vrPerPop pnPopSize = pnClusterSize * vrPerPop #print 'PN layer, neurons per population will be: ', pnPopSize numPopPN = int(ceil(float(numVR) / float(vrPerPop))) #print 'PN layer, number of populations(cores) used will be: ', numPopPN #print 'PN layer, spare (unused) cores : ', coresAvailablePN - numPopPN weightPNPN = float(params['WEIGHT_WTA_PN_PN']) delayPNPN = int(params['DELAY_WTA_PN_PN']) connectivityPNPN = float(params['CONNECTIVITY_WTA_PN_PN']) for p in range(numPopPN): popName = 'popPN_' + str(p) popPN = spynnaker.Population(pnPopSize, neuronModel, cell_params, label=popName) #print 'created population ', popName populationsPN.append(popPN) #create a FromList to feed each PN neuron in this popn from its #corresponding RN neuron in the single monolithic RN popn weightRNPN = float(params['WEIGHT_RN_PN']) delayRNPN = int(params['DELAY_RN_PN']) rnStartIdx = p * pnPopSize rnEndIdx = rnStartIdx + pnPopSize - 1 # The last PN popn will often have unneeded 'ghost' clusters at #the end due to imperfect dstribution of VRs among cores # As there is no RN cluster that feeds these (RN is one pop of the #correct total size) so the connections must stop at the end of RN rnMaxIdx = populationsRN[0]._size - 1 if rnEndIdx > rnMaxIdx: rnEndIdx = rnMaxIdx #clamp to the end of the RN population pnEndIdx = rnEndIdx - rnStartIdx connections = utils.fromList_OneToOne_fromRangeToRange( rnStartIdx, rnEndIdx, 0, pnEndIdx, weightRNPN, delayRNPN, delayRNPN) projClusterRNToClusterPN = spynnaker.Projection( populationsRN[0], popPN, spynnaker.FromListConnector(connections), target='excitatory') #within this popn only, connect each PN sub-population VR #"cluster" to inhibit every other if vrPerPop > 1: utils.createIntraPopulationWTA(popPN, vrPerPop, weightPNPN, delayPNPN, connectivityPNPN, True) #Also connect each PN cluster to inhibit every other cluster utils.createInterPopulationWTA(populationsPN, weightPNPN, delayPNPN, connectivityPNPN)