Пример #1
0
def plotSingleTuningCurve(dataPath, gaussianDistance, ax1=None):
    b.rcParams['font.size'] = 20
    averagingWindowSize = 1
    nE = 1600
    ymax = 1
    
    if ax1==None:
        b.figure(figsize=(8,6.5))
        fig_axis = b.subplot(1,1,1)
    else:
        fig_axis = ax1
        b.sca(ax1)
        
    path = dataPath + '/dist'+str(gaussianDistance)+'/' +'activity/'
    spikeCount = np.load(path + 'spikeCountPerExample.npy')
    spikeCountSingleNeuron = (spikeCount[:,nE/2-2,0])
    numMeasurements = len(spikeCount[:,0,0])
    
    spikeCount = movingaverage(spikeCountSingleNeuron,averagingWindowSize)
    spikeCount /= np.max(spikeCountSingleNeuron)
    b.plot(spikeCount, color='deepskyblue', marker='o', alpha=0.6, linewidth=0, label='Output')#alpha=0.5+(0.5*float(i)/float(len(lower_peaks))), 
    fig_axis.set_xticks([0., numMeasurements/2, numMeasurements])
    fig_axis.set_xticklabels(['0', '0.5', '1'])
    fig_axis.set_yticks([0., ymax/2, ymax])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
    b.ylabel('Normalized response')
    b.ylim(0,ymax+0.05)

#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.legend(loc='upper left', fancybox=True, framealpha=0.0)
        b.savefig(dataPath + '/tuningCurveSingleNeuron.png', dpi=300, bbox_inches='tight')
Пример #2
0
def plotActivity(dataPath, gaussianDistances, ax1=None):
    averagingWindowSize = 32
    
    if ax1==None:
        b.figure()
    else:
        b.sca(ax1)
        
    linewidth = 2
    for i,dist in enumerate(gaussianDistances[:]):
        path = dataPath + '/dist'+str(dist)+'/' +'activity/'
        spikeCountTemp = np.load(path + 'spikeCountPerExample.npy')
        spikeCount = spikeCountTemp[25,:,0]#np.loadtxt(path + 'spikeCountAe.txt')
#         spikeCount = np.roll(spikeCount, 400)
        inputSpikeCount = np.loadtxt(path + 'spikeCountXe.txt')
        
        spikeCount = movingaverage(spikeCount,averagingWindowSize)
        inputSpikeCount = movingaverage(inputSpikeCount,averagingWindowSize)
        if i==len(gaussianDistances)-1:
            b.plot(spikeCount, 'b', alpha=0.6, linewidth=linewidth, label='Max. dist output')#alpha=0.5+(0.5*float(i)/float(len(lower_peaks))), 
            b.plot(inputSpikeCount, 'r', alpha=1., linewidth=linewidth, label='Max. dist. input')
        elif i==0:
            b.plot(spikeCount, 'k--', alpha=0.6, linewidth=linewidth, label='Min. dist output')
            b.plot(inputSpikeCount, 'r--', alpha=1., linewidth=linewidth, label='Min. dist. input')
        else: 
            b.plot(spikeCount, 'k', alpha=0.2+(0.4*float(i)/float(len(gaussianDistances))), linewidth=0.6)
            b.plot(inputSpikeCount, 'r', alpha=0.2+(0.4*float(i)/float(len(gaussianDistances))), linewidth=0.6)
    b.ylim(0,35)

#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.legend(loc='upper left', fancybox=True, framealpha=0.0)
        b.savefig(dataPath + '/multipleAnglesActivity.png', dpi=300)
Пример #3
0
def plotHeatmap(dataPath, gaussianDistances, ax1=None):
    b.rcParams['font.size'] = 20
    if ax1==None:
        b.figure(figsize=(8,15))
    else:
        b.sca(ax1)
        
    nE = 1600
    averagingWindowSize = 32
    
    spikeCount = np.zeros((len(gaussianDistances), nE))
    for i,dist in enumerate(gaussianDistances[:]):
        path = dataPath + '/dist'+str(dist)+'/' +'activity/'
        spikeCountTemp = np.load(path + 'spikeCountPerExample.npy')
        spikeCount[i,:] = spikeCountTemp[25,:,0]#np.loadtxt(path + 'spikeCountAe.txt')
