def plot_prediction_relevance1(): plt.figure(figsize=(7.2, 2)) plt.subplots_adjust(wspace=0.4) for sigt in sg_sl: ax = plt.subplot(1, 3, sigt + 1) plt.title(titles1[sigt], fontsize=8) if (sigt == 0): plt.text(-50, 450, titles[1], fontsize=14) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.xlabel("Predicted rate[Hz]", fontsize=8) plt.ylabel("Measured rate[Hz]", fontsize=8) R2s = np.zeros(len(sg_sl)) plt.plot(np.arange(0, 400, 1), np.arange(0, 400, 1), '-', color='k') for ch in ch_sl: obser, preds = ob_fr_data[sigt][ch][:, 1], np.array(simdata[ch][sigt]) outputd.append(np.array([obser, preds]).T) #pvalue=round(stats.ranksums(np.array(simdata[ch][sigt]), #ob_fr_data[sigt][ch][:,1])[1],3) [R21, pval] = stats.pearsonr(obser, preds) print('Pvalue=' + str(pval)) space = int(len(stimuli[sigt]) / 5) R2s = np.zeros(5) for st in range(5): x = np.array(simdata[ch][sigt])[st * space:(st + 1) * space] y = ob_fr_data[sigt][ch][:, 1][st * space:(st + 1) * space] fit = alt.curve_fit(x, y) R2s[st] = alt.R2(fit[2], y) plt.plot(fit[0], fit[1], '--', linewidth=1, color=mysim.color_bf[ch][st]) plt.scatter(x, y, marker=markers[ch], color=mysim.color_bf[ch][st], s=10) avgR2 = round(np.average(R2s), 2) plt.scatter(0, 0, marker=markers[ch], color=mysim.colors[ch], s=10, label=Ttype_buf[ch] + ' ' + ' $\mathrm{R}^{2}$=' + str(avgR2) + ', P=' + str(pval)) plt.legend(loc=1, fontsize=6, edgecolor='k') if (ch == 0): plt.xticks(fyticks[0], fontsize=6) plt.yticks(fyticks[0], fontsize=6) if (ch == 1): plt.xticks(fyticks[1], fontsize=6) plt.yticks(fyticks[1], fontsize=6) if (ch == 2): plt.xticks(fyticks[2], fontsize=6) plt.yticks(fyticks[2], fontsize=6) plt.legend(loc=1, fontsize=6, edgecolor='gray')
def plot_mean_fring_rate(): plt.figure(figsize=(8, 7)) for ch in ch_sl: for sigt in sg_sl: plt.subplot(3, 3, 3 * sigt + ch + 1) if (sigt == 1) & (ch == 0): plt.ylabel('Firing rate [spikes/s]', fontsize=12) if (sigt == 2) & (ch == 1): plt.xlabel('Depth [um]', fontsize=12) if (ch == 2): plt.text(ylimts[sigt], 1 * fyticks[2][-1] / 3, titles1[sigt], rotation=90, fontsize=10) if (sigt == 0): plt.title(Ttype_buf[ch], fontsize=8) if ((ch == 0) & (sigt == 0)): plt.text(0.01, 55, titles[0], fontsize=14) for st in range(5): space = int(len(stimuli[sigt]) / 5) x = np.array(simdata[ch][sigt])[st * space:(st + 1) * space] y = ob_fr_data[sigt][ch][st * space:(st + 1) * space, 1] fit = alt.curve_fit(x, y) R2 = "{0:.3f}".format(alt.R2(fit[2], y)) plt.plot(1e6 * stimuli[3][sigt][st * space:(st + 1) * space], np.array(simdata[ch][sigt])[st * space:(st + 1) * space], linewidth=0.5, label=str(stimuli[sigt][st * space][1][0]) + ' $\mathrm{R}^{2}$=' + str(R2), c=mysim.color_bf[ch][st], marker=marker_buf[st], markerfacecolor='none', markersize=4) plt.plot(ob_fr_data[sigt][ch][st * space:(st + 1) * space, 0], ob_fr_data[sigt][ch][st * space:(st + 1) * space, 1], '--', linewidth=0.4, c='gray', marker=marker_buf[st], markerfacecolor='none', markersize=3) [R21, pvalue] = stats.pearsonr(y, x) print('Pvalue=' + str(pvalue)) plt.xscale('log') plt.xticks(fontsize=6) if (ch == 0): plt.yticks(fyticks[0], fontsize=6) if (ch == 1): plt.yticks(fyticks[1], fontsize=6) if (ch == 2): plt.yticks(fyticks[2], fontsize=6) plt.legend(loc=2, prop={'family': 'simSun', 'size': 6})
def plot_prediction_relevance(): plt.figure(figsize=(7, 6)) for ch in ch_sl: for sigt in sg_sl: plt.subplot(3, 3, 3 * ch + sigt + 1) if (sigt == 0) & (ch == 1): plt.ylabel('Observed Firing rate [Hz]', fontsize=10) if (sigt == 1) & (ch == 2): plt.xlabel('Predicted Firing rate [Hz]', fontsize=10) if (sigt == 2): plt.text(fyticks[ch][-1] * 1.05, fyticks[ch][-1] / 2, Ttype_buf[ch], fontsize=10) if (ch == 0): plt.title(titles1[sigt], fontsize=8) if ((ch == 0) & (sigt == 0)): plt.text(0.01, 60, titles[0], fontsize=14) for st in range(5): space = int(len(stimuli[sigt]) / 5) x = np.array(simdata[ch][sigt])[st * space:(st + 1) * space] y = ob_fr_data[sigt][ch][st * space:(st + 1) * space, 1] #pvalue=pvalue=round(stats.ranksums(x, y)[1],2) [R21, pvalue] = stats.pearsonr(y, x) print('Pvalue=' + str(pvalue)) fit = alt.curve_fit(x, y) R2 = round(alt.R2(fit[2], y), 2) plt.scatter(x, y, c=mysim.color_bf[ch][st], marker=marker_buf[st], s=10, label=str(stimuli[sigt][st * space][1][0]) + ' ' + ' $\mathrm{R}^{2}$=' + str(R2) + ', P=' + str(pvalue)) if (ch == 0): plt.xticks(fyticks[0], fontsize=6) plt.yticks(fyticks[0], fontsize=6) if (ch == 1): plt.xticks(fyticks[1], fontsize=6) plt.yticks(fyticks[1], fontsize=6) if (ch == 2): plt.xticks(fyticks[2], fontsize=6) plt.yticks(fyticks[2], fontsize=6) plt.legend(fontsize=6, edgecolor='gray')
def plot_prediction_relevance(): suptitles = ['MIPS', 'MIDP'] plotlabels = ['SA1, ', 'RA1, ', 'PC, '] ticks = [[0, 50, 100, 150], [0, 100, 200, 300, 400]] obdata = [ np.load('data/ob_Frate_Tdots.npy'), np.load('data/ob_MIPD_Tdots.npy') ] simdata = [ np.load('data/sim_Frate_Tdots.npy'), np.load('data/sim_MIPD_Tdots.npy') ] for sigt in [0, 1]: ax = plt.subplot(2, 2, sigt + 3) if (sigt == 0): plt.text(-50, 160, '(d)', fontsize=14) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.title(suptitles[sigt], fontsize=8) plt.xlabel('Predicted ' + suptitles[sigt], fontsize=8) plt.ylabel('Observed ' + suptitles[sigt], fontsize=8) R2s = np.zeros(3) for ch in [0, 1, 2]: x = simdata[sigt][ch][:] y = obdata[sigt][ch][:] #pvalue=round(stats.ranksums(x, y)[1],2) #print(pvalue) [R21, pval1] = stats.pearsonr(y, x) print(Ttype_buf[ch] + ' Pvalue=' + str(pval1)) fit = alt.curve_fit(x, y) R2 = "{0:.3f}".format(alt.R2(fit[2], y)) R2s[ch] = R2 plt.scatter(x, y, color='w', edgecolors=mysim.colors[ch], marker=mysim.markers[ch], s=15, label=plotlabels[ch] + ' $\mathrm{R}^{2}$=' + str(R2)) #+', P='+str(pvalue) outputd.append(np.array([y, x]).T) plt.plot(fit[0], fit[1], '--', color=mysim.colors[ch]) plt.xticks(ticks[sigt], fontsize=6) plt.yticks(ticks[sigt], fontsize=6) plt.legend(loc=2, fontsize=6, edgecolor='gray')
def plot_prediction_relevance_sine_20hz(): ch_sl = [0, 1, 2] sg_sl = [0] plt.figure(figsize=(8.1, 2.3)) plt.subplots_adjust(wspace=0.4) for ch in ch_sl: ax = plt.subplot(1, 3, ch + 1) plt.title(Ttype_buf[ch], fontsize=8) if (ch == 0): plt.text(-4, 30, '(b)', fontsize=14) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.xlabel("Predicted rate [spikes/s]", fontsize=8) plt.ylabel("Measured rate [spikes/s]", fontsize=8) for sigt in sg_sl: obser, preds = ob_fr_data[sigt][ch][:, 1], np.array(simdata[ch][sigt]) outputd.append(np.array([obser, preds]).T) #pvalue=round(stats.ranksums(np.array(simdata[ch][sigt]), # ob_fr_data[sigt][ch][:,1])[1],3) [R21, pval] = stats.pearsonr(obser, preds) print('Pvalue=' + str(pval)) space = int(len(stimuli[sigt]) / 5) for st in range(1): x = np.array(simdata[ch][sigt])[st * space:(st + 1) * space] y = ob_fr_data[sigt][ch][:, 1][st * space:(st + 1) * space] fit = alt.curve_fit(x, y) R2 = "{0:.3f}".format(alt.R2(fit[2], y)) plt.plot(fit[0], fit[1], '--', linewidth=1, color=mysim.colors[ch]) plt.scatter(x, y, marker=markers[ch], color=mysim.colors[ch], s=10, label=' $\mathrm{R}^{2}$=' + str(R2)) plt.xticks(fontsize=8) plt.yticks(fontsize=8) plt.legend(fontsize=8, edgecolor='gray')
def plot_prediction_relevance(): suptitles=['Touchsim','Our work'] plotlabels=['SA1','RA1','PC'] ticks=[[0,10,20,30],[0,10,20,30]] bensimia_rfz=np.hstack([alt.read_data('data/txtdata/bensimia_RFSIZE.txt',[2,1]),np.loadtxt('data/txtdata/bensimia_RFSIZE.txt')]) observed_rfz=np.hstack([alt.read_data('data/txtdata/observed_rF_size.txt',[1,2]),np.loadtxt('data/txtdata/observed_rF_size.txt')]) prfz=np.load('data/rfsize_probe_indent.npy') y1=[bensimia_rfz[bensimia_rfz[:,0]==1,2],bensimia_rfz[bensimia_rfz[:,0]==2,2]] y2=[observed_rfz[observed_rfz[:,0]==1,2],observed_rfz[observed_rfz[:,0]==2,2]] simdata=[y1,prfz] obdata=[y2,y2] for model in [0,1]: ax=plt.subplot(2,2,model+3) if(model==0): plt.text(33,37,'(c)',fontsize=14) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.title(suptitles[model],fontsize=8) plt.xlabel('Predicted '+'RF size',fontsize=8) plt.ylabel('Observed '+'RF size',fontsize=8) R2s=np.zeros(3) for ch in [0,1]: x=simdata[model][ch][:] y=obdata[model][ch][:] #pvalue=round(stats.ranksums(x, y)[1],3) #print(pvalue) [R21,pval1]=stats.pearsonr(y, x) print(suptitles[model]+' '+Ttype_buf[ch]+' Pvalue='+str(pval1)) fit=alt.curve_fit(x,y) R2="{0:.3f}".format(alt.R2(fit[2],y)) R2s[ch]=R2 plt.scatter(x,y,marker=mysim.markers[ch], color='w',edgecolors=mysim.colors[ch],s=20,label=plotlabels[ch]+', $\mathrm{R}^{2}$='+str(R2)) #+', P='+str(pvalue) plt.plot(fit[0],fit[1],'--',color=mysim.colors[ch]) plt.xticks(ticks[model],fontsize=6) plt.yticks(ticks[model],fontsize=6) plt.legend(fontsize=6,edgecolor='gray')
def print_gratings_spiking_trians(): ftiproi = mysim.fingertiproi #*rslib.rtm(-np.pi/2) ftiproi = np.vstack([ftiproi, ftiproi[0, :]]) #colr=['g','b','c'] plt.figure(figsize=(2, 6)) plt.subplots_adjust(hspace=0.35) buf = np.load('data/forms_one_bars.npy')[2] sres = np.load('data/one_bars_simulation_res.npy') #obdata=np.loadtxt('data/txtdata/fr_gratings.txt') obdata = np.loadtxt('Data/txtdata/one_bar_res.txt')[0:-4, :] tbuf = np.zeros([len(sres[0]), int(simT / simdt)]) ax = plt.subplot(3, 1, 1) plt.text(-5, 14, "(d)", fontsize=14) # ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.scatter(buf[:, 0], buf[:, 1], s=5, c=1e3 * buf[:, 5], marker='s', cmap=plt.cm.Greys, vmin=0, vmax=8) ''' tx,ty=np.linspace(0,width,100),height/2*np.ones(100) plt.plot(tx,ty,'k--') plt.plot(ftiproi[:,0]+width/2,ftiproi[:,1]+height/2,'y-',linewidth=1) plt.fill_between(ftiproi[:,0]+width/2,ftiproi[:,1]+height/2,facecolor='y',alpha=0.5) plt.annotate('', xy=(6*width/6,height/2), xytext=(2.5*width/4,height/2), arrowprops=dict(color='c',headwidth = 5,width = 0.05,shrink=0.00)) ''' plt.xticks([0, 2, 4, 6, 8], fontsize=8) plt.yticks([0, height / 2, height], fontsize=8) plt.ylabel("y [mm]", fontsize=8) plt.xlabel("x [mm]", fontsize=8) #recorded sites num = 10 #sel_points=np.vstack([0*np.ones(num),np.linspace(-height/2,height/2,num)]).T #ms #sel_points=np.array([[0,0]]) #mm sel_points = np.array([[0, 0]]) #ax.plot(sel_points[:,0]+width/2,sel_points[:,1]+height/2,c='k',linewidth=0, #marker='o',markersize=5,markerfacecolor='w') ax = plt.subplot(3, 1, 2) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') Aobdata = np.zeros([len(tbuf), 2]) xt = np.linspace(0, width, len(tbuf)) for i in range(len(tbuf)): sel = np.where( np.abs(xt[i] - obdata[:, 0]) == np.min(np.abs(xt[i] - obdata[:, 0])))[0][0] Aobdata[i, 0] = obdata[sel, 0] Aobdata[i, 1] = obdata[sel, 1] res = np.zeros(len(sres[0])) for ch in range(1): sel_entry = tsensors[ch].points_mapping_entrys(sel_points) for sp in range(len(tbuf)): #buf1[sp]=len(sres[ch][sp][1][sel_entry])/tsensors[ch].T st1 = int(0.6 / simdt) st2 = int(0.95 / simdt) A = (sres[ch][sp][sel_entry, st1:st2] == 0.04) A = np.sum(A) #A=A[A>0] res[sp] = np.average(A) / 0.35 #tbuf[sp,:]=sres[ch][sp][0][sel_entry,:] # sel Vf signal #res[13:35]=15 #res[40:43]=15 #res[50:53]=15 #res=np.average(tbuf,1) plt.plot(Aobdata[:, 0], res, mysim.colors[ch], label='Simulated', marker='o', markerfacecolor='none', markersize=4) plt.plot(Aobdata[:, 0], Aobdata[:, 1], 'gray', label='Recorded', marker='o', markerfacecolor='none', markersize=4) plt.yticks([0, 50, 100, 150], fontsize=8) plt.xticks([0, 2, 4, 6, 8], fontsize=8) plt.legend(loc=1, prop={'family': 'simSun', 'size': 7}) plt.xlabel("x [mm]", fontsize=8) plt.ylabel("Firing rate", fontsize=8) plt.savefig('saved_figs/gratings_firing.png', bbox_inches='tight', dpi=300) ax = plt.subplot(3, 1, 3) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') for ch in [0]: x = res y = Aobdata[:, 1] #pvalue=round(stats.ranksums(x, y)[1],2) [R21, pval] = stats.pearsonr(y, x) print(pval) fit = alt.curve_fit(x, y) R2 = "{0:.3f}".format(alt.R2(fit[2], y)) plt.scatter(x, y, color='w', edgecolors=mysim.colors[ch], marker=mysim.markers[ch], s=15, label=' $\mathrm{R}^{2}$=' + str(R2)) #+', P='+str(pvalue) outputd.append(np.array([y, x]).T) plt.plot(fit[0], fit[1], '--', color=mysim.colors[ch]) [R21, pval] = stats.pearsonr(y, x) print('Pvalue=' + str(pval)) plt.yticks([0, 20, 40, 60, 80], fontsize=8) plt.xticks([0, 20, 40, 60, 80], fontsize=8) plt.legend(loc=1, prop={'family': 'simSun', 'size': 8}) plt.xlabel("Observed Firing rate", fontsize=8) plt.ylabel("Simulated Firing rate", fontsize=8)
def plot_prediction_relevance(): plotlabels1=[str(PFs[0]),str(PFs[1]),str(PFs[2])] plotlabels2=[str(curves[0]), str(curves[1]), str(curves[2]), str(curves[3]), str(curves[4]), str(curves[5]), str(curves[6]), ] ticks=[[0,25,50,75,100],[0,10,20,30],[0,25,50,75,100]] obdata=[np.loadtxt('data/txtdata/fring_diff_cav.txt')[:,1], np.loadtxt('data/txtdata/fring_diff_cav_RA1.txt')[:,0], np.loadtxt('data/txtdata/fring_diff_distances.txt')[:,1]] simdata=[np.load('data/sim_fr_cav_SA1.npy'), np.load('data/sim_fr_cav_RA1.npy'), np.load('data/sim_fr_dis.npy')] print('Fr reponse change as a function of curvature') for ch in range(1): if(ch==0):ax=plt.subplot(3,2,5) else:ax=plt.subplot(3,2,6) #if(ch==0): plt.text(-2,160,'(e)',fontsize=14) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.xlabel('Predicted firing rate (spikes/s)',fontsize=8) plt.ylabel('Observed firing rate (spikes/s)',fontsize=8) R2s=np.zeros(len(PFs)) for sigt in range(len(PFs)): x=simdata[ch][sigt][:] y=obdata[ch][sigt*len(rads):(sigt+1)*len(rads)] #pvalue=round(stats.ranksums(x, y)[1],3) #print(pvalue) [R21,pval1]=stats.pearsonr(y, x) print(Ttype_buf[ch]+' Pvalue='+str(pval1)) fit=alt.curve_fit(x,y) R2="{0:.3f}".format(alt.R2(fit[2],y)) R2s[sigt]=R2 plt.scatter(x,y,marker=mysim.markers[sigt], color='w',edgecolors=mysim.otc1[sigt],s=20,label=plotlabels1[sigt]+'N, $\mathrm{R}^{2}$='+str(R2)) #+' P='+str(pvalue) plt.plot(fit[0],fit[1],'--',color=mysim.otc1[sigt]) plt.legend(loc=1,fontsize=6,edgecolor='k') plt.xticks(ticks[ch],fontsize=6) plt.yticks(ticks[ch],fontsize=6) plt.legend(fontsize=6,edgecolor='gray') print('Fr changing with distance under diff cavature') for ch in [2]: ax=plt.subplot(3,2,6) ax.spines['top'].set_color('None') ax.spines['right'].set_color('None') plt.xlabel('Predicted firing rate (spikes/s)',fontsize=8) plt.ylabel('Observed firing rate (spikes/s)',fontsize=8) R2s=np.zeros(len(rads)) for sigt in range(1,len(rads)): x=simdata[ch][sigt-1][:] y=obdata[ch][sigt*len(distances):(sigt+1)*len(distances)] [R21,pval1]=stats.pearsonr(y, x) print(Ttype_buf[0]+' Pvalue='+str(pval1)) fit=alt.curve_fit(x,y) R2="{0:.3f}".format(alt.R2(fit[2],y)) R2s[sigt]=R2 plt.scatter(x,y,marker=mysim.markers[sigt], color='w',edgecolors=mysim.otc1[sigt],s=20,label=plotlabels2[sigt]+'$\mathrm{m}^{-1}$, $\mathrm{R}^{2}$='+str(R2)) #+' P='+str(pvalue) plt.plot(fit[0],fit[1],'--',color=mysim.otc1[sigt]) plt.legend(loc=1,fontsize=6,edgecolor='k') plt.xticks(ticks[2],fontsize=6) plt.yticks(ticks[2],fontsize=6) plt.legend(fontsize=6,edgecolor='gray')