def calculateWinnersAN(settings, populationsAN, classLabels):
    nrObs = len(classLabels)
    numTotClasses = len(populationsAN)
    observationExposureTimeMs = settings["OBSERVATION_EXPOSURE_TIME_MS"]

    # set up lists to hold highest spike count and current winning class so
    # far for each observation
    winningSpikeCount = [0] * nrObs
    winningClass = [0] * nrObs

    for cls in range(numTotClasses):

        allSpikes = populationsAN[cls].getSpikes(compatible_output=True)
        for observation in range(nrObs):
            startMs = observation * observationExposureTimeMs
            endMs = startMs + observationExposureTimeMs
            observationSpikes = utils.getSpikesBetween(startMs, endMs, allSpikes)
            spikeCount = observationSpikes.shape[0]
            # print spikeCount
            # print 'StartMs:', startMs, 'EndMs:', endMs, 'Observation:' ,
            # observation, 'Class:' , cls, 'Spikes:' , spikeCount
            if spikeCount > winningSpikeCount[observation] and spikeCount > 500:
                winningSpikeCount[observation] = spikeCount
                winningClass[observation] = cls

    return winningClass, winningSpikeCount
def calculateWinnersAN(settings, populationsAN, classLabels):
    nrObs = len(classLabels)
    numTotClasses = len(populationsAN)
    observationExposureTimeMs = settings['OBSERVATION_EXPOSURE_TIME_MS']

    #set up lists to hold highest spike count and current winning class so
    #far for each observation
    winningSpikeCount = [0] * nrObs
    winningClass = [0] * nrObs

    for cls in range(numTotClasses):

        allSpikes = populationsAN[cls].getSpikes(compatible_output=True)
        for observation in range(nrObs):
            startMs = observation * observationExposureTimeMs
            endMs = startMs + observationExposureTimeMs
            observationSpikes = utils.getSpikesBetween(startMs, endMs,
                                                       allSpikes)
            spikeCount = observationSpikes.shape[0]
            #print spikeCount
            #print 'StartMs:', startMs, 'EndMs:', endMs, 'Observation:' ,
            #observation, 'Class:' , cls, 'Spikes:' , spikeCount
            if spikeCount > winningSpikeCount[observation] and spikeCount > 500:
                winningSpikeCount[observation] = spikeCount
                winningClass[observation] = cls

    return winningClass, winningSpikeCount
def calculateWinnersAN(settings,populationsAN):
    
    numClasses = len(populationsAN)
    numObservations = settings['NUM_OBSERVATIONS']
    observationExposureTimeMs = settings['OBSERVATION_EXPOSURE_TIME_MS']
   
    #set up lists to hold highest spike count and current winning class so far for each observation
    winningSpikeCount = [0] * numObservations
    winningClass = [-1] * numObservations

    
    for cls in range(numClasses):

        allSpikes = populationsAN[cls].getSpikes(compatible_output=True)
        for observation in range(numObservations):
 
            startMs = observation * observationExposureTimeMs
            endMs = startMs + observationExposureTimeMs
            observationSpikes = utils.getSpikesBetween(startMs,endMs,allSpikes)
            spikeCount= observationSpikes.shape[0]
            #print 'StartMs:', startMs, 'EndMs:', endMs, 'Observation:' , observation, 'Class:' , cls, 'Spikes:' , spikeCount
            if spikeCount > winningSpikeCount[observation]:
                winningSpikeCount[observation] = spikeCount
                winningClass[observation] = cls
            
    return winningClass
Exemplo n.º 4
0
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