#         spikeCount[i,:] = np.roll(spikeCount[i,:], int(0.25*len(spikeCount[i,:])))
        spikeCount[i,:] = movingaverage(spikeCount[i,:], averagingWindowSize)
        spikeCount[i,:] /= np.max(spikeCount[i,:])
    
    b.imshow(spikeCount[:,:], aspect='auto', extent=[0,1,2,0])
    b.colorbar()
    b.xlabel('Neuron number (resorted)')
    b.xlabel('Neuron number (resorted)')
    
    
    if ax1==None:
        b.savefig(dataPath + '/multipleAnglesHeatmap.png', dpi=300, bbox_inches='tight')
Пример #4
0
def plotActivity(dataPath, lower_peaks, ax1=None):
    averagingWindowSize = 32
    if ax1==None:
        b.figure()
    else:
        b.sca(ax1)
    
    for i,gaussian_peak_low in enumerate(lower_peaks[:]):
        path = dataPath + '/peak_'+str(gaussian_peak_low)+'/' +'activity/'
        spikeCount = np.loadtxt(path + 'spikeCountAe.txt')
        inputSpikeCount = np.loadtxt(path + 'spikeCountXe.txt')
        
        spikeCount = movingaverage(spikeCount,averagingWindowSize)
        inputSpikeCount = movingaverage(inputSpikeCount,averagingWindowSize)
        if i==len(lower_peaks)-1:
            b.plot(spikeCount, 'k', alpha=1., linewidth=3, label='Output')#alpha=0.5+(0.5*float(i)/float(len(lower_peaks))), 
            b.plot(inputSpikeCount, 'r', alpha=1., linewidth=3, label='Input')
        elif i==0:
            b.plot(spikeCount, 'k', alpha=0.6, linewidth=3)#
            b.plot(inputSpikeCount, 'r', alpha=0.6, linewidth=3)  
        else: 
            b.plot(spikeCount, 'k', alpha=0.2+(0.4*float(i)/float(len(lower_peaks))), linewidth=0.6)
            b.plot(inputSpikeCount, 'r', alpha=0.2+(0.4*float(i)/float(len(lower_peaks))), linewidth=0.6)

    b.legend()
    b.ylim(0,35)
#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.savefig(dataPath + 'CueIntegration.png', dpi=900)
def plotActivity(dataPath, inputStrengths, ax1=None):
    averagingWindowSize = 1
    nE = 1600
    ymax = 30
#     b.rcParams['lines.color'] = 'w'
#     b.rcParams['text.color'] = 'w'
#     b.rcParams['xtick.color'] = 'w'
#     b.rcParams['ytick.color'] = 'w'
#     b.rcParams['axes.labelcolor'] = 'w'
#     b.rcParams['axes.edgecolor'] = 'w'
    b.rcParams['font.size'] = 20
    if ax1==None:
        b.figure(figsize=(8,6.5))
        fig_axis = b.subplot(1,1,1)
    else:
        fig_axis = ax1
        b.sca(ax1)
    for i,inputStrength in enumerate(inputStrengths[:]):
        path = dataPath + '/peak_'+str(inputStrength)+'/' +'activity/'
        spikeCount = np.loadtxt(path + 'spikeCountAe.txt')
        inputSpikeCount = np.loadtxt(path + 'spikeCountXe.txt')
        
        spikeCount = movingaverage(spikeCount,averagingWindowSize)
        inputSpikeCount = movingaverage(inputSpikeCount,averagingWindowSize)
        if i==len(inputStrengths)-1:
            b.plot(inputSpikeCount, 'r', alpha=1., linewidth=3, label='Input')
            b.plot(spikeCount, 'deepskyblue', alpha=0.6, linewidth=3, label='Output')#alpha=0.5+(0.5*float(i)/float(len(numPeaks))), 
#         elif i==0:
#             b.plot(spikeCount, 'k--', alpha=1., linewidth=3)#
#             b.plot(inputSpikeCount, 'r--', alpha=1., linewidth=3)  
        else: 
            b.plot(spikeCount, 'k', alpha=0.2+(0.4*float(i)/float(len(inputStrength))), linewidth=0.6)
            b.plot(inputSpikeCount, 'r', alpha=0.2+(0.4*float(i)/float(len(inputStrength))), linewidth=0.6)
    fig_axis.set_xticks([0., nE/2, nE])
    fig_axis.set_xticklabels(['0', '0.5', '1'])
    fig_axis.set_yticks([0., ymax/2, ymax])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
    b.ylabel('Firing Rate [Hz]')

    b.ylim(0,ymax)
#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))

    if ax1==None:
        b.xlabel('Neuron number (resorted)')
        b.legend(fancybox=True, framealpha=0.0, loc='upper left')
        b.savefig(dataPath + 'CueIntegration_single.png', dpi=900, transparent=True)
Пример #6
0
def plotPopulationTuningCurve(dataPath, gaussianDistance, ax1=None):
    b.rcParams['font.size'] = 20
    averagingWindowSize = 1
    nE = 1600
    ymax = 1
    
    if ax1==None:
        b.figure(figsize=(8,6.5))
        fig_axis = b.subplot(1,1,1)
    else:
        fig_axis = ax1
        b.sca(ax1)
        
    
    path = dataPath + '/dist'+str(gaussianDistance)+'/' +'activity/'
    spikeCount = np.load(path + 'spikeCountPerExample.npy')
    numMeasurements = len(spikeCount[:,0,0])
    measurementSpace = np.arange(numMeasurements)
    populationSpikeCount = np.zeros((numMeasurements))
    for i in xrange(nE):
        populationSpikeCount += np.roll(spikeCount[:,i,0], int(-1.*i/nE*numMeasurements+ numMeasurements/2))
    populationSpikeCount = movingaverage(populationSpikeCount,averagingWindowSize)
    populationSpikeCount /= np.max(populationSpikeCount)
    if gaussianDistance==0.:
        mean = sum(measurementSpace*populationSpikeCount)/numMeasurements                   #note this correction
        sigma = sum(populationSpikeCount*(measurementSpace-mean)**2)/numMeasurements        #note this correction
        popt, _ = curve_fit(gaus,measurementSpace,populationSpikeCount,p0=[1,mean,sigma])
        print 'Gaussian amplitude: ', popt[0], ', mean: ', popt[1], ', std.: ', popt[2]**2
        
        b.plot(measurementSpace,gaus(measurementSpace,*popt),'k')
    
    b.plot(populationSpikeCount, color='deepskyblue', marker='o', alpha=0.6, linewidth=0, label='Output')#alpha=0.5+(0.5*float(i)/float(len(lower_peaks))), 
    fig_axis.set_xticks([0., numMeasurements/2, numMeasurements])
    fig_axis.set_xticklabels(['0', '0.5', '1'])
    fig_axis.set_yticks([0., ymax/2, ymax])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
#     b.ylabel('Normalized response')
    b.ylim(0,ymax+0.05)

#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.legend(loc='upper left', fancybox=True, framealpha=0.0)
        b.savefig(dataPath + '/tuningCurvePopulation' + str(gaussianDistance) + '.png', dpi=300, bbox_inches='tight')
Пример #7
0
def plotActivity(dataPath, ax1=None):
    averagingWindowSize = 1
    nE = 1600
    ymax = 40
#     b.rcParams['lines.color'] = 'w'
#     b.rcParams['text.color'] = 'w'
#     b.rcParams['xtick.color'] = 'w'
#     b.rcParams['ytick.color'] = 'w'
#     b.rcParams['axes.labelcolor'] = 'w'
#     b.rcParams['axes.edgecolor'] = 'w'
    b.rcParams['font.size'] = 20
    if ax1==None:
        fig = b.figure(figsize=(8,6.5))
        fig_axis=b.subplot(1,1,1)
    else:
        fig_axis = ax1
        b.sca(ax1)
    path = dataPath + 'activity/'
    spikeCount = np.loadtxt(path + 'spikeCountCe.txt')
    popVecs = np.loadtxt(path + 'popVecs1.txt')
    desiredResult = (popVecs[0] + popVecs[1])%1.*1600
    resultMonitor = np.loadtxt(path + 'resultPopVecs1.txt')
    actualResult = resultMonitor[2]*1600
    ax1.axvline(desiredResult, color='r', linewidth=3, ymax=ymax, label='Desired result')
    ax1.axvline(actualResult, color='blue', linewidth=3, ymax=ymax, label='Population vector')
    
    print 'desiredResult', desiredResult, ', actual result', actualResult
#     spikeCount = np.roll(spikeCount, 800+int(-1*desiredResult))
    spikeCount = movingaverage(spikeCount,averagingWindowSize)
    b.plot(spikeCount, 'deepskyblue', alpha=0.6, linewidth=3, label='Population activity')
    fig_axis.set_xticks([0., nE/2, nE])
    fig_axis.set_xticklabels(['0', '0.5', '1'])
    fig_axis.set_yticks([0., ymax/2, ymax])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
    b.ylabel('Firing Rate [Hz]')

    b.ylim(0,ymax)
    b.legend(fancybox=True, framealpha=0.0, loc='upper left')
