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')
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)
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 = 10 nE = 1600 ymax = 40 linewidth = 5 # 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 + '/in_'+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([0], 'w', label=' ')# b.plot([0], 'w', label='Avg. input 20 Hz:')# b.plot(inputSpikeCount, 'coral', alpha=0.6, linewidth=linewidth, label='Input firing rate') b.plot(spikeCount, 'deepskyblue', alpha=0.6, linewidth=linewidth, label='Output firing rate') elif i==1: b.plot([0], 'w', label=' ')# b.plot([0], 'w', label='Avg. input 6 Hz:')# b.plot(inputSpikeCount, 'red', alpha=1., linewidth=linewidth, label='Input firing rate') b.plot(spikeCount, 'blue', alpha=0.6, linewidth=linewidth, label='Output firing rate') elif i==0: b.plot([0], 'w', label='Avg. input 2 Hz:')# b.plot(inputSpikeCount, 'darkred', alpha=1., linewidth=linewidth, label='Input firing rate') b.plot(spikeCount, 'darkblue', alpha=1.0, linewidth=linewidth, label='Output firing rate') else: b.plot(spikeCount, 'k', alpha=0.2+(0.4*float(i)/float(len(inputStrengths))), linewidth=0.6) b.legend(loc='upper right', fancybox=True, framealpha=0.0, fontsize = 17) handles, labels = fig_axis.get_legend_handles_labels() # fig_axis.legend(handles[::-1], labels[::-1], loc='upper left', fancybox=True, framealpha=0.0) fig_axis.set_xticks([0., nE/2, nE]) 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.xlabel('Neuron number (resorted)') b.ylabel('Firing rate [Hz]') b.ylim(0,ymax)
def Plot(M, Mu, Mv, number): br.plot(211) #pudb.set_trace() br.plot(Mu.times / br.ms, Mu[0] / br.mvolt, label='u') br.plot((Mv.times) / br.ms, 2000 * (Mv[0] / br.mvolt) - 58000, label='v') br.plot((M.times) / br.ms, 2000 * (M[0] / br.mvolt) - 58000, label='ge') #br.plot(Mv.times/br.ms,Mv[ br.legend() br.show()
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)
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')
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)
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)
if spike_counters: b.figure(fig_num) fig_num += 1 for i, name in enumerate(spike_counters): b.subplot(len(spike_counters), 1, i) b.plot(spike_counters['Ae'].count[:]) b.title('spike count of population ' + name) if state_monitors: b.figure(fig_num) fig_num += 1 for i, name in enumerate(state_monitors): b.plot(state_monitors[name].times/b.second, state_monitors[name]['v'][0], label = name + ' v 0') # plot(state_monitors[name].times/second, state_monitors[name]['v'][5], label = name + ' 5') b.legend() b.title('membrane voltages of population ' + name) b.figure(fig_num) fig_num += 1 for i, name in enumerate(state_monitors): b.plot(state_monitors[name].times/b.second, state_monitors[name]['ge'][0], label = name + ' ge 0') b.plot(state_monitors[name].times/b.second, state_monitors[name]['gi'][0], label = name + ' gi 0') # plot(state_monitors[name].times/second, state_monitors[name]['v'][5], label = name + ' 5') b.legend() b.title('conductances of population ' + name) plot_weights = [ # 'XeAe', # 'XeAi',
def plotResults(self): #------------------------------------------------------------------------------ # plot results #------------------------------------------------------------------------------ if self.rateMonitors: b.figure() for i, name in enumerate(self.rateMonitors): b.subplot(len(self.rateMonitors), 1, i) b.plot(self.rateMonitors[name].times/b.second, self.rateMonitors[name].rate, '.') b.title('rates of population ' + name) if self.spikeMonitors: b.figure() for i, name in enumerate(self.spikeMonitors): b.subplot(len(self.spikeMonitors), 1, i) b.raster_plot(self.spikeMonitors[name]) b.title('spikes of population ' + name) if name=='Ce': timePoints = np.linspace(0+(self.singleExampleTime+self.restingTime)/(2*b.second)*1000, self.runtime/b.second*1000-(self.singleExampleTime+self.restingTime)/(2*b.second)*1000, self.numExamples) b.plot(timePoints, self.resultMonitor[:,0]*self.nE, 'g') b.plot(timePoints, self.resultMonitor[:,1]*self.nE, 'r') if self.stateMonitors: b.figure() for i, name in enumerate(self.stateMonitors): b.plot(self.stateMonitors[name].times/b.second, self.stateMonitors[name]['v'][0], label = name + ' v 0') b.legend() b.title('membrane voltages of population ' + name) b.figure() for i, name in enumerate(self.stateMonitors): b.plot(self.stateMonitors[name].times/b.second, self.stateMonitors[name]['ge'][0], label = name + ' v 0') b.legend() b.title('conductances of population ' + name) plotWeights = [ # 'XeAe', # 'XeAi', # 'AeAe', # 'AeAi', # 'AiAe', # 'AiAi', # 'BeBe', # 'BeBi', # 'BiBe', # 'BiBi', # 'CeCe', # 'CeCi', 'CiCe', # 'CiCi', # 'HeHe', # 'HeHi', # 'HiHe', # 'HiHi', 'AeHe', # 'BeHe', # 'CeHe', 'HeAe', # 'HeBe', # 'HeCe', ] for name in plotWeights: b.figure() # my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list('own2',['#f4f4f4', '#000000']) # my_cmap2 = matplotlib.colors.LinearSegmentedColormap.from_list('own2',['#000000', '#f4f4f4']) if name[1]=='e': nSrc = self.nE else: nSrc = self.nI if name[3]=='e': nTgt = self.nE else: nTgt = self.nI w_post = np.zeros((nSrc, nTgt)) connMatrix = self.connections[name][:] for i in xrange(nSrc): w_post[i, connMatrix.rowj[i]] = connMatrix.rowdata[i] im2 = b.imshow(w_post, interpolation="nearest", vmin = 0, cmap=cm.get_cmap('gist_ncar')) #my_cmap b.colorbar(im2) b.title('weights of connection' + name) if self.plotError: error = np.abs(self.resultMonitor[:,1] - self.resultMonitor[:,0]) correctionIdxs = np.where(error > 0.5)[0] correctedError = [1 - error[i] if (i in correctionIdxs) else error[i] for i in xrange(len(error))] correctedErrorSum = np.average(correctedError) b.figure() b.scatter(self.resultMonitor[:,1], self.resultMonitor[:,0], c=range(len(error)), cmap=cm.get_cmap('gray')) b.title('Error: ' + str(correctedErrorSum)) b.xlabel('Desired activity') b.ylabel('Population activity') b.figure() error = np.abs(self.resultMonitor[:,1] - self.resultMonitor[:,0]) correctionIdxs = np.where(error > 0.5)[0] correctedError = [1 - error[i] if (i in correctionIdxs) else error[i] for i in xrange(len(error))] correctedErrorSum = np.average(correctedError) b.scatter(self.resultMonitor[:,1], self.resultMonitor[:,0], c=self.resultMonitor[:,2], cmap=cm.get_cmap('gray')) b.title('Error: ' + str(correctedErrorSum)) b.xlabel('Desired activity') b.ylabel('Population activity') b.ioff() b.show()