Пример #1
0
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')