#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.xlabel('Neuron number (resorted)')
        b.savefig(dataPath + 'SignalRestoration.png', dpi=900, transparent=True)
Пример #8
0
def plotSingleActivity(dataPath, gaussianDistance, ax1=None):
    b.rcParams['font.size'] = 20
    averagingWindowSize = 30
    nE = 1600
    ymax = 1
    
    if ax1==None:
        b.figure(figsize=(8,6.5))
        fig_axis = b.subplot(1,1,1)
    else:
        fig_axis = ax1
        b.sca(ax1)
        
    linewidth = 3
    path = dataPath + '/dist'+str(gaussianDistance)+'/' +'activity/'
    spikeCountTemp = np.load(path + 'spikeCountPerExample.npy')
    spikeCount = spikeCountTemp[25,:,0]#np.loadtxt(path + 'spikeCountAe.txt')
#     spikeCount = np.roll(spikeCount, 400)
    inputSpikeCount = np.roll(np.loadtxt(path + 'spikeCountXe.txt'), 400)
    
    spikeCount = movingaverage(spikeCount,averagingWindowSize)
    spikeCount /= np.max(spikeCount)
    inputSpikeCount = movingaverage(inputSpikeCount,averagingWindowSize)
    inputSpikeCount /= np.max(inputSpikeCount)
    b.plot(spikeCount, 'deepskyblue', alpha=0.6, linewidth=linewidth, label='Output')#alpha=0.5+(0.5*float(i)/float(len(lower_peaks))), 
    b.plot(inputSpikeCount, 'r', alpha=1., linewidth=linewidth, label='Input')
    fig_axis.set_xticks([0., nE/2, nE])
    fig_axis.set_xticklabels(['0', '0.5', '1'])
    fig_axis.set_yticks([0., ymax/2, ymax])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
    b.ylabel('Normalized response')
    b.ylim(0,ymax)

#         b.title('spikes:' + str(sum(spikeCount)) + ', pop. value: ' + str(computePopVector(spikeCount)))
    if ax1==None:
        b.legend(loc='upper left', fancybox=True, framealpha=0.0)
        b.savefig(dataPath + '/multipleAnglesSingleActivity.png', dpi=300)
Пример #9
0
            result_monitor)
    np.save(data_path + 'activity/inputNumbers' + str(num_examples),
            input_numbers)

#------------------------------------------------------------------------------
# plot results
#------------------------------------------------------------------------------
if rate_monitors:
    b.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(rate_monitors):
        b.subplot(len(rate_monitors), 1, i + 1)
        b.plot(rate_monitors[name].times / b.second, rate_monitors[name].rate,
               '.')
        b.title('Rates of population ' + name)
    b.savefig('../plots/rate_monitors_' + str(n_e) + '_' + stdp_input +
              '_input_exc_weights_norm.png')

if spike_monitors:
    b.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(spike_monitors):
        b.subplot(len(spike_monitors), 1, i + 1)
        b.raster_plot(spike_monitors[name])
        b.title('Spikes of population ' + name)
    b.savefig('../plots/spike_monitors_' + str(n_e) + '_' + stdp_input +
              '_input_exc_weights_norm.png')

if spike_counters:
    b.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(spike_counters):
Пример #10
0

fi = b.figure(figsize = (5.0,4.6))
ax = plt.subplot(1,1,1)
matplotlib.rcParams.update({'font.size': 22})
b.scatter(resultMonitor[start_time:end_time,1]*1600, resultMonitor[start_time:end_time,0]*1600, c='k', cmap=cmap.gray) #range(len(error))
# b.title('Error: ' + str(correctedErrorSum))
# b.xlabel('Desired activity')
# b.ylabel('Population activity')
ax.set_xticks([0,800,1600])     
ax.set_xticklabels(['0', '800', '1600'])
ax.set_yticks([0,800,1600])     
ax.set_yticklabels(['0', '800', '1600'], va='center')
b.xlim(xmin = 0, xmax = 1600)
b.ylim(ymin = 0, ymax = 1600)
b.savefig('evaluation' + ending, dpi = 300, transparent=True)


