def plot_NMDAspike(self,remakeFig=False): with open(self.datapath+'NMDAspike_latest.pkl','rb') as f: res = pickle.load(f) fig = MyFigure(figsize=(1.4,0.8)) pd=fig.addplot([0.3,0.4,0.65,0.55]) for j in xrange(len(res['vDend_list'])): plot(res['times'],res['vDend_list'][j],color='black') pd.xlabel('Time (ms)',labelpad=3) pd.ylabel('$V_D$ (mV)',labelpad=2) pd.ax.set_yticks([-70,-20]) pd.ax.set_xticks([0,100]) pd.xaxis.set_tick_params(pad=0.) pd.yaxis.set_tick_params(pad=0.) if remakeFig: fig.save(self.figpath+'plot_NMDAspike_Dend'+self.version) fig = MyFigure(figsize=(1.4,0.7)) pd=fig.addplot([0.3,0.3,0.65,0.65]) for j in xrange(len(res['vDend_list'])): plot(res['times'],res['vSoma_list'][j],color='black') pd.xlabel('Time (ms)',labelpad=3) ylabel('$V_S$ (mV)',labelpad=0) pd.ax.set_yticks([-70,-60]) pd.ax.set_xticks([0,100]) pd.xaxis.set_tick_params(pad=0.) pd.yaxis.set_tick_params(pad=0.) if remakeFig: fig.save(self.figpath+'plot_NMDAspike_Soma'+self.version) show()
def plot_NMDAspike(self, remakeFig=False): with open(self.datapath + 'NMDAspike_latest.pkl', 'rb') as f: res = pickle.load(f) fig = MyFigure(figsize=(1.4, 0.8)) pd = fig.addplot([0.3, 0.4, 0.65, 0.55]) for j in xrange(len(res['vDend_list'])): plot(res['times'], res['vDend_list'][j], color='black') pd.xlabel('Time (ms)', labelpad=3) pd.ylabel('$V_D$ (mV)', labelpad=2) pd.ax.set_yticks([-70, -20]) pd.ax.set_xticks([0, 100]) pd.xaxis.set_tick_params(pad=0.) pd.yaxis.set_tick_params(pad=0.) if remakeFig: fig.save(self.figpath + 'plot_NMDAspike_Dend' + self.version) fig = MyFigure(figsize=(1.4, 0.7)) pd = fig.addplot([0.3, 0.3, 0.65, 0.65]) for j in xrange(len(res['vDend_list'])): plot(res['times'], res['vSoma_list'][j], color='black') pd.xlabel('Time (ms)', labelpad=3) ylabel('$V_S$ (mV)', labelpad=0) pd.ax.set_yticks([-70, -60]) pd.ax.set_xticks([0, 100]) pd.xaxis.set_tick_params(pad=0.) pd.yaxis.set_tick_params(pad=0.) if remakeFig: fig.save(self.figpath + 'plot_NMDAspike_Soma' + self.version) show()
def plot_NevianFit(self): with open(self.datapath+'learning_para_2014-11-10_0','rb') as f: para = pickle.load(f) experiment3B = 'NevianFig3B' with open(self.datapath+'resultlist_'+experiment3B,'rb') as f: result_list3B = pickle.load(f) experiment3D_full = 'NevianFig3D_full' with open(self.datapath+'resultlist_'+experiment3D_full,'rb') as f: result_list3D_full = pickle.load(f) experiment2_full = 'NevianFig2_full' with open(self.datapath+'resultlist_'+experiment2_full,'rb') as f: result_list2_full = pickle.load(f) remakeFig = True fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.3,0.25,0.65,0.7]) self.plot_model_result(pl, para, result_list2_full, experiment2_full, plot_data=True) #fig.save(self.figpath+'Fit'+experiment2_full+'_'+self.version) #compareWithNevian_CaTrace(para,remakeFig,experiment = 'NevianFig5') fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.3,0.25,0.65,0.7]) self.plot_model_result(pl, para, result_list3B, experiment3B, plot_data=True) #fig.save(self.figpath+'Fit'+experiment3B+'_'+self.version) #compareWithNevian_CaTrace(para,remakeFig,experiment = experiment3B) fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.3,0.25,0.65,0.7]) self.plot_model_result(pl, para, result_list3D_full, experiment3D_full, plot_data=True) fig.save(self.figpath+'Fit'+experiment3D_full+'_'+self.version)
def plot_NMDAPlateauMechanism(self): p = MCM.read_params(self.paramsfile) # NMDA channel voltage-glutamate input relationship betaPlot = linspace(0, 10, 100) def vSteadyFunc(p, v, beta): gL = 1 gNMDA = beta * gL #gGABA = 1 iLeak = -gL * (v - p['vRest_pyr']) iNMDA = -gNMDA * (v - p['vE_pyr']) / ( 1 + exp(-(v - p['vHalfNMDA']) / p['vSpreadNMDA'])) iGABA = -gGABA * (v - p['vI_pyr']) iTot = iLeak + iNMDA + iGABA return iTot gGABA = 0 figure() vSteadyPlot_low = list() vSteadyPlot_high = list() for beta in betaPlot: sol = sp.optimize.newton(lambda v: vSteadyFunc(p, v, beta), -70 * mvolt, maxiter=1000) vSteadyPlot_low.append(sol) sol = sp.optimize.newton(lambda v: vSteadyFunc(p, v, beta), 0 * mvolt, maxiter=1000) vSteadyPlot_high.append(sol) theta = betaPlot[array(vSteadyPlot_high) / mvolt < -40][-1] fig = MyFigure(figsize=(1.5, 1.3)) pl = fig.addplot([0.35, 0.3, 0.6, 0.65]) pl.plot([theta] * 2, [-70, 0], '--', color=array([189, 189, 189]) / 255) pl.plot(betaPlot, array(vSteadyPlot_low) / mvolt, color='black') pl.plot(betaPlot, array(vSteadyPlot_high) / mvolt, color='black') pl.ax.set_yticks([-70, -10]) pl.ax.set_xticks([0, theta, 10]) pl.ax.set_xticklabels(['0', r'$\theta_{\mathrm{NMDA}}$', '10']) xlabel('$g_{\mathrm{NMDA}}/(g_L+g_{\mathrm{GABA}})$') ylabel('$V_{ss}$ (mV)', labelpad=-5) fig.save(self.figpath + 'plot_NMDAPlateauMechanism' + self.version) vplot = linspace(-70, -15, 100) * mV fMg = 1 / (1 + exp(-(vplot - p['vHalfNMDA']) / p['vSpreadNMDA'])) fig = MyFigure(figsize=(1.5, 1.3)) pl = fig.addplot([0.35, 0.3, 0.6, 0.65]) pl.plot(vplot / mV, fMg, color='black') ylabel('$f_{\mathrm{Mg}}(V)$', labelpad=-5) xlabel('$V_D$ (mV)') pl.ax.set_xticks([-70, -10]) pl.ax.set_yticks([0, 0.5])
def plot_NMDAPlateauMechanism(self): p = MCM.read_params(self.paramsfile) # NMDA channel voltage-glutamate input relationship betaPlot = linspace(0,10,100) def vSteadyFunc(p,v,beta): gL = 1 gNMDA = beta*gL #gGABA = 1 iLeak = -gL*(v-p['vRest_pyr']) iNMDA = -gNMDA*(v-p['vE_pyr'])/(1+exp(-(v-p['vHalfNMDA'])/p['vSpreadNMDA'])) iGABA = -gGABA*(v-p['vI_pyr']) iTot = iLeak + iNMDA + iGABA return iTot gGABA=0 figure() vSteadyPlot_low = list() vSteadyPlot_high = list() for beta in betaPlot: sol = sp.optimize.newton(lambda v: vSteadyFunc(p,v,beta),-70*mvolt,maxiter=1000) vSteadyPlot_low.append(sol) sol = sp.optimize.newton(lambda v: vSteadyFunc(p,v,beta),0*mvolt,maxiter=1000) vSteadyPlot_high.append(sol) theta = betaPlot[array(vSteadyPlot_high)/mvolt<-40][-1] fig = MyFigure(figsize=(1.5,1.3)) pl=fig.addplot([0.35,0.3,0.6,0.65]) pl.plot([theta]*2,[-70,0],'--',color=array([189,189,189])/255) pl.plot(betaPlot,array(vSteadyPlot_low)/mvolt, color='black') pl.plot(betaPlot,array(vSteadyPlot_high)/mvolt, color='black') pl.ax.set_yticks([-70,-10]) pl.ax.set_xticks([0,theta,10]) pl.ax.set_xticklabels(['0',r'$\theta_{\mathrm{NMDA}}$','10']) xlabel('$g_{\mathrm{NMDA}}/(g_L+g_{\mathrm{GABA}})$') ylabel('$V_{ss}$ (mV)',labelpad=-5) fig.save(self.figpath+'plot_NMDAPlateauMechanism'+self.version) vplot = linspace(-70,-15,100)*mV fMg = 1/(1+exp(-(vplot-p['vHalfNMDA'])/p['vSpreadNMDA'])) fig = MyFigure(figsize=(1.5,1.3)) pl=fig.addplot([0.35,0.3,0.6,0.65]) pl.plot(vplot/mV,fMg, color='black') ylabel('$f_{\mathrm{Mg}}(V)$',labelpad=-5) xlabel('$V_D$ (mV)') pl.ax.set_xticks([-70,-10]) pl.ax.set_yticks([0,0.5])
def plot_Newsome_statespace_legend(self): i_dim = 0 n_m = 6 for colors in [motion_colors, color_colors]: mks = 4 fig = MyFigure(figsize=(0.75, 0.2)) pl = fig.addplot(rect=[0.05, 0.05, 0.9, 0.9]) for i_coh in xrange(n_m): if i_coh < (n_m / 2): mfc = 'white' mec = colors[i_coh] else: mfc = colors[n_m - i_coh - 1] mec = mfc pl.plot(i_coh, 0, 'o', markerfacecolor=mfc, markeredgecolor=mec, markersize=mks) pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) fig.save(self.figpath + 'plot_Newsome_statespace_legend_%d' % i_dim) i_dim += 1
def plot_WeightChangevsRate(self): with open(self.datapath + 'calc_WeightChangevsRate', 'rb') as f: output = pickle.load(f) p = output['params'] w_post_list = output['w_post_list'] dend_inh_rates = p['dend_inh_rates'] colorMatrix = array([[65, 182, 196], [34, 94, 168], [8, 29, 88]]) / 255 fig = MyFigure(figsize=(2.5, 1.2)) pl = fig.addplot(rect=[0.25, 0.3, 0.7, 0.65]) pl.plot([0, max(p['pre_rates'])], [1, 1], color=array([189, 189, 189]) / 255) i = 0 plotlist = list() for w_post in w_post_list: ax, = pl.plot(p['pre_rates'], w_post, color=colorMatrix[i, :]) plotlist.append(ax) plt.xlabel('Pre-synaptic rate (Hz)') plt.ylabel('Weight change') i += 1 pl.ax.set_xticks([0, 20, 40]) pl.ax.set_plt.ylim((0, 3)) pl.ax.set_yticks([0, 1, 2, 3]) leg = plt.legend(plotlist, ['%d' % r for r in dend_inh_rates], title='Inhibition (Hz)', loc=2, bbox_to_anchor=[0.1, 1.15]) leg.draw_frame(False) fig.save(self.figpath + 'WeightChangevsRate' + self.version)
def plot_basic_pathway_gating_slice(self,mode,plot_ylabel=True): with open(self.datapath+'basic_pathway_gating_response_slice_'+mode+'_latest','rb') as f: p = pickle.load(f) #print p['firing_rate_plot'] fig=MyFigure(figsize=(1.8,0.75)) pl = fig.addplot(rect=[0.25,0.15,0.55,0.65]) #pl.plot(p['firing_rate_plot'][:p['np']],color=colorMatrix[1],label='%d' % p['bkg_inh_rate']) #pl.plot(p['firing_rate_plot'][p['np']:],color=colorMatrix[5],label='%d' % (p['bkg_inh_rate']+p['dend_inh_rate'])) pl.plot(p['firing_rate_plot'][:p['np']],color=colorMatrix[1],label='1') pl.plot(p['firing_rate_plot'][p['np']:],color=colorMatrix[5],label='2') #xlabel('Pathway 1 stimulus') #xticks([p['np']//2],['preferred']) xticks([p['np']//2],['']) if mode in ['prelearning','postlearning']: maxr = 25 else: maxr = p['firing_rate_plot'].max() pl.ax.set_ylim((0,maxr)) pl.ax.set_yticks([0,maxr//5*5]) if plot_ylabel: ylabel('Output rate (Hz)') leg = legend(title='Open gate',loc=1, bbox_to_anchor=[1.0, 1.35], frameon=False) else: pl.ax.set_yticklabels(['','']) fig.save(self.figpath+'basic_pathway_gating_slice_'+mode+self.version) ron = np.max(p['firing_rate_plot'][:p['np']]) - np.min(p['firing_rate_plot'][:]) roff = np.max(p['firing_rate_plot'][p['np']:]) - np.min(p['firing_rate_plot'][:]) print 'Gating selectivity is %0.2f' % ((ron-roff)/(ron+roff))
def plot_sNMDAmean(self): p = MCM.read_params(self.paramsfile) def meansNMDA(rate,p): x_mean = rate*p['tauNMDARise'] temp = p['alphaNMDA']*p['tauNMDADecay']*x_mean s_mean = temp/(1+temp) return s_mean theta = 0.645 # make threshold around 30 Hz #theta = 0.6784 gGABA = 0.6 # NMDA channel voltage-glutamate input relationship fig = MyFigure(figsize=(1.9,1.5)) pl=fig.addplot([0.4,0.3,0.5,0.65]) rates = linspace(0,300,100) meanNMDAplot=meansNMDA(rates,p) meanNMDAplot2 = meanNMDAplot/(1+gGABA) pl.plot([0,300],[theta]*2,'--',color=array([189,189,189])/255) pl.plot(rates,meanNMDAplot,color=colorMatrix[1],label='0') pl.plot(rates,meanNMDAplot2,color=colorMatrix[5],label='%0.1f' % gGABA) xlabel('NMDA input rate (Hz)') ylabel('$g_{\mathrm{NMDA}}/(g_L+g_{\mathrm{GABA}})$') pl.ax.set_yticks([0,theta]) pl.ax.set_yticklabels(['0',r'$\theta_{\mathrm{NMDA}}$']) pl.ax.set_xticks([0,150,300]) leg=legend(title='$g_{\mathrm{GABA}}/g_L$',loc=4,bbox_to_anchor=[1.2, -0.05]) leg.draw_frame(False) fig.save(self.figpath+'sNMDAmean'+self.version)
def plot_WeightChangevsRate(self): with open(self.datapath+'calc_WeightChangevsRate','rb') as f: output = pickle.load(f) p = output['params'] w_post_list = output['w_post_list'] dend_inh_rates = p['dend_inh_rates'] colorMatrix = array([[65,182,196], [34,94,168], [8,29,88]])/255 fig=MyFigure(figsize=(2.5,1.2)) pl = fig.addplot(rect=[0.25,0.3,0.7,0.65]) pl.plot([0,max(p['pre_rates'])],[1,1],color=array([189,189,189])/255) i = 0 plotlist = list() for w_post in w_post_list: ax, = pl.plot(p['pre_rates'],w_post,color=colorMatrix[i,:]) plotlist.append(ax) plt.xlabel('Pre-synaptic rate (Hz)') plt.ylabel('Weight change') i += 1 pl.ax.set_xticks([0,20,40]) pl.ax.set_plt.ylim((0,3)) pl.ax.set_yticks([0,1,2,3]) leg=plt.legend(plotlist,['%d' % r for r in dend_inh_rates],title='Inhibition (Hz)', loc=2,bbox_to_anchor=[0.1, 1.15]) leg.draw_frame(False) fig.save(self.figpath+'WeightChangevsRate'+self.version)
def fit_RatevsI(self): ''' fit the somatic firing rate as a function of current injection ''' with open(self.datapath+'RatevsI'+self.version,'rb') as f: result = pickle.load(f) x0 = [ 174.85951028, 45.16030095, 2.89003711] bnds = ((100,500),(10,1000),(0,5)) res = scipy.optimize.minimize(lambda p: self.obj_func_RatevsI(p,result), x0,bounds=bnds,method='SLSQP', options={'maxiter':100, 'disp':True}) print res.x p = res.x xdata = result['clamped_current_list'] ydata = result['fr_list'] ymodel, _ = self.obj_func_RatevsI(p,result,rich_return=True) fig=MyFigure(figsize=(2,1.5)) pl = fig.addplot(rect=[0.25,0.25,0.7,0.7]) pl.plot(xdata,ydata,color=np.array([55,126,184])/255) pl.plot(xdata,ymodel,color='black') pl.ax.set_yticks([0,50,100]) pl.xlabel(r'$I$ (pA)') pl.ylabel('Firing rate (Hz)') leg = pl.legend(['Simulation','Fit'],loc=2) leg.draw_frame(False) fig.save(self.figpath+'RatevsI'+self.version)
def plot_fit_vary_param(self): with open(self.datapath+'fit_vary_param'+ self.version,'rb') as f: res = pickle.load(f) n_som2dend_list = res.keys() n_som2dend_list.remove('best_sqe') n_som2dend_list.remove('worst_sqe') n_som2dend_list.remove('monkey') sqe_list = list() for n_som2dend in n_som2dend_list: sqes = res[n_som2dend].values() sqe_list.append(np.median(sqes)) fig=MyFigure(figsize=(2,1.7)) pl = fig.addplot(rect=[0.3,0.3,0.65,0.65]) pl.plot(n_som2dend_list,sqe_list, 'o-',markeredgecolor='black',markerfacecolor='black',markersize=2, color=np.array([150,150,150])/255,linewidth=1.5,label='model') pl.plot(n_som2dend_list,[res['best_sqe']]*len(n_som2dend_list), '-',markeredgecolor='black',markerfacecolor='black', color=np.array([150,150,150])/255,linewidth=1.5,label='optimal') pylab.ylabel('Sum of squared errors') pylab.xlabel(r'$N_{\mathit{SOM}\rightarrow dend}$') #pl.ax.set_yticks([0.01,0.02,0.03]) pl.ax.set_yticks([0,0.05,0.1]) pl.ax.set_xticks([5,10,15,20]) pylab.legend(loc=2,numpoints=1,frameon=False) #pl.plot(n_som2dend_list,[res['worst_sqe']]*len(n_som2dend_list),'--',markeredgecolor='black',markerfacecolor='black',linewidth=1.5) fig.save(self.figpath+ 'NewsomeFit_vary_param' + self.version)
def plot_NevianFit(self): with open(self.datapath + 'learning_para_2014-11-10_0', 'rb') as f: para = pickle.load(f) experiment3B = 'NevianFig3B' with open(self.datapath + 'resultlist_' + experiment3B, 'rb') as f: result_list3B = pickle.load(f) experiment3D_full = 'NevianFig3D_full' with open(self.datapath + 'resultlist_' + experiment3D_full, 'rb') as f: result_list3D_full = pickle.load(f) experiment2_full = 'NevianFig2_full' with open(self.datapath + 'resultlist_' + experiment2_full, 'rb') as f: result_list2_full = pickle.load(f) remakeFig = True fig = MyFigure(figsize=(1.5, 1.5)) pl = fig.addplot(rect=[0.3, 0.25, 0.65, 0.7]) self.plot_model_result(pl, para, result_list2_full, experiment2_full, plot_data=True) #fig.save(self.figpath+'Fit'+experiment2_full+'_'+self.version) #compareWithNevian_CaTrace(para,remakeFig,experiment = 'NevianFig5') fig = MyFigure(figsize=(1.5, 1.5)) pl = fig.addplot(rect=[0.3, 0.25, 0.65, 0.7]) self.plot_model_result(pl, para, result_list3B, experiment3B, plot_data=True) #fig.save(self.figpath+'Fit'+experiment3B+'_'+self.version) #compareWithNevian_CaTrace(para,remakeFig,experiment = experiment3B) fig = MyFigure(figsize=(1.5, 1.5)) pl = fig.addplot(rect=[0.3, 0.25, 0.65, 0.7]) self.plot_model_result(pl, para, result_list3D_full, experiment3D_full, plot_data=True) fig.save(self.figpath + 'Fit' + experiment3D_full + '_' + self.version)
def fit_DendVvsgErI(self): ''' fit the dendritic voltage as a function of excitatory input and inhibitory rate ''' with open(self.datapath+'DendVvsgErI'+self.version,'rb') as f: result = pickle.load(f) x0 = [5,10,7,1] bnds = ((1,20),(1,20),(1,20),(0,3)) params = copy.copy(self.params) for key in result['params']: params[key] = result['params'][key] # overwrite the old value temp = params['pre_rate']*params['tauNMDARise']*params['tauNMDADecay']*params['alphaNMDA'] print params['tauNMDARise']*params['tauNMDADecay']*params['alphaNMDA'] # 0.06 is obtained from tau_rise = 2ms, tau_decay=100ms, alpha=0.3 /ms s_mean = temp/(1+temp) # mean gating variable result['Exc'] = result['weights']*params['gNMDA']*1e9*params['num_input']*s_mean # unit-less weights * synaptic conductance 2.5nS * 15 synapses * mean gating variable for 30Hz result['Inh'] = result['dend_inh_rates'] *params['tauGABA']*params['gGABA']*1e9 # Total Rate * synaptic conductance * tau_GABA res = scipy.optimize.minimize(lambda p: self.obj_func_DendVvsgErI(p,result), x0,bounds=bnds,method='SLSQP', options={'maxiter':100, 'disp':True}) print res.x p = res.x xdata = result['Exc'] n_curve = len(result['vdend_mean_list']) fig=MyFigure(figsize=(2,1.5)) pl = fig.addplot(rect=[0.25,0.25,0.7,0.7]) for i in xrange(n_curve): ydata = result['vdend_mean_list'][i]*1000 ax_data, = pl.plot(xdata,ydata,color=np.array([55,126,184])/255) ymodel_list, sqe = self.obj_func_DendVvsgErI(p,result,rich_return=True) for i in xrange(n_curve): ax_model, = pl.plot(xdata,ymodel_list[i],color='black') pl.xlabel(r'$g_{E,\mathrm{tot}}$ (nS)',labelpad = 3) pl.ylabel(r'$\overline{V}_D$ (mV)') pl.ax.set_xlim((0,50)) pl.ax.set_xticks([0,25,50]) pl.ax.set_ylim((-70,-10)) pl.ax.set_yticks([-70,-20]) leg = pl.legend([ax_data,ax_model],['Simulation','Fit'],loc=2, bbox_to_anchor=[0, 1.05]) leg.draw_frame(False) fig.save(self.figpath+'DendVvsgErI'+self.version)
def plot_voltagedistribution(self,denseinh = False): ''' Plot voltage distribution ''' p = dict() p['num_DendEach']=1 p['dt'] = 0.2*ms p['num_Soma'] = 40 p['pre_rate'] = 40*Hz p['inh_base'] = 5*Hz if denseinh: p['gGABA'] = p['gGABA']/10 p['inh_base'] = p['inh_base']*10 self.version = 'denseinh_' + self.version pre_rates = ones(p['num_Soma'])*p['pre_rate'] model = MCM.Model(paramsfile=self.paramsfile,eqsfile=self.eqsfile,outsidePara=p) model.make_model_dendrite_only(num_soma = p['num_Soma'],clamped_somavolt=-60*mV,condition='invivo') model.make_dend_bkginh(inh_rates=p['inh_base']) model.single_pathway_gating_experiment(pre_rates, num_input=15,w_input = 1) model.make_network() model.reinit() net = Network(model) net.run(2.5*second,report='text') mon = model.monitor times = mon['MvDend'].times/ms plotstart = 500 dendv = mon['MvDend'].values[:,times>plotstart]/mV dendv = dendv[range(0,p['num_DendEach']*p['num_Soma'],p['num_DendEach']),:] res = dict() res['params'] = p res['dendv'] = dendv with open(self.datapath+'voltage_distribution_'+self.version,'wb') as f: pickle.dump(res,f) fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.05,0.3,0.9,0.65]) #pl.ax.set_frame_on(False) pl.ax.spines['left'].set_visible(False) pl.ax.get_yaxis().set_visible(False) n, bins, patches = hist(dendv.flatten(), 50, normed=1, histtype='stepfilled') color_hist = array([99,99,99])/255 setp(patches, 'facecolor', color_hist,'edgecolor',color_hist) xlim([-70,-10]) xticks([-60,-50,-40,-30,-20],['-60','','-40','','-20']) xlabel('$V_D$ (mV)') fig.save(self.figpath+'VoltageDistribution_'+self.version)
def plot_GABAABratio(self): with open(self.datapath+'GatingCapacity_varyGABAABratio'+self.version,'rb') as f: p = pickle.load(f) fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.3,0.3,0.65,0.65]) pl.plot(1-p['GABAA_prop_plot'],p['gs1_plot'], 'o-', color=colorMatrix1[1], markeredgecolor = 'none', markersize=3) print p['gs1_plot'] ylabel('Gating selectivity') ylim((0,1)) xlim((0,1)) yticks([0,0.5,1],['0','0.5','1']) xticks([0,0.5,1],['0','0.5','1']) xlabel(r'$\mathrm{GABA}_{\mathrm{B}}$ conductance ratio') fig.save(self.figpath+'GatingCapacity_varyGABAABratio'+self.version)
def plot_basic_pathway_gating_slice(self, mode, plot_ylabel=True): with open( self.datapath + 'basic_pathway_gating_response_slice_' + mode + '_latest', 'rb') as f: p = pickle.load(f) #print p['firing_rate_plot'] fig = MyFigure(figsize=(1.8, 0.75)) pl = fig.addplot(rect=[0.25, 0.15, 0.55, 0.65]) #pl.plot(p['firing_rate_plot'][:p['np']],color=colorMatrix[1],label='%d' % p['bkg_inh_rate']) #pl.plot(p['firing_rate_plot'][p['np']:],color=colorMatrix[5],label='%d' % (p['bkg_inh_rate']+p['dend_inh_rate'])) pl.plot(p['firing_rate_plot'][:p['np']], color=colorMatrix[1], label='1') pl.plot(p['firing_rate_plot'][p['np']:], color=colorMatrix[5], label='2') #xlabel('Pathway 1 stimulus') #xticks([p['np']//2],['preferred']) xticks([p['np'] // 2], ['']) if mode in ['prelearning', 'postlearning']: maxr = 25 else: maxr = p['firing_rate_plot'].max() pl.ax.set_ylim((0, maxr)) pl.ax.set_yticks([0, maxr // 5 * 5]) if plot_ylabel: ylabel('Output rate (Hz)') leg = legend(title='Open gate', loc=1, bbox_to_anchor=[1.0, 1.35], frameon=False) else: pl.ax.set_yticklabels(['', '']) fig.save(self.figpath + 'basic_pathway_gating_slice_' + mode + self.version) ron = np.max(p['firing_rate_plot'][:p['np']]) - np.min( p['firing_rate_plot'][:]) roff = np.max(p['firing_rate_plot'][p['np']:]) - np.min( p['firing_rate_plot'][:]) print 'Gating selectivity is %0.2f' % ((ron - roff) / (ron + roff))
def plot_fit_vary_param(self): with open(self.datapath + 'fit_vary_param' + self.version, 'rb') as f: res = pickle.load(f) n_som2dend_list = res.keys() n_som2dend_list.remove('best_sqe') n_som2dend_list.remove('worst_sqe') n_som2dend_list.remove('monkey') sqe_list = list() for n_som2dend in n_som2dend_list: sqes = res[n_som2dend].values() sqe_list.append(np.median(sqes)) fig = MyFigure(figsize=(2, 1.7)) pl = fig.addplot(rect=[0.3, 0.3, 0.65, 0.65]) pl.plot(n_som2dend_list, sqe_list, 'o-', markeredgecolor='black', markerfacecolor='black', markersize=2, color=np.array([150, 150, 150]) / 255, linewidth=1.5, label='model') pl.plot(n_som2dend_list, [res['best_sqe']] * len(n_som2dend_list), '-', markeredgecolor='black', markerfacecolor='black', color=np.array([150, 150, 150]) / 255, linewidth=1.5, label='optimal') pylab.ylabel('Sum of squared errors') pylab.xlabel(r'$N_{\mathit{SOM}\rightarrow dend}$') #pl.ax.set_yticks([0.01,0.02,0.03]) pl.ax.set_yticks([0, 0.05, 0.1]) pl.ax.set_xticks([5, 10, 15, 20]) pylab.legend(loc=2, numpoints=1, frameon=False) #pl.plot(n_som2dend_list,[res['worst_sqe']]*len(n_som2dend_list),'--',markeredgecolor='black',markerfacecolor='black',linewidth=1.5) fig.save(self.figpath + 'NewsomeFit_vary_param' + self.version)
def plot_DendVvsgErI(self): with open(self.datapath+'DendVvsgErI'+self.version,'rb') as f: res = pickle.load(f) fig=MyFigure(figsize=(4,3)) pl = fig.addplot(rect=[0.2,0.15,0.7,0.8]) i = 0 for vdend_mean in res['vdend_mean_list']: pl.plot(res['params']['weights'],vdend_mean/mV, label='%d' % res['dend_inh_rates'][i]) xlabel('Weight') ylabel('Mean Dendritic Voltage (mV)') i += 1 pl.ax.set_xlim((0,2)) pl.ax.set_xticks([0,1,2]) pl.ax.set_ylim((-70,-10)) pl.ax.set_yticks([-70,-50,-30,-10]) leg=legend(title='Inhibition (Hz)',loc=2) leg.draw_frame(False) fig.save(self.figpath+'DendVvsgErI'+self.version)
def fit_RatevsDendV(self): ''' fit the somatic firing rate as a function of mean dendritic voltage ''' with open(self.datapath + 'RatevsDendV' + self.version, 'rb') as f: result = pickle.load(f) x0 = [1.5, 0.08, 2.2] bnds = ((0, 5), (0, 1), (1, 3)) params = copy.copy(self.params) for key in result['params']: params[key] = result['params'][key] # overwrite the old value res = scipy.optimize.minimize( lambda p: self.obj_func_RatevsDendV(p, result), x0, bounds=bnds, method='SLSQP', options={ 'maxiter': 100, 'disp': True }) print res.x p = res.x xdata = result['clamped_dendvolt_list'] + 70 ydata = result['fr_list'] ymodel, _ = self.obj_func_RatevsDendV(p, result, rich_return=True) fig = MyFigure(figsize=(2, 1.5)) pl = fig.addplot(rect=[0.25, 0.25, 0.7, 0.7]) pl.plot(xdata - 70, ydata, color=np.array([55, 126, 184]) / 255) pl.plot(xdata - 70, ymodel, color='black') pl.ax.set_xticks([-70, -60, -50, -40]) pl.ax.set_yticks([0, 50, 100, 150]) pl.xlabel(r'$\langle \overline{V}_D\rangle$ (mV)') pl.ylabel('Firing rate (Hz)') leg = pl.legend(['Simulation', 'Fit'], loc=2) leg.draw_frame(False) fig.save(self.figpath + 'RatevsDendV' + self.version)
def plot_DendVvsgErI(self): with open(self.datapath + 'DendVvsgErI' + self.version, 'rb') as f: res = pickle.load(f) fig = MyFigure(figsize=(4, 3)) pl = fig.addplot(rect=[0.2, 0.15, 0.7, 0.8]) i = 0 for vdend_mean in res['vdend_mean_list']: pl.plot(res['params']['weights'], vdend_mean / mV, label='%d' % res['dend_inh_rates'][i]) xlabel('Weight') ylabel('Mean Dendritic Voltage (mV)') i += 1 pl.ax.set_xlim((0, 2)) pl.ax.set_xticks([0, 1, 2]) pl.ax.set_ylim((-70, -10)) pl.ax.set_yticks([-70, -50, -30, -10]) leg = legend(title='Inhibition (Hz)', loc=2) leg.draw_frame(False) fig.save(self.figpath + 'DendVvsgErI' + self.version)
def plot_Newsome_statespace_legend(self): i_dim = 0 n_m = 6 for colors in [motion_colors,color_colors]: mks = 4 fig=MyFigure(figsize=(0.75,0.2)) pl = fig.addplot(rect=[0.05,0.05,0.9,0.9]) for i_coh in xrange(n_m): if i_coh<(n_m/2): mfc = 'white' mec = colors[i_coh] else: mfc = colors[n_m-i_coh-1] mec = mfc pl.plot(i_coh,0,'o',markerfacecolor=mfc,markeredgecolor=mec,markersize=mks) pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) fig.save(self.figpath+'plot_Newsome_statespace_legend_%d' % i_dim) i_dim += 1
def fit_RatevsI(self): ''' fit the somatic firing rate as a function of current injection ''' with open(self.datapath + 'RatevsI' + self.version, 'rb') as f: result = pickle.load(f) x0 = [174.85951028, 45.16030095, 2.89003711] bnds = ((100, 500), (10, 1000), (0, 5)) res = scipy.optimize.minimize( lambda p: self.obj_func_RatevsI(p, result), x0, bounds=bnds, method='SLSQP', options={ 'maxiter': 100, 'disp': True }) print res.x p = res.x xdata = result['clamped_current_list'] ydata = result['fr_list'] ymodel, _ = self.obj_func_RatevsI(p, result, rich_return=True) fig = MyFigure(figsize=(2, 1.5)) pl = fig.addplot(rect=[0.25, 0.25, 0.7, 0.7]) pl.plot(xdata, ydata, color=np.array([55, 126, 184]) / 255) pl.plot(xdata, ymodel, color='black') pl.ax.set_yticks([0, 50, 100]) pl.xlabel(r'$I$ (pA)') pl.ylabel('Firing rate (Hz)') leg = pl.legend(['Simulation', 'Fit'], loc=2) leg.draw_frame(False) fig.save(self.figpath + 'RatevsI' + self.version)
def plot_sNMDAmean(self): p = MCM.read_params(self.paramsfile) def meansNMDA(rate, p): x_mean = rate * p['tauNMDARise'] temp = p['alphaNMDA'] * p['tauNMDADecay'] * x_mean s_mean = temp / (1 + temp) return s_mean theta = 0.645 # make threshold around 30 Hz #theta = 0.6784 gGABA = 0.6 # NMDA channel voltage-glutamate input relationship fig = MyFigure(figsize=(1.9, 1.5)) pl = fig.addplot([0.4, 0.3, 0.5, 0.65]) rates = linspace(0, 300, 100) meanNMDAplot = meansNMDA(rates, p) meanNMDAplot2 = meanNMDAplot / (1 + gGABA) pl.plot([0, 300], [theta] * 2, '--', color=array([189, 189, 189]) / 255) pl.plot(rates, meanNMDAplot, color=colorMatrix[1], label='0') pl.plot(rates, meanNMDAplot2, color=colorMatrix[5], label='%0.1f' % gGABA) xlabel('NMDA input rate (Hz)') ylabel('$g_{\mathrm{NMDA}}/(g_L+g_{\mathrm{GABA}})$') pl.ax.set_yticks([0, theta]) pl.ax.set_yticklabels(['0', r'$\theta_{\mathrm{NMDA}}$']) pl.ax.set_xticks([0, 150, 300]) leg = legend(title='$g_{\mathrm{GABA}}/g_L$', loc=4, bbox_to_anchor=[1.2, -0.05]) leg.draw_frame(False) fig.save(self.figpath + 'sNMDAmean' + self.version)
def fit_RatevsDendV(self): ''' fit the somatic firing rate as a function of mean dendritic voltage ''' with open(self.datapath+'RatevsDendV'+self.version,'rb') as f: result = pickle.load(f) x0 = [1.5,0.08,2.2] bnds = ((0,5),(0,1),(1,3)) params = copy.copy(self.params) for key in result['params']: params[key] = result['params'][key] # overwrite the old value res = scipy.optimize.minimize(lambda p: self.obj_func_RatevsDendV(p,result), x0,bounds=bnds,method='SLSQP', options={'maxiter':100, 'disp':True}) print res.x p = res.x xdata = result['clamped_dendvolt_list'] + 70 ydata = result['fr_list'] ymodel, _ = self.obj_func_RatevsDendV(p,result,rich_return=True) fig=MyFigure(figsize=(2,1.5)) pl = fig.addplot(rect=[0.25,0.25,0.7,0.7]) pl.plot(xdata-70,ydata,color=np.array([55,126,184])/255) pl.plot(xdata-70,ymodel,color='black') pl.ax.set_xticks([-70,-60,-50,-40]) pl.ax.set_yticks([0,50,100,150]) pl.xlabel(r'$\langle \overline{V}_D\rangle$ (mV)') pl.ylabel('Firing rate (Hz)') leg = pl.legend(['Simulation','Fit'],loc=2) leg.draw_frame(False) fig.save(self.figpath+'RatevsDendV'+self.version)
def quick_runNewsome_psychometric(self,p,savenew=True,savename=''): datacolor3 = np.array([150,150,150])/255 modelcolor3 = np.array([37,37,37])/255 m_options = np.array([-0.5,-0.15,-0.05,0.05,0.15,0.5]) c_options = np.array([-0.5,-0.18,-0.06,0.06,0.18,0.5]) n_options = 6 mks = 5 n_plot = 51 coh_plot = np.linspace(-0.6,0.6,n_plot) performance_plot_m = np.zeros((n_options,n_plot)) for i_c in xrange(n_options): for i_m in xrange(n_plot): c = c_options[i_c] m = coh_plot[i_m] performance = self.quick_Newsome_model(p,m,c) performance_plot_m[i_c,i_m] += performance*100 fig=MyFigure(figsize=(4.5,1.7)) pl = fig.addplot(rect=[0.1,0.3,0.24,0.6]) pl.plot(m_options*100,self.p_m_m*100,'o',color=datacolor3,markeredgecolor=datacolor3,label='Data',markersize=mks) pl.plot(coh_plot*100,performance_plot_m.mean(axis=0),color = modelcolor3,label='Model') pylab.ylim([-5,105]) pylab.yticks([0,25,50,75,100]) pylab.xticks([-50,-15,15,50],['-50\n Left','-15','15','50\n Right']) pylab.ylabel('Choices to right (%)') pylab.xlabel('Motion coherence') leg = pylab.legend(loc=2,numpoints=1, bbox_to_anchor=(-0.03, 1.15)) leg.draw_frame(False) m_options = c_options[:] performance_plot_c = np.zeros((n_options,n_plot)) for i_m in xrange(n_options): for i_c in xrange(n_plot): c = coh_plot[i_c] m = m_options[i_m] performance = self.quick_Newsome_model(p,m,c) performance_plot_c[i_m,i_c] += performance*100 pl = fig.addplot(rect=[0.44,0.3,0.24,0.6]) pl.plot(c_options*100,self.p_m_c*100,'o',color=datacolor3,markeredgecolor=datacolor3,label='Data',markersize=mks) pl.plot(coh_plot*100,performance_plot_c.mean(axis=0),color = modelcolor3,label='Model') pylab.ylim([-5,105]) pylab.yticks([0,25,50,75,100],[]) pylab.xticks([-50,-15,15,50],['-50\n Red','-15','15','50\n Green']) pylab.xlabel('Color coherence') pylab.ylabel('Choices to green (%)') #title('Motion Context') leg = pylab.legend(loc=2,numpoints=1, bbox_to_anchor=(-0.03, 1.15)) leg.draw_frame(False) pl = fig.addplot(rect=[0.73,0.3,0.24,0.6]) for i_m in xrange(n_options//2): pl.plot(coh_plot*100,(performance_plot_c[i_m,:]+performance_plot_c[-1-i_m,:])/2,color=motion_colors4[-i_m-1]) pylab.ylim([-5,105]) pylab.yticks([0,25,50,75,100],[]) pylab.xticks([-50,-15,15,50],['-50\n Red','-15','15','50\n Green']) leg = pylab.legend(['Strong','Medium','Weak'],title='Motion coherence',loc=2,bbox_to_anchor=(-0.1, 1.2)) leg.draw_frame(False) pylab.xlabel('Color coherence') if savenew: fig.save(self.figpath+'CompareWithNewsomePsychometric_'+savename+self.monkey+self.version) combined_panel = True if combined_panel: mks = 3 fig=MyFigure(figsize=(1.85,1.5)) pl = fig.addplot(rect=[0.3,0.25,0.6,0.55]) pl.plot(c_options*100,self.p_m_c*100,'o',color=np.array([8,29,88])/255, markeredgecolor=np.array([8,29,88])/255,markersize=mks,label='Data - Color context') pl.plot(coh_plot*100,performance_plot_c.mean(axis=0),color = np.array([8,29,88])/255) pl.plot(m_options*100,self.p_m_m*100,'o',color=np.array([65,182,196])/255, markeredgecolor=np.array([65,182,196])/255,label='Data - Motion context',markersize=mks) pl.plot(coh_plot*100,performance_plot_m.mean(axis=0),color = np.array([65,182,196])/255,label='Model') pylab.ylim([-5,105]) pylab.yticks([0,25,50,75,100]) pylab.xticks([-50,-15,15,50],['-50','-15','15','50']) pylab.ylabel('Choices to right (%)') pylab.xlabel('Motion coherence to right') leg = pylab.legend(loc=2,numpoints=1, bbox_to_anchor=(-0.03, 1.35)) leg.draw_frame(False) fig.save(self.figpath+'CompareWithNewsomePsychometric_combpanel_'+savename+self.monkey+self.version)
def plot_EvsDI(self,name = 'NMDA',denseinh = False,bothinh = True,rate_range=60): ''' plot mean dendritic voltage as a function of excitatory input rate, and inhibitory rate ''' if denseinh: di = 'denseinh_' k = 10 else: di = '' k = 1 name_append = di+name+('_range%d' % rate_range)+self.version with open(self.datapath+'EvsDI_'+di+name+('_range%d' % rate_range)+'_latest.pkl','rb') as f: res = pickle.load(f) if rate_range>100: figsize = (1.5,1.3) ylim = (-70,0) yticks = [-70,-10] rect = [0.25,0.3,0.65,0.65] else: figsize = (1.3,1.3) ylim = (-70,-10) yticks = [-70,-20] rect = [0.3,0.3,0.65,0.65] fig=MyFigure(figsize=figsize) pl = fig.addplot(rect=rect) pl.plot(res['pre_rates'],res['vDend_mean'][0],color=colorMatrix[1],label='0') print res['vDend_mean'][0] if bothinh: pl.plot(res['pre_rates'],res['vDend_mean'][30],color=colorMatrix[5],label='30') #leg=legend(title='Inhibition (Hz)',loc=2, bbox_to_anchor=[-0.05, 1.05],frameon=False) pl.ax.set_ylim(ylim) pl.ax.set_yticks(yticks) xticks = [0,int(rate_range/2),rate_range] pl.ax.set_xticks(xticks) #xlabel('Rate of %d ' % p['num_inputeach']+name+' inputs (Hz)' ) xlabel('Rate (Hz)') if name is 'NMDA': ylabel('$\overline{V}_D$ (mV)',labelpad=-5) else: pl.ax.set_yticklabels(['','']) if bothinh: fig.save(self.figpath+'EvsDI_'+name_append) else: fig.save(self.figpath+'EvsDI_preinh_'+name_append) if name is 'NMDA': inh_list = res['vDend_mean'].keys() inh_list = sort(inh_list) fig=MyFigure(figsize=(2.2,1.6)) pl = fig.addplot(rect=[0.25,0.25,0.7,0.7]) for i in xrange(len(inh_list)): color = colorMatrix[i+1,:] pl.plot(res['pre_rates'],res['vDend_mean'][inh_list[i]], color=color,label='%d' % (inh_list[i]*k)) leg=legend(title='Inhibition (Hz)',loc=2, bbox_to_anchor=[0.02, 1.05],frameon=False) pl.ax.set_ylim((-70,-10)) pl.ax.set_yticks([-70,-20]) pl.ax.set_xticks(xticks) #xlabel('Rate of %d ' % p['num_inputeach']+name+' inputs (Hz)' ) xlabel('Excitatory input rate (Hz)') ylabel('Mean dendritic voltage (mV)',labelpad=5) fig.save(self.figpath+'EvsDI_full_'+name_append)
def plot_WeightChangevsInitWeight(self): post_rate = 10 with open(self.datapath + 'learning_para_2014-11-10_0', 'rb') as f: para = pickle.load(f) q = para.copy() with open( self.datapath + 'WeightChangevsInitWeight_postr%d' % post_rate, 'rb') as f: resultlist = pickle.load(f) # in vivo change (see Higgins, Graupner, Brunel 2014) q = self.invivo_learningparams(q) vDend_mean_list = list() fig = MyFigure(figsize=(4, 3)) pl = fig.addplot(rect=[0.2, 0.15, 0.7, 0.8]) pl.plot([q['w0'], q['w1']], [q['w0'], q['w1']], color='black', linestyle='--') i = 0 for result in resultlist: p = result['params'] vDend = result['vDend'] NMDACasyn = result['NMDACasyn'] bAPCa = result['bAPCa'] vDend_mean = vDend.mean(axis=1) vDend_mean = vDend_mean.reshape(p['n_weight'], p['n_rep']) vDend_mean = vDend_mean.mean(axis=1) vDend_mean_list.append(vDend_mean) num_syn = NMDACasyn.shape[0] num_soma = bAPCa.shape[0] synsomaratio = num_syn // num_soma bAPCasyn = bAPCa.repeat(synsomaratio, axis=0) CaTrace = NMDACasyn * q['NMDA_scaling'] + bAPCasyn * q[ 'bAP_scaling'] w_post = np.zeros(num_syn) n_eachweight = num_syn // p['n_weight'] total_time = 3000 #s record_dt = p['record_dt'] for i_syn in xrange(num_syn): CaTraceSorted = np.sort(CaTrace[i_syn]) AlphaP = MCM.crossthresholdtime( CaTraceSorted, q['thetaP']) * record_dt * (total_time / p['runtime']) AlphaD = MCM.crossthresholdtime( CaTraceSorted, q['thetaD']) * record_dt * (total_time / p['runtime']) wpre = p['weights'][i_syn // n_eachweight] wpost_syn = MCM.SynapseChange(wpre, AlphaP, AlphaD, q) w_post[i_syn] = wpost_syn w_post = w_post.reshape(p['n_weight'], n_eachweight) w_post = w_post.mean(axis=1) ax, = pl.plot(p['weights'], w_post, color=colorMatrix[i * 0, :], label='%d' % result['dend_inh_rate']) i += 1 plt.xlabel('Weight before learning') plt.ylabel('Weight after learning') pl.ax.set_plt.xlim((0, 3)) pl.ax.set_xticks([0, 1, 2, 3]) pl.ax.set_plt.ylim((0, 3)) pl.ax.set_yticks([0, 1, 2, 3]) leg = plt.legend(title='Inhibition (Hz)', loc=2) leg.draw_frame(False) axis('equal') #title('%d NMDA inputs of %d Hz' % (num_input,pre_rate)) fig.save(self.figpath + ('WeightChangevsInitWeight_%d' % post_rate) + self.version)
def plot_vary_inh(self,savenew=True,plot_ylabel=True): p = MCM.read_params(self.paramsfile) p['inh_rate_base'] = 5 p['num_soma'] = 1 p['num_DendEach'] = 10 p['num_path'] = 2 p['num_DendDisinh'] = 3 p['mode'] = 'control_voltage' p['v_target'] = -40 single_gating_list = list() single_gating_nonoverlap_list = list() num_dend_list = list() leg_list = list() inh_list = [30,20,10] for inh in inh_list: p['inh_rate_max'] = inh + p['inh_rate_base'] p['inh_base'] = p['inh_rate_base']*p['tauGABA']*p['gGABA']/nsiemens # rate * tau_GABA * gGABA p['inh_max'] = p['inh_rate_max']*p['tauGABA']*p['gGABA']/nsiemens # rate * tau_GABA * gGABA num_dend_plot = range(p['num_DendDisinh'],50) single_gating_plot = list() for num_dend in num_dend_plot: p['num_DendEach'] = num_dend res = self.analytic_evalgating(p) single_gating_plot.append(res['single_gating']) num_dend_list.append(num_dend_plot) single_gating_list.append(single_gating_plot) leg_list.append(str(inh)) res = self.analytic_evalgating(p,no_overlap=True) single_gating_nonoverlap_list.append(res['single_gating']) # Single path fig=MyFigure(figsize=(1.5,1.5)) pl = fig.addplot(rect=[0.3,0.3,0.65,0.65]) for i in xrange(len(inh_list)): pl.plot(num_dend_list[i][0]/array(num_dend_list[i]),single_gating_list[i], color=colorMatrix1[2*i+1]) ylim((0,1)) xlim((0,1)) xticks([0,0.5,1],['0','0.5','1']) xlabel('$N_{disinh}/N_{dend}$') if plot_ylabel: ylabel('Gating selectivity') yticks([0,0.5,1],['0','0.5','1']) else: yticks([0,0.5,1],['','','']) leg = legend(leg_list,title='Disinhibition (Hz)',loc=1, bbox_to_anchor=[1.1, 1.1]) leg.draw_frame(False) for i in xrange(len(inh_list)): pl.plot([0],single_gating_nonoverlap_list[i],'D',markerfacecolor=colorMatrix1[2*i+1], markeredgecolor = 'none',markersize=4) if savenew: fig.save(self.figpath+'GatingCapacitySinglePathVaryInh'+self.version)
def plot_WeightChangevsrE(self): ''' Plot weight change when varying excitatory input rate ''' with open(self.datapath + 'resultlist_varyrate_postr10', 'rb') as f: result_list = pickle.load(f) with open(self.datapath + 'learning_para_2014-11-10_0', 'rb') as f: para = pickle.load(f) q = para.copy() # in vivo change (see Higgins, Graupner, Brunel 2014) #q['NMDA_scaling'] = q['NMDA_scaling']*1.5/2 #q['bAP_scaling'] = q['bAP_scaling']/5 vDend_mean_list = list() w_post_list = list() AlphaP_list = list() AlphaD_list = list() for result in result_list: p = result['params'] vDend = result['vDend'] NMDACasyn = result['NMDACasyn'] bAPCa = result['bAPCa'] vDend_mean = vDend.mean(axis=1) vDend_mean_list.append(vDend_mean) num_syn = NMDACasyn.shape[0] num_soma = bAPCa.shape[0] synsomaratio = num_syn // num_soma bAPCasyn = bAPCa.repeat(synsomaratio, axis=0) CaTrace = NMDACasyn * q['NMDA_scaling'] + bAPCasyn * q[ 'bAP_scaling'] w_post = zeros(num_syn) AlphaP_plot = zeros(num_syn) AlphaD_plot = zeros(num_syn) n_eachrate = num_syn // p['n_rate'] repeat_times = 5 record_dt = p['record_dt'] for i_syn in xrange(num_syn): CaTraceSorted = sort(CaTrace[i_syn]) AlphaP = MCM.crossthresholdtime( CaTraceSorted, q['thetaP']) * record_dt * repeat_times AlphaD = MCM.crossthresholdtime( CaTraceSorted, q['thetaD']) * record_dt * repeat_times wpre = 1 wpost_syn = MCM.SynapseChange(wpre, AlphaP, AlphaD, q) w_post[i_syn] = wpost_syn AlphaP_plot[i_syn] = AlphaP AlphaD_plot[i_syn] = AlphaD w_post = w_post.reshape(p['n_rate'], n_eachrate) w_post = w_post.mean(axis=1) w_post_list.append(w_post) AlphaP_list.append(AlphaP_plot) AlphaD_list.append(AlphaD_plot) dend_inh_rates = p['dend_inh_rates'] colorMatrix = array([[65, 182, 196], [34, 94, 168], [8, 29, 88]]) / 255 fig = MyFigure(figsize=(2.5, 2.5)) pl = fig.addplot(rect=[0.2, 0.25, 0.7, 0.7]) plotlist = list() i = 0 for vDend_mean in vDend_mean_list: ax, = pl.plot(p['pre_rates'], vDend_mean / mV, color=colorMatrix[i, :]) plotlist.append(ax) xlabel('Pre-synaptic rate (Hz)') ylabel('Mean Dendritic Voltage (mV)') i += 1 pl.ax.set_xticks([0, 20, 40]) pl.ax.set_ylim((-70, -10)) pl.ax.set_yticks([-70, -50, -30, -10]) leg = legend(plotlist, ['%d' % r for r in dend_inh_rates], title='Inhibition (Hz)', loc=2) leg.draw_frame(False) #fig.save('figures/RateVsInhibition'+self.version) fig = MyFigure(figsize=(2, 2)) pl = fig.addplot(rect=[0.2, 0.2, 0.7, 0.7]) pl.plot([0, max(p['pre_rates'])], [1, 1], color=array([189, 189, 189]) / 255) i = 0 plotlist = list() for w_post in w_post_list: ax, = pl.plot(p['pre_rates'], w_post, color=colorMatrix[i, :]) plotlist.append(ax) xlabel('Pre-synaptic rate (Hz)') ylabel('Weight change') i += 1 pl.ax.set_xticks([0, 20, 40]) pl.ax.set_ylim((0, 3)) pl.ax.set_yticks([0, 1, 2, 3]) leg = legend(plotlist, ['%d' % r for r in dend_inh_rates], title='Inhibition (Hz)', loc=2) leg.draw_frame(False) #title('post rate = %d Hz' % p['post_rate']) fig.save(self.figpath + 'WeightChangevsrE_postr%d' % p['post_rate'] + self.version)
def plot_WeightChangevsInitWeight(self): post_rate = 10 with open(self.datapath+'learning_para_2014-11-10_0','rb') as f: para = pickle.load(f) q = para.copy() with open(self.datapath+'WeightChangevsInitWeight_postr%d' % post_rate,'rb') as f: resultlist = pickle.load(f) # in vivo change (see Higgins, Graupner, Brunel 2014) q = self.invivo_learningparams(q) vDend_mean_list = list() fig=MyFigure(figsize=(4,3)) pl = fig.addplot(rect=[0.2,0.15,0.7,0.8]) pl.plot([q['w0'],q['w1']],[q['w0'],q['w1']],color='black',linestyle='--') i = 0 for result in resultlist: p = result['params'] vDend = result['vDend'] NMDACasyn = result['NMDACasyn'] bAPCa = result['bAPCa'] vDend_mean = vDend.mean(axis=1) vDend_mean = vDend_mean.reshape(p['n_weight'],p['n_rep']) vDend_mean = vDend_mean.mean(axis=1) vDend_mean_list.append(vDend_mean) num_syn = NMDACasyn.shape[0] num_soma = bAPCa.shape[0] synsomaratio = num_syn//num_soma bAPCasyn = bAPCa.repeat(synsomaratio,axis=0) CaTrace = NMDACasyn*q['NMDA_scaling'] + bAPCasyn*q['bAP_scaling'] w_post = np.zeros(num_syn) n_eachweight = num_syn//p['n_weight'] total_time = 3000 #s record_dt = p['record_dt'] for i_syn in xrange(num_syn): CaTraceSorted = np.sort(CaTrace[i_syn]) AlphaP = MCM.crossthresholdtime(CaTraceSorted,q['thetaP'])*record_dt*(total_time/p['runtime']) AlphaD = MCM.crossthresholdtime(CaTraceSorted,q['thetaD'])*record_dt*(total_time/p['runtime']) wpre = p['weights'][i_syn//n_eachweight] wpost_syn = MCM.SynapseChange(wpre,AlphaP,AlphaD,q) w_post[i_syn] = wpost_syn w_post = w_post.reshape(p['n_weight'],n_eachweight) w_post = w_post.mean(axis=1) ax, = pl.plot(p['weights'],w_post,color=colorMatrix[i*0,:],label='%d' % result['dend_inh_rate']) i += 1 plt.xlabel('Weight before learning') plt.ylabel('Weight after learning') pl.ax.set_plt.xlim((0,3)) pl.ax.set_xticks([0,1,2,3]) pl.ax.set_plt.ylim((0,3)) pl.ax.set_yticks([0,1,2,3]) leg=plt.legend(title='Inhibition (Hz)',loc=2) leg.draw_frame(False) axis('equal') #title('%d NMDA inputs of %d Hz' % (num_input,pre_rate)) fig.save(self.figpath+('WeightChangevsInitWeight_%d' % post_rate)+self.version)
def fit_experiment(self): global Nfeval experiment3B = 'NevianFig3B' with open(self.datapath + 'resultlist_' + experiment3B, 'rb') as f: result_list3B = pickle.load(f) experiment3D = 'NevianFig3D' with open(self.datapath + 'resultlist_' + experiment3D, 'rb') as f: result_list3D = pickle.load(f) experiment3D_full = 'NevianFig3D_full' with open(self.datapath + 'resultlist_' + experiment3D_full, 'rb') as f: result_list3D_full = pickle.load(f) experiment2 = 'NevianFig2' with open(self.datapath + 'resultlist_' + experiment2, 'rb') as f: result_list2 = pickle.load(f) experiment2_full = 'NevianFig2_full' with open(self.datapath + 'resultlist_' + experiment2_full, 'rb') as f: result_list2_full = pickle.load(f) x0 = list() bnds = list() # The following is the most up-to-date parameters fitting Nevian Fig.2 x0.append(0.371) # NMDA scaling parameter bnds.append([0.3, 3]) x0.append(0.957) # bAP scaling bnds.append([0.4, 1]) x0.append(39.949) # induced depression strength bnds.append([20, 500]) x0.append(177.552) # induced potentiation strength bnds.append([50, 500]) #x0.append(346.833) # synaptic learning time constant (s) #bnds.append([50,700]) x0.append( 2.78) # potentiation threshold (this parameter is very important) bnds.append([1.2, 3]) #x0.append(20) #bnds.append([12,100]) # Ca time constant (ms) #x0.append(0.647) #bnds.append([0.35,70]) # noise constant sigma start = time.clock() # Fit the model to some of the data but not all obj_func = lambda para: \ 0*self.get_model_sqe(para, result_list3B, experiment3B) + \ 1*self.get_model_sqe(para, result_list3D, experiment3D) + \ 1*self.get_model_sqe(para, result_list2, experiment2) Nfeval = 1 def callbackF(Xi): global Nfeval if Nfeval == 1: print 'N f NMDA bAP wpre w1 gP tau tau_Ca' print('%2d %0.3f ' % (Nfeval, obj_func(Xi)) + ' '.join('{:0.3f}'.format(k) for k in Xi)) Nfeval += 1 res = scipy.optimize.minimize(obj_func, x0, bounds=bnds, method='SLSQP', options={ 'maxiter': 300, 'disp': True }, callback=callbackF) x = res.x print('%2d %0.3f ' % (Nfeval, obj_func(x)) + ' '.join('{:0.3f}'.format(k) for k in x)) end = time.clock() print 'time spent %0.6f' % (end - start) sqe, change_list, wpost_list, para = self.get_model_sqe( x, result_list2, rich_return=True) fig = MyFigure(figsize=(2, 2)) pl = fig.addplot(rect=[0.2, 0.15, 0.7, 0.8]) self.plot_model_result(pl, para, result_list2_full, experiment2_full, plot_data=True) self.compareWithNevian_CaTrace(para, remakeFig=False, experiment='NevianFig5') fig = MyFigure(figsize=(1.5, 2)) pl = fig.addplot(rect=[0.2, 0.15, 0.7, 0.8]) self.plot_model_result(pl, para, result_list3B, experiment3B, plot_data=True) #compareWithNevian_CaTrace(para,remakeFig = False,experiment = experiment3B) fig = MyFigure(figsize=(1.5, 2)) pl = fig.addplot(rect=[0.2, 0.15, 0.7, 0.8]) self.plot_model_result(pl, para, result_list3D_full, experiment3D_full, plot_data=True)
def fit_experiment(self): global Nfeval experiment3B = 'NevianFig3B' with open(self.datapath+'resultlist_'+experiment3B,'rb') as f: result_list3B = pickle.load(f) experiment3D = 'NevianFig3D' with open(self.datapath+'resultlist_'+experiment3D,'rb') as f: result_list3D = pickle.load(f) experiment3D_full = 'NevianFig3D_full' with open(self.datapath+'resultlist_'+experiment3D_full,'rb') as f: result_list3D_full = pickle.load(f) experiment2 = 'NevianFig2' with open(self.datapath+'resultlist_'+experiment2,'rb') as f: result_list2 = pickle.load(f) experiment2_full = 'NevianFig2_full' with open(self.datapath+'resultlist_'+experiment2_full,'rb') as f: result_list2_full = pickle.load(f) x0 = list() bnds = list() # The following is the most up-to-date parameters fitting Nevian Fig.2 x0.append(0.371) # NMDA scaling parameter bnds.append([0.3,3]) x0.append(0.957) # bAP scaling bnds.append([0.4,1]) x0.append(39.949) # induced depression strength bnds.append([20,500]) x0.append(177.552) # induced potentiation strength bnds.append([50,500]) #x0.append(346.833) # synaptic learning time constant (s) #bnds.append([50,700]) x0.append(2.78) # potentiation threshold (this parameter is very important) bnds.append([1.2,3]) #x0.append(20) #bnds.append([12,100]) # Ca time constant (ms) #x0.append(0.647) #bnds.append([0.35,70]) # noise constant sigma start = time.clock() # Fit the model to some of the data but not all obj_func = lambda para: \ 0*self.get_model_sqe(para, result_list3B, experiment3B) + \ 1*self.get_model_sqe(para, result_list3D, experiment3D) + \ 1*self.get_model_sqe(para, result_list2, experiment2) Nfeval = 1 def callbackF(Xi): global Nfeval if Nfeval == 1: print 'N f NMDA bAP wpre w1 gP tau tau_Ca' print('%2d %0.3f ' % (Nfeval,obj_func(Xi))+' '.join('{:0.3f}'.format(k) for k in Xi)) Nfeval += 1 res = scipy.optimize.minimize(obj_func,x0,bounds=bnds,method='SLSQP', options={'maxiter':300, 'disp':True},callback=callbackF) x = res.x print('%2d %0.3f ' % (Nfeval,obj_func(x))+' '.join('{:0.3f}'.format(k) for k in x)) end = time.clock() print 'time spent %0.6f' % (end-start) sqe, change_list, wpost_list, para = self.get_model_sqe(x, result_list2, rich_return=True) fig=MyFigure(figsize=(2,2)) pl = fig.addplot(rect=[0.2,0.15,0.7,0.8]) self.plot_model_result(pl, para, result_list2_full, experiment2_full, plot_data=True) self.compareWithNevian_CaTrace(para,remakeFig = False,experiment = 'NevianFig5') fig=MyFigure(figsize=(1.5,2)) pl = fig.addplot(rect=[0.2,0.15,0.7,0.8]) self.plot_model_result(pl, para, result_list3B, experiment3B, plot_data=True) #compareWithNevian_CaTrace(para,remakeFig = False,experiment = experiment3B) fig=MyFigure(figsize=(1.5,2)) pl = fig.addplot(rect=[0.2,0.15,0.7,0.8]) self.plot_model_result(pl, para, result_list3D_full, experiment3D_full, plot_data=True)
def quick_runNewsome_psychometric(self, p, savenew=True, savename=''): datacolor3 = np.array([150, 150, 150]) / 255 modelcolor3 = np.array([37, 37, 37]) / 255 m_options = np.array([-0.5, -0.15, -0.05, 0.05, 0.15, 0.5]) c_options = np.array([-0.5, -0.18, -0.06, 0.06, 0.18, 0.5]) n_options = 6 mks = 5 n_plot = 51 coh_plot = np.linspace(-0.6, 0.6, n_plot) performance_plot_m = np.zeros((n_options, n_plot)) for i_c in xrange(n_options): for i_m in xrange(n_plot): c = c_options[i_c] m = coh_plot[i_m] performance = self.quick_Newsome_model(p, m, c) performance_plot_m[i_c, i_m] += performance * 100 fig = MyFigure(figsize=(4.5, 1.7)) pl = fig.addplot(rect=[0.1, 0.3, 0.24, 0.6]) pl.plot(m_options * 100, self.p_m_m * 100, 'o', color=datacolor3, markeredgecolor=datacolor3, label='Data', markersize=mks) pl.plot(coh_plot * 100, performance_plot_m.mean(axis=0), color=modelcolor3, label='Model') pylab.ylim([-5, 105]) pylab.yticks([0, 25, 50, 75, 100]) pylab.xticks([-50, -15, 15, 50], ['-50\n Left', '-15', '15', '50\n Right']) pylab.ylabel('Choices to right (%)') pylab.xlabel('Motion coherence') leg = pylab.legend(loc=2, numpoints=1, bbox_to_anchor=(-0.03, 1.15)) leg.draw_frame(False) m_options = c_options[:] performance_plot_c = np.zeros((n_options, n_plot)) for i_m in xrange(n_options): for i_c in xrange(n_plot): c = coh_plot[i_c] m = m_options[i_m] performance = self.quick_Newsome_model(p, m, c) performance_plot_c[i_m, i_c] += performance * 100 pl = fig.addplot(rect=[0.44, 0.3, 0.24, 0.6]) pl.plot(c_options * 100, self.p_m_c * 100, 'o', color=datacolor3, markeredgecolor=datacolor3, label='Data', markersize=mks) pl.plot(coh_plot * 100, performance_plot_c.mean(axis=0), color=modelcolor3, label='Model') pylab.ylim([-5, 105]) pylab.yticks([0, 25, 50, 75, 100], []) pylab.xticks([-50, -15, 15, 50], ['-50\n Red', '-15', '15', '50\n Green']) pylab.xlabel('Color coherence') pylab.ylabel('Choices to green (%)') #title('Motion Context') leg = pylab.legend(loc=2, numpoints=1, bbox_to_anchor=(-0.03, 1.15)) leg.draw_frame(False) pl = fig.addplot(rect=[0.73, 0.3, 0.24, 0.6]) for i_m in xrange(n_options // 2): pl.plot(coh_plot * 100, (performance_plot_c[i_m, :] + performance_plot_c[-1 - i_m, :]) / 2, color=motion_colors4[-i_m - 1]) pylab.ylim([-5, 105]) pylab.yticks([0, 25, 50, 75, 100], []) pylab.xticks([-50, -15, 15, 50], ['-50\n Red', '-15', '15', '50\n Green']) leg = pylab.legend(['Strong', 'Medium', 'Weak'], title='Motion coherence', loc=2, bbox_to_anchor=(-0.1, 1.2)) leg.draw_frame(False) pylab.xlabel('Color coherence') if savenew: fig.save(self.figpath + 'CompareWithNewsomePsychometric_' + savename + self.monkey + self.version) combined_panel = True if combined_panel: mks = 3 fig = MyFigure(figsize=(1.85, 1.5)) pl = fig.addplot(rect=[0.3, 0.25, 0.6, 0.55]) pl.plot(c_options * 100, self.p_m_c * 100, 'o', color=np.array([8, 29, 88]) / 255, markeredgecolor=np.array([8, 29, 88]) / 255, markersize=mks, label='Data - Color context') pl.plot(coh_plot * 100, performance_plot_c.mean(axis=0), color=np.array([8, 29, 88]) / 255) pl.plot(m_options * 100, self.p_m_m * 100, 'o', color=np.array([65, 182, 196]) / 255, markeredgecolor=np.array([65, 182, 196]) / 255, label='Data - Motion context', markersize=mks) pl.plot(coh_plot * 100, performance_plot_m.mean(axis=0), color=np.array([65, 182, 196]) / 255, label='Model') pylab.ylim([-5, 105]) pylab.yticks([0, 25, 50, 75, 100]) pylab.xticks([-50, -15, 15, 50], ['-50', '-15', '15', '50']) pylab.ylabel('Choices to right (%)') pylab.xlabel('Motion coherence to right') leg = pylab.legend(loc=2, numpoints=1, bbox_to_anchor=(-0.03, 1.35)) leg.draw_frame(False) fig.save(self.figpath + 'CompareWithNewsomePsychometric_combpanel_' + savename + self.monkey + self.version)
def plot_voltagedistribution(self, denseinh=False): ''' Plot voltage distribution ''' p = dict() p['num_DendEach'] = 1 p['dt'] = 0.2 * ms p['num_Soma'] = 40 p['pre_rate'] = 40 * Hz p['inh_base'] = 5 * Hz if denseinh: p['gGABA'] = p['gGABA'] / 10 p['inh_base'] = p['inh_base'] * 10 self.version = 'denseinh_' + self.version pre_rates = ones(p['num_Soma']) * p['pre_rate'] model = MCM.Model(paramsfile=self.paramsfile, eqsfile=self.eqsfile, outsidePara=p) model.make_model_dendrite_only(num_soma=p['num_Soma'], clamped_somavolt=-60 * mV, condition='invivo') model.make_dend_bkginh(inh_rates=p['inh_base']) model.single_pathway_gating_experiment(pre_rates, num_input=15, w_input=1) model.make_network() model.reinit() net = Network(model) net.run(2.5 * second, report='text') mon = model.monitor times = mon['MvDend'].times / ms plotstart = 500 dendv = mon['MvDend'].values[:, times > plotstart] / mV dendv = dendv[range(0, p['num_DendEach'] * p['num_Soma'], p['num_DendEach']), :] res = dict() res['params'] = p res['dendv'] = dendv with open(self.datapath + 'voltage_distribution_' + self.version, 'wb') as f: pickle.dump(res, f) fig = MyFigure(figsize=(1.5, 1.5)) pl = fig.addplot(rect=[0.05, 0.3, 0.9, 0.65]) #pl.ax.set_frame_on(False) pl.ax.spines['left'].set_visible(False) pl.ax.get_yaxis().set_visible(False) n, bins, patches = hist(dendv.flatten(), 50, normed=1, histtype='stepfilled') color_hist = array([99, 99, 99]) / 255 setp(patches, 'facecolor', color_hist, 'edgecolor', color_hist) xlim([-70, -10]) xticks([-60, -50, -40, -30, -20], ['-60', '', '-40', '', '-20']) xlabel('$V_D$ (mV)') fig.save(self.figpath + 'VoltageDistribution_' + self.version)
def plot_compare(self, p, savenew=True, savename=''): cohs = [0.05, 0.15, 0.5] x_plot = [-coh for coh in cohs[::-1]] + cohs x_plot = np.array(x_plot) p_frac1 = p.copy() p_frac1['frac_proj'] = 1 r_mc_list = np.zeros((6, 6)) for i_m in xrange(len(x_plot)): for i_c in xrange(len(x_plot)): m = x_plot[i_m] c = x_plot[i_c] #for a particular value of motion and color m,c \in (-1,1) #the input from the two pathways to the four considered populations are #(m,c) #(-m,c) #(m,-c) #(-m,-c) r_mc_list[i_m, i_c] = self.analytic_twopath(p_frac1, 40 * (1 + m), 40 * (1 + c)) input_plot_all = r_mc_list - r_mc_list[::-1, ::-1] win1_list = self.perform_func(input_plot_all) n_c = n_m = 6 Dim_motion = r_mc_list + r_mc_list[:, :: -1] - r_mc_list[:: -1, :] - r_mc_list[:: -1, :: -1] Dim_color = r_mc_list - r_mc_list[:, :: -1] + r_mc_list[:: -1, :] - r_mc_list[:: -1, :: -1] smalllinewidth = 1 largelinewidth = 2.5 Dim_motion = Dim_motion.mean(axis=1) fig = MyFigure(figsize=(4, 4)) pl = fig.addplot(rect=[0.2, 0.2, 0.7, 0.7]) for i_motion in xrange(n_m): if i_motion < (n_m / 2): facecolor = 'white' linewidth = smalllinewidth linecolor = motion_colors[i_motion] px = 1 else: linecolor = motion_colors[n_m - i_motion - 1] facecolor = motion_colors[n_m - i_motion - 1] linewidth = largelinewidth px = -1 pl.plot(px, Dim_motion[i_motion], 'o', markeredgecolor=linecolor, markerfacecolor=facecolor, linewidth=linewidth) Dim_color1 = Dim_color[:3, :].mean(axis=0) Dim_color2 = Dim_color[3:, :].mean(axis=0) print Dim_motion print Dim_color1 for i_color in xrange(n_c): if i_color < (n_c / 2): linecolor = color_colors[i_color] markerfacecolor = 'white' else: linecolor = color_colors[n_c - i_color - 1] markerfacecolor = linecolor pl.plot(0.5, Dim_color1[i_color], 'o', markeredgecolor=linecolor, markerfacecolor=markerfacecolor, linewidth=smalllinewidth) pl.plot(-0.5, Dim_color2[i_color], 'o', markeredgecolor=linecolor, markerfacecolor=markerfacecolor, linewidth=largelinewidth) pylab.xlabel('Dim Dec') pylab.ylabel('Dim Motion/Color') self.quick_runNewsome_psychometric(p, savenew=savenew, savename=savename)
def plot_state_space(self,p,savenew=True): ''' Plot the state-space plot for fitted model ''' n_list = 6 record_list = [np.array([])]*n_list name_list = ['r1','r2','input_mc','input_none','input_m','input_c'] for i_m in xrange(len(self.m_plot)): for i_c in xrange(len(self.c_plot)): m = self.m_plot[i_m] c = self.c_plot[i_c] result = self.run_Newsome_model(p,m,c, biphasic_input=False) for i_list in xrange(n_list): record_list[i_list] = np.concatenate((record_list[i_list],result[name_list[i_list]])) print 'm = %0.2f, c = %0.2f' % (m,c) # z-score results zscore_list = list() for i_list in xrange(n_list): zscore = record_list[i_list] temp = zscore[zscore>0.01] # exclude the data before and after dots #zscore -= np.mean(record_list[i_list]) zscore = zscore/np.std(temp) zscore_list.append(zscore) zs = zscore_list Dim_dec = -(zs[0]-zs[1])/2 Dim_motion = (zs[2]-zs[3]+zs[4]-zs[5])/4 Dim_color = (zs[2]-zs[3]-zs[4]+zs[5])/4 N_t = len(result['r1']) maxr = max([max(abs(Dim_dec)),max(abs(Dim_motion)),max(abs(Dim_color))]) smalllinewidth = 0.5 largelinewidth = 1 mks = 2 n_m = 6 n_c = 6 px = [0]*n_m py = [0]*n_m for i_cond in xrange(n_m*n_c): i_motion = i_cond//n_m px[i_motion] += Dim_dec[i_cond*N_t:(i_cond+1)*N_t]/n_c py[i_motion] += Dim_motion[i_cond*N_t:(i_cond+1)*N_t]/n_c dotoffcolor = np.array([84,39,143])/255. fig=MyFigure(figsize=(3,1.5)) pl = fig.addplot(rect=[0.01,0.05,0.45,0.9]) for i_motion in xrange(n_m): if i_motion<(n_m/2): mfc = 'white' linewidth = smalllinewidth linecolor = motion_colors[i_motion] mec = linecolor else: linecolor = motion_colors[n_m-i_motion-1] mfc = motion_colors[n_m-i_motion-1] linewidth = largelinewidth mec = mfc pl.plot([px[i_motion][-1]]*2,[py[i_motion][-1],0], 'o-',color=dotoffcolor, markerfacecolor=dotoffcolor,markeredgecolor=dotoffcolor,linewidth=linewidth,markersize=mks) pl.plot(px[i_motion],py[i_motion], 'o-',color=linecolor, markerfacecolor=mfc,markeredgecolor=mec,linewidth=linewidth,markersize=mks) #xlabel('Dim Dec') #ylabel('Dim Motion') pylab.xlim((-maxr,maxr)) pylab.ylim((-maxr,maxr)) pylab.axis('equal') pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) px_1 = [0]*n_c py_1 = [0]*n_c px_2 = [0]*n_c py_2 = [0]*n_c for i_cond in xrange(n_m*n_c): i_color = np.mod(i_cond,n_c) i_motion = i_cond//n_m if i_motion<(n_m/2): px_1[i_color] += Dim_dec[i_cond*N_t:(i_cond+1)*N_t]/n_c*2 py_1[i_color] += Dim_color[i_cond*N_t:(i_cond+1)*N_t]/n_c*2 else: px_2[i_color] += Dim_dec[i_cond*N_t:(i_cond+1)*N_t]/n_c*2 py_2[i_color] += Dim_color[i_cond*N_t:(i_cond+1)*N_t]/n_c*2 pl = fig.addplot(rect=[0.54,0.05,0.45,0.9]) for i_color in xrange(n_c): if i_color<(n_c/2): linecolor = color_colors[i_color] mfc = 'white' mec = linecolor else: linecolor = color_colors[n_c-i_color-1] mfc = linecolor mec = mfc pl.plot([px_1[i_color][-1]]*2,[py_1[i_color][-1],0],'o-', color=dotoffcolor,markerfacecolor=dotoffcolor,markeredgecolor=dotoffcolor,linewidth=smalllinewidth,markersize=mks) pl.plot([px_2[i_color][-1]]*2,[py_2[i_color][-1],0],'o-', color=dotoffcolor,markerfacecolor=dotoffcolor,markeredgecolor=dotoffcolor,linewidth=largelinewidth,markersize=mks) pl.plot(px_1[i_color],py_1[i_color],'o-', color=linecolor,markerfacecolor=mfc,markeredgecolor=mec,linewidth=smalllinewidth,markersize=mks) pl.plot(px_2[i_color],py_2[i_color],'o-', color=linecolor,markerfacecolor=mfc,markeredgecolor=mec,linewidth=largelinewidth,markersize=mks) #xlabel('Dim Dec') #ylabel('Dim Color') pylab.xlim((-maxr,maxr)) pylab.ylim((-maxr,maxr)) pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) if savenew: fig.save(self.figpath+'plot_Newsome_statespace'+'_'+self.monkey+self.version)
def fit_DendVvsgErI(self): ''' fit the dendritic voltage as a function of excitatory input and inhibitory rate ''' with open(self.datapath + 'DendVvsgErI' + self.version, 'rb') as f: result = pickle.load(f) x0 = [5, 10, 7, 1] bnds = ((1, 20), (1, 20), (1, 20), (0, 3)) params = copy.copy(self.params) for key in result['params']: params[key] = result['params'][key] # overwrite the old value temp = params['pre_rate'] * params['tauNMDARise'] * params[ 'tauNMDADecay'] * params['alphaNMDA'] print params['tauNMDARise'] * params['tauNMDADecay'] * params[ 'alphaNMDA'] # 0.06 is obtained from tau_rise = 2ms, tau_decay=100ms, alpha=0.3 /ms s_mean = temp / (1 + temp) # mean gating variable result['Exc'] = result['weights'] * params['gNMDA'] * 1e9 * params[ 'num_input'] * s_mean # unit-less weights * synaptic conductance 2.5nS * 15 synapses * mean gating variable for 30Hz result['Inh'] = result['dend_inh_rates'] * params['tauGABA'] * params[ 'gGABA'] * 1e9 # Total Rate * synaptic conductance * tau_GABA res = scipy.optimize.minimize( lambda p: self.obj_func_DendVvsgErI(p, result), x0, bounds=bnds, method='SLSQP', options={ 'maxiter': 100, 'disp': True }) print res.x p = res.x xdata = result['Exc'] n_curve = len(result['vdend_mean_list']) fig = MyFigure(figsize=(2, 1.5)) pl = fig.addplot(rect=[0.25, 0.25, 0.7, 0.7]) for i in xrange(n_curve): ydata = result['vdend_mean_list'][i] * 1000 ax_data, = pl.plot(xdata, ydata, color=np.array([55, 126, 184]) / 255) ymodel_list, sqe = self.obj_func_DendVvsgErI(p, result, rich_return=True) for i in xrange(n_curve): ax_model, = pl.plot(xdata, ymodel_list[i], color='black') pl.xlabel(r'$g_{E,\mathrm{tot}}$ (nS)', labelpad=3) pl.ylabel(r'$\overline{V}_D$ (mV)') pl.ax.set_xlim((0, 50)) pl.ax.set_xticks([0, 25, 50]) pl.ax.set_ylim((-70, -10)) pl.ax.set_yticks([-70, -20]) leg = pl.legend([ax_data, ax_model], ['Simulation', 'Fit'], loc=2, bbox_to_anchor=[0, 1.05]) leg.draw_frame(False) fig.save(self.figpath + 'DendVvsgErI' + self.version)
def plot_state_space(self, p, savenew=True): ''' Plot the state-space plot for fitted model ''' n_list = 6 record_list = [np.array([])] * n_list name_list = [ 'r1', 'r2', 'input_mc', 'input_none', 'input_m', 'input_c' ] for i_m in xrange(len(self.m_plot)): for i_c in xrange(len(self.c_plot)): m = self.m_plot[i_m] c = self.c_plot[i_c] result = self.run_Newsome_model(p, m, c, biphasic_input=False) for i_list in xrange(n_list): record_list[i_list] = np.concatenate( (record_list[i_list], result[name_list[i_list]])) print 'm = %0.2f, c = %0.2f' % (m, c) # z-score results zscore_list = list() for i_list in xrange(n_list): zscore = record_list[i_list] temp = zscore[zscore > 0.01] # exclude the data before and after dots #zscore -= np.mean(record_list[i_list]) zscore = zscore / np.std(temp) zscore_list.append(zscore) zs = zscore_list Dim_dec = -(zs[0] - zs[1]) / 2 Dim_motion = (zs[2] - zs[3] + zs[4] - zs[5]) / 4 Dim_color = (zs[2] - zs[3] - zs[4] + zs[5]) / 4 N_t = len(result['r1']) maxr = max( [max(abs(Dim_dec)), max(abs(Dim_motion)), max(abs(Dim_color))]) smalllinewidth = 0.5 largelinewidth = 1 mks = 2 n_m = 6 n_c = 6 px = [0] * n_m py = [0] * n_m for i_cond in xrange(n_m * n_c): i_motion = i_cond // n_m px[i_motion] += Dim_dec[i_cond * N_t:(i_cond + 1) * N_t] / n_c py[i_motion] += Dim_motion[i_cond * N_t:(i_cond + 1) * N_t] / n_c dotoffcolor = np.array([84, 39, 143]) / 255. fig = MyFigure(figsize=(3, 1.5)) pl = fig.addplot(rect=[0.01, 0.05, 0.45, 0.9]) for i_motion in xrange(n_m): if i_motion < (n_m / 2): mfc = 'white' linewidth = smalllinewidth linecolor = motion_colors[i_motion] mec = linecolor else: linecolor = motion_colors[n_m - i_motion - 1] mfc = motion_colors[n_m - i_motion - 1] linewidth = largelinewidth mec = mfc pl.plot([px[i_motion][-1]] * 2, [py[i_motion][-1], 0], 'o-', color=dotoffcolor, markerfacecolor=dotoffcolor, markeredgecolor=dotoffcolor, linewidth=linewidth, markersize=mks) pl.plot(px[i_motion], py[i_motion], 'o-', color=linecolor, markerfacecolor=mfc, markeredgecolor=mec, linewidth=linewidth, markersize=mks) #xlabel('Dim Dec') #ylabel('Dim Motion') pylab.xlim((-maxr, maxr)) pylab.ylim((-maxr, maxr)) pylab.axis('equal') pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) px_1 = [0] * n_c py_1 = [0] * n_c px_2 = [0] * n_c py_2 = [0] * n_c for i_cond in xrange(n_m * n_c): i_color = np.mod(i_cond, n_c) i_motion = i_cond // n_m if i_motion < (n_m / 2): px_1[i_color] += Dim_dec[i_cond * N_t:(i_cond + 1) * N_t] / n_c * 2 py_1[i_color] += Dim_color[i_cond * N_t:(i_cond + 1) * N_t] / n_c * 2 else: px_2[i_color] += Dim_dec[i_cond * N_t:(i_cond + 1) * N_t] / n_c * 2 py_2[i_color] += Dim_color[i_cond * N_t:(i_cond + 1) * N_t] / n_c * 2 pl = fig.addplot(rect=[0.54, 0.05, 0.45, 0.9]) for i_color in xrange(n_c): if i_color < (n_c / 2): linecolor = color_colors[i_color] mfc = 'white' mec = linecolor else: linecolor = color_colors[n_c - i_color - 1] mfc = linecolor mec = mfc pl.plot([px_1[i_color][-1]] * 2, [py_1[i_color][-1], 0], 'o-', color=dotoffcolor, markerfacecolor=dotoffcolor, markeredgecolor=dotoffcolor, linewidth=smalllinewidth, markersize=mks) pl.plot([px_2[i_color][-1]] * 2, [py_2[i_color][-1], 0], 'o-', color=dotoffcolor, markerfacecolor=dotoffcolor, markeredgecolor=dotoffcolor, linewidth=largelinewidth, markersize=mks) pl.plot(px_1[i_color], py_1[i_color], 'o-', color=linecolor, markerfacecolor=mfc, markeredgecolor=mec, linewidth=smalllinewidth, markersize=mks) pl.plot(px_2[i_color], py_2[i_color], 'o-', color=linecolor, markerfacecolor=mfc, markeredgecolor=mec, linewidth=largelinewidth, markersize=mks) #xlabel('Dim Dec') #ylabel('Dim Color') pylab.xlim((-maxr, maxr)) pylab.ylim((-maxr, maxr)) pl.ax.set_frame_on(False) pl.ax.set_yticks([]) pl.ax.set_xticks([]) if savenew: fig.save(self.figpath + 'plot_Newsome_statespace' + '_' + self.monkey + self.version)
def plot_WeightChangevsrE(self): ''' Plot weight change when varying excitatory input rate ''' with open(self.datapath+'resultlist_varyrate_postr10','rb') as f: result_list = pickle.load(f) with open(self.datapath+'learning_para_2014-11-10_0','rb') as f: para = pickle.load(f) q = para.copy() # in vivo change (see Higgins, Graupner, Brunel 2014) #q['NMDA_scaling'] = q['NMDA_scaling']*1.5/2 #q['bAP_scaling'] = q['bAP_scaling']/5 vDend_mean_list = list() w_post_list = list() AlphaP_list = list() AlphaD_list = list() for result in result_list: p = result['params'] vDend = result['vDend'] NMDACasyn = result['NMDACasyn'] bAPCa = result['bAPCa'] vDend_mean = vDend.mean(axis=1) vDend_mean_list.append(vDend_mean) num_syn = NMDACasyn.shape[0] num_soma = bAPCa.shape[0] synsomaratio = num_syn//num_soma bAPCasyn = bAPCa.repeat(synsomaratio,axis=0) CaTrace = NMDACasyn*q['NMDA_scaling'] + bAPCasyn*q['bAP_scaling'] w_post = zeros(num_syn) AlphaP_plot = zeros(num_syn) AlphaD_plot = zeros(num_syn) n_eachrate = num_syn//p['n_rate'] repeat_times = 5 record_dt = p['record_dt'] for i_syn in xrange(num_syn): CaTraceSorted = sort(CaTrace[i_syn]) AlphaP = MCM.crossthresholdtime(CaTraceSorted,q['thetaP'])*record_dt*repeat_times AlphaD = MCM.crossthresholdtime(CaTraceSorted,q['thetaD'])*record_dt*repeat_times wpre = 1 wpost_syn = MCM.SynapseChange(wpre,AlphaP,AlphaD,q) w_post[i_syn] = wpost_syn AlphaP_plot[i_syn] = AlphaP AlphaD_plot[i_syn] = AlphaD w_post = w_post.reshape(p['n_rate'],n_eachrate) w_post = w_post.mean(axis=1) w_post_list.append(w_post) AlphaP_list.append(AlphaP_plot) AlphaD_list.append(AlphaD_plot) dend_inh_rates = p['dend_inh_rates'] colorMatrix = array([[65,182,196], [34,94,168], [8,29,88]])/255 fig=MyFigure(figsize=(2.5,2.5)) pl = fig.addplot(rect=[0.2,0.25,0.7,0.7]) plotlist = list() i = 0 for vDend_mean in vDend_mean_list: ax, = pl.plot(p['pre_rates'],vDend_mean/mV,color=colorMatrix[i,:]) plotlist.append(ax) xlabel('Pre-synaptic rate (Hz)') ylabel('Mean Dendritic Voltage (mV)') i += 1 pl.ax.set_xticks([0,20,40]) pl.ax.set_ylim((-70,-10)) pl.ax.set_yticks([-70,-50,-30,-10]) leg=legend(plotlist,['%d' % r for r in dend_inh_rates],title='Inhibition (Hz)',loc=2) leg.draw_frame(False) #fig.save('figures/RateVsInhibition'+self.version) fig=MyFigure(figsize=(2,2)) pl = fig.addplot(rect=[0.2,0.2,0.7,0.7]) pl.plot([0,max(p['pre_rates'])],[1,1],color=array([189,189,189])/255) i = 0 plotlist = list() for w_post in w_post_list: ax, = pl.plot(p['pre_rates'],w_post,color=colorMatrix[i,:]) plotlist.append(ax) xlabel('Pre-synaptic rate (Hz)') ylabel('Weight change') i += 1 pl.ax.set_xticks([0,20,40]) pl.ax.set_ylim((0,3)) pl.ax.set_yticks([0,1,2,3]) leg=legend(plotlist,['%d' % r for r in dend_inh_rates],title='Inhibition (Hz)',loc=2) leg.draw_frame(False) #title('post rate = %d Hz' % p['post_rate']) fig.save(self.figpath+'WeightChangevsrE_postr%d' % p['post_rate']+self.version)
def plot_EvsDI(self, name='NMDA', denseinh=False, bothinh=True, rate_range=60): ''' plot mean dendritic voltage as a function of excitatory input rate, and inhibitory rate ''' if denseinh: di = 'denseinh_' k = 10 else: di = '' k = 1 name_append = di + name + ('_range%d' % rate_range) + self.version with open( self.datapath + 'EvsDI_' + di + name + ('_range%d' % rate_range) + '_latest.pkl', 'rb') as f: res = pickle.load(f) if rate_range > 100: figsize = (1.5, 1.3) ylim = (-70, 0) yticks = [-70, -10] rect = [0.25, 0.3, 0.65, 0.65] else: figsize = (1.3, 1.3) ylim = (-70, -10) yticks = [-70, -20] rect = [0.3, 0.3, 0.65, 0.65] fig = MyFigure(figsize=figsize) pl = fig.addplot(rect=rect) pl.plot(res['pre_rates'], res['vDend_mean'][0], color=colorMatrix[1], label='0') print res['vDend_mean'][0] if bothinh: pl.plot(res['pre_rates'], res['vDend_mean'][30], color=colorMatrix[5], label='30') #leg=legend(title='Inhibition (Hz)',loc=2, bbox_to_anchor=[-0.05, 1.05],frameon=False) pl.ax.set_ylim(ylim) pl.ax.set_yticks(yticks) xticks = [0, int(rate_range / 2), rate_range] pl.ax.set_xticks(xticks) #xlabel('Rate of %d ' % p['num_inputeach']+name+' inputs (Hz)' ) xlabel('Rate (Hz)') if name is 'NMDA': ylabel('$\overline{V}_D$ (mV)', labelpad=-5) else: pl.ax.set_yticklabels(['', '']) if bothinh: fig.save(self.figpath + 'EvsDI_' + name_append) else: fig.save(self.figpath + 'EvsDI_preinh_' + name_append) if name is 'NMDA': inh_list = res['vDend_mean'].keys() inh_list = sort(inh_list) fig = MyFigure(figsize=(2.2, 1.6)) pl = fig.addplot(rect=[0.25, 0.25, 0.7, 0.7]) for i in xrange(len(inh_list)): color = colorMatrix[i + 1, :] pl.plot(res['pre_rates'], res['vDend_mean'][inh_list[i]], color=color, label='%d' % (inh_list[i] * k)) leg = legend(title='Inhibition (Hz)', loc=2, bbox_to_anchor=[0.02, 1.05], frameon=False) pl.ax.set_ylim((-70, -10)) pl.ax.set_yticks([-70, -20]) pl.ax.set_xticks(xticks) #xlabel('Rate of %d ' % p['num_inputeach']+name+' inputs (Hz)' ) xlabel('Excitatory input rate (Hz)') ylabel('Mean dendritic voltage (mV)', labelpad=5) fig.save(self.figpath + 'EvsDI_full_' + name_append)
def plot_compare(self,p,savenew=True,savename=''): cohs = [0.05,0.15,0.5] x_plot = [-coh for coh in cohs[::-1]]+cohs x_plot = np.array(x_plot) p_frac1 = p.copy() p_frac1['frac_proj'] = 1 r_mc_list = np.zeros((6,6)) for i_m in xrange(len(x_plot)): for i_c in xrange(len(x_plot)): m = x_plot[i_m] c = x_plot[i_c] #for a particular value of motion and color m,c \in (-1,1) #the input from the two pathways to the four considered populations are #(m,c) #(-m,c) #(m,-c) #(-m,-c) r_mc_list[i_m,i_c] = self.analytic_twopath(p_frac1,40*(1+m),40*(1+c)) input_plot_all = r_mc_list - r_mc_list[::-1,::-1] win1_list = self.perform_func(input_plot_all) n_c = n_m = 6 Dim_motion = r_mc_list + r_mc_list[:,::-1] - r_mc_list[::-1,:] - r_mc_list[::-1,::-1] Dim_color = r_mc_list - r_mc_list[:,::-1] + r_mc_list[::-1,:] - r_mc_list[::-1,::-1] smalllinewidth = 1 largelinewidth = 2.5 Dim_motion = Dim_motion.mean(axis=1) fig=MyFigure(figsize=(4,4)) pl = fig.addplot(rect=[0.2,0.2,0.7,0.7]) for i_motion in xrange(n_m): if i_motion<(n_m/2): facecolor = 'white' linewidth = smalllinewidth linecolor = motion_colors[i_motion] px = 1 else: linecolor = motion_colors[n_m-i_motion-1] facecolor = motion_colors[n_m-i_motion-1] linewidth = largelinewidth px = -1 pl.plot(px,Dim_motion[i_motion], 'o',markeredgecolor=linecolor, markerfacecolor=facecolor,linewidth=linewidth) Dim_color1 = Dim_color[:3,:].mean(axis=0) Dim_color2 = Dim_color[3:,:].mean(axis=0) print Dim_motion print Dim_color1 for i_color in xrange(n_c): if i_color<(n_c/2): linecolor = color_colors[i_color] markerfacecolor = 'white' else: linecolor = color_colors[n_c-i_color-1] markerfacecolor = linecolor pl.plot(0.5,Dim_color1[i_color],'o', markeredgecolor=linecolor,markerfacecolor=markerfacecolor,linewidth=smalllinewidth) pl.plot(-0.5,Dim_color2[i_color],'o', markeredgecolor=linecolor,markerfacecolor=markerfacecolor,linewidth=largelinewidth) pylab.xlabel('Dim Dec') pylab.ylabel('Dim Motion/Color') self.quick_runNewsome_psychometric(p,savenew=savenew,savename=savename)