b.figure()
b.scatter(correctedDesDiff, correctedError[1:], c=resultMonitor[start_time+1:end_time,2], cmap=cmap.gray)
b.title('Error: ' + str(correctedErrorSum))
b.xlabel('Difference from last desired activity')
b.ylabel('Error')


b.figure()
b.scatter(correctedPopDiff, correctedError[1:], c=resultMonitor[start_time+1:end_time,2], cmap=cmap.gray)
b.title('Error: ' + str(correctedErrorSum))
b.xlabel('Difference from last population activity')
b.ylabel('Error')
Пример #11
0
def plotTuningHeatmap(dataPath, gaussianDistances, ax1=None):
    b.rcParams['font.size'] = 20
#     averagingWindowSize = 1
    nE = 1600
    if ax1==None:
        b.figure(figsize=(8,15))
        fig_axis = b.subplot(1,1,1)
    else:
        b.sca(ax1)
        fig_axis=ax1
    path = dataPath + '/dist'+str(gaussianDistances[0])+'/' +'activity/'
    spikeCount = np.load(path + 'spikeCountPerExample.npy')
    numMeasurements = len(spikeCount[:,0,0])
    measurementSpace = np.arange(numMeasurements)
    populationSpikeCount = np.zeros((numMeasurements, len(gaussianDistances)))
        
    for i,gaussianDistance in enumerate(gaussianDistances):
#         distanceAngle = gaussianDistance * 2 * 360
        path = dataPath + '/dist'+str(gaussianDistance)+'/' +'activity/'
        spikeCount = np.load(path + 'spikeCountPerExample.npy')
        for j in xrange(nE):
            populationSpikeCount[:,i] += np.roll(spikeCount[:,j,0], int(-1.*j/nE*numMeasurements+ numMeasurements/2))
#         j = 0
#         populationSpikeCount[:,i] += np.roll(spikeCount[:,j,0], int(-1.*j/nE*numMeasurements+ numMeasurements/2))
#         populationSpikeCount[:,i] = movingaverage(populationSpikeCount[:,i],averagingWindowSize)
        populationSpikeCount[:,i] /= np.max(populationSpikeCount[:,i])
        
        if gaussianDistance==0.:
            mean = sum(measurementSpace*populationSpikeCount[:,i])/numMeasurements                   #note this correction
            sigma = sum(populationSpikeCount[:,i]*(measurementSpace-mean)**2)/numMeasurements        #note this correction
            popt, _ = curve_fit(gaus,measurementSpace,populationSpikeCount[:,i],p0=[1,mean,sigma])
#             tuningWidth = abs(popt[2])*2
            tuningWidth = np.sum(populationSpikeCount>=0.5)
            tuningWidthAngle = tuningWidth/50.*360.
            print 'Gaussian amplitude:', popt[0], 'mean:', popt[1], 'std.:', popt[2], \
                ', tuning width:', tuningWidth, ', tuning width angle:', tuningWidthAngle
        
        
        
    minX = max(0,round(numMeasurements/2-tuningWidth*2))
    maxX = min(numMeasurements, round(numMeasurements/2+tuningWidth*2))
    minY = round(0)
    maxY = round(tuningWidth/50.*len(gaussianDistances)*2*2)
    print minX, maxX, minY, maxY
    croppedCount = populationSpikeCount[minX:maxX,minY:maxY]
    fig_axis.imshow(croppedCount.transpose(), aspect='auto', 
                    extent=[minX, maxX, 2, 0])
#     b.colorbar()
    fig_axis.set_xlabel('Distance from preferred stimulus, \ndivided by tuning width')
    fig_axis.set_xticks([numMeasurements/2-tuningWidth*2, numMeasurements/2-tuningWidth, 
                         numMeasurements/2, numMeasurements/2+tuningWidth, numMeasurements/2+tuningWidth*2])
    fig_axis.set_xticklabels(['-2', '-1', '0', '1', '2'])
    fig_axis.set_yticks([0., 0.5, 1, 1.5, 2])
    fig_axis.spines['top'].set_visible(False)
    fig_axis.spines['right'].set_visible(False)
    fig_axis.spines['bottom'].set_visible(False)
    fig_axis.spines['left'].set_visible(False)
    fig_axis.get_xaxis().tick_bottom()
    fig_axis.get_yaxis().tick_left()
    
    if ax1==None:
        b.savefig(dataPath + '/tuningHeatmap.png', dpi=300, bbox_inches='tight')
    
    return tuningWidthAngle