def run_isi_simulation(): N = 150 network_params = default_params trial_duration = 2 * second var = 10 x1 = 50 x2 = 100 isi_times = range(25, 750, 25) stim_dur = 100 * ms adaptation = np.zeros(len(isi_times)) for i, isi in enumerate(isi_times): print('Testing isi=%dms' % isi) stim1_start_time = 1 * second stim1_end_time = stim1_start_time + stim_dur stim2_start_time = stim1_end_time + isi * ms stim2_end_time = stim2_start_time + stim_dur same_pop_monitor, same_voxel_monitor = run_pop_code( ProbabilisticPopulationCode, N, network_params, [x1, x1], [var, var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) diff_pop_monitor, diff_voxel_monitor = run_pop_code( ProbabilisticPopulationCode, N, network_params, [x1, x2], [var, var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) same_y_max = np.max(same_voxel_monitor['y'][0]) diff_y_max = np.max(diff_voxel_monitor['y'][0]) adaptation[i] = (diff_y_max - same_y_max) / diff_y_max * 100.0 data_dir = '../../data/adaptation/isi' fig = plt.figure() plt.plot(isi_times, adaptation) plt.xlabel('ISI (ms)') plt.ylabel('Adaptation') fname = 'adaptation.isi.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig)
def run_isi_simulation(): N=150 network_params=default_params trial_duration=2*second var=10 x1=50 x2=100 isi_times=range(25,750,25) stim_dur=100*ms adaptation=np.zeros(len(isi_times)) for i,isi in enumerate(isi_times): print('Testing isi=%dms' % isi) stim1_start_time=1*second stim1_end_time=stim1_start_time+stim_dur stim2_start_time=stim1_end_time+isi*ms stim2_end_time=stim2_start_time+stim_dur same_pop_monitor,same_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x1], [var,var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration) diff_pop_monitor,diff_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x2], [var,var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration) same_y_max=np.max(same_voxel_monitor['y'][0]) diff_y_max=np.max(diff_voxel_monitor['y'][0]) adaptation[i]=(diff_y_max-same_y_max)/diff_y_max*100.0 data_dir='../../data/adaptation/isi' fig=plt.figure() plt.plot(isi_times,adaptation) plt.xlabel('ISI (ms)') plt.ylabel('Adaptation') fname='adaptation.isi.%s' save_to_png(fig, os.path.join(data_dir,fname % 'png')) save_to_eps(fig, os.path.join(data_dir,fname % 'eps')) plt.close(fig)
def demo(N, network_params, trial_duration, x1, x2, low_var, high_var, isi, stim_dur): stim1_start_time=1*second stim1_end_time=stim1_start_time+stim_dur stim2_start_time=stim1_end_time+isi stim2_end_time=stim2_start_time+stim_dur low_var_prob_pop_monitor,low_var_prob_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x2],[low_var,low_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration) high_var_prob_pop_monitor,high_var_prob_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x2],[high_var,high_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time], trial_duration) low_var_samp_pop_monitor,low_var_samp_voxel_monitor=run_pop_code(SamplingPopulationCode, N, network_params, [x1,x2], [low_var,low_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration) high_var_samp_pop_monitor,high_var_samp_voxel_monitor=run_pop_code(SamplingPopulationCode, N, network_params, [x1,x2], [high_var,high_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration) data_dir='../../data/adaptation/demo' fig=plt.figure() plt.subplot(411) plt.title('Probabilistic population, low variance - rate') plt.imshow(low_var_prob_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,.2) plt.subplot(412) plt.title('Probabilistic population, high variance - rate') plt.imshow(high_var_prob_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,.2) plt.subplot(413) plt.title('Sampling population, low variance - rate') plt.imshow(low_var_samp_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,.2) plt.subplot(414) plt.title('Sampling population, high variance - rate') plt.imshow(high_var_samp_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,.2) fname='firing_rate.%s' save_to_png(fig, os.path.join(data_dir,fname % 'png')) save_to_eps(fig, os.path.join(data_dir,fname % 'eps')) plt.close(fig) fig=plt.figure() plt.subplot(411) plt.title('Probabilistic population, low variance - efficacy') plt.imshow(low_var_prob_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) plt.subplot(412) plt.title('Probabilistic population, high variance - efficacy') plt.imshow(high_var_prob_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) plt.subplot(413) plt.title('Sampling population, low variance - efficacy') plt.imshow(low_var_samp_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) plt.subplot(414) plt.title('Sampling population, high variance - efficacy') plt.imshow(high_var_samp_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) fname='efficacy.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) fig=plt.figure() plt.title('BOLD') plt.plot(low_var_prob_voxel_monitor['y'][0],label='prob,low var') plt.plot(high_var_prob_voxel_monitor['y'][0],label='prob,high var') plt.plot(low_var_samp_voxel_monitor['y'][0],label='samp,low var') plt.plot(high_var_samp_voxel_monitor['y'][0],label='samp,high var') plt.legend(loc='best') fname='bold.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) stim1_mid_time=stim1_start_time+(stim1_end_time-stim1_start_time)/2 idx1=int(stim1_mid_time/defaultclock.dt) stim2_mid_time=stim2_start_time+(stim2_end_time-stim2_start_time)/2 idx2=int(stim2_mid_time/defaultclock.dt) fig=plt.figure() plt.title('Probabilistic Population snapshot') plt.plot(low_var_prob_pop_monitor['r'][:,idx1],'r', label='low var, stim 1') plt.plot(low_var_prob_pop_monitor['r'][:,idx2],'r--', label='low var stim 2') plt.plot(high_var_prob_pop_monitor['r'][:,idx1],'b', label='high var, stim 1') plt.plot(high_var_prob_pop_monitor['r'][:,idx2],'b--', label='high var stim 2') plt.legend(loc='best') fname='prob_pop.firing_rate.snapshot.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) fig=plt.figure() plt.title('Sampling Population snapshot') plt.plot(low_var_samp_pop_monitor['r'][:,idx1],'r', label='low var, stim 1') plt.plot(low_var_samp_pop_monitor['r'][:,idx2],'r--', label='low var, stim 2') plt.plot(high_var_samp_pop_monitor['r'][:,idx1],'b', label='high var, stim 1') plt.plot(high_var_samp_pop_monitor['r'][:,idx2],'b--', label='high var, stim 2') plt.legend(loc='best') fname='samp_pop.firing_rate.snapshot.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig)
def test_simulation(design): N=150 network_params=default_params sim_params=rapid_design_params network_params.tau_ar=100*ms if design=='long': network_params.tau_a=5*second sim_params=long_design_params var=10 x1=50 x2=100 stim1_start_time=1*second stim1_end_time=stim1_start_time+sim_params.stim_dur stim2_start_time=stim1_end_time+sim_params.isi stim2_end_time=stim2_start_time+sim_params.stim_dur same_pop_monitor,same_voxel_monitor,same_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, [Stimulus(x1,var,stim1_start_time,stim1_end_time), Stimulus(x1,var,stim2_start_time,stim2_end_time)], sim_params.trial_duration) diff_pop_monitor,diff_voxel_monitor,diff_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, [Stimulus(x1,var,stim1_start_time,stim1_end_time), Stimulus(x2,var,stim2_start_time,stim2_end_time)], sim_params.trial_duration) # single_pop_monitor,single_voxel_monitor,single_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, # [Stimulus(x1,var,stim1_start_time,stim1_end_time)], # sim_params.trial_duration) data_dir='../../data/adaptation/adaptation_test' fig=plt.figure() #plt.subplot(311) plt.subplot(211) plt.title('Same') plt.imshow(same_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() #plt.subplot(312) plt.subplot(212) plt.title('Different') plt.imshow(diff_pop_monitor['r'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() # plt.subplot(313) # plt.title('Single') # plt.imshow(single_pop_monitor['r'][:],aspect='auto') # plt.xlabel('time') # plt.ylabel('neuron') # plt.colorbar() fname='%s.firing_rate' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) fig=plt.figure() #plt.subplot(311) plt.subplot(211) plt.title('Same') plt.imshow(same_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) #plt.subplot(312) plt.subplot(212) plt.title('Different') plt.imshow(diff_pop_monitor['e'][:],aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0,1) # plt.subplot(313) # plt.title('Single') # plt.imshow(single_pop_monitor['e'][:],aspect='auto') # plt.xlabel('time') # plt.ylabel('neuron') # plt.colorbar() # plt.clim(0,1) fname='%s.efficacy' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) fig=plt.figure() plt.title('BOLD') plt.plot(same_voxel_monitor['y'][0],label='same') plt.plot(diff_voxel_monitor['y'][0],label='different') #plt.plot(single_voxel_monitor['y'][0],label='single') plt.legend(loc='best') fname='%s.bold' % design save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) # fig=plt.figure() # plt.plot(same_pop_monitor['total_e'][0],label='same') # plt.plot(diff_pop_monitor['total_e'][0],label='different') # #plt.plot(single_pop_monitor['total_e'][0],label='single') # plt.legend(loc='best') # fname='%s.total_e' % design # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) # # fig=plt.figure() # plt.plot(same_pop_monitor['total_r'][0],label='same') # plt.plot(diff_pop_monitor['total_r'][0],label='different') # #plt.plot(single_pop_monitor['total_r'][0],label='single') # plt.legend(loc='best') # fname='%s.total_r' % design # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) fig=plt.figure() plt.plot(same_voxel_monitor['G_total'][0][0:20000],label='same') plt.plot(diff_voxel_monitor['G_total'][0][0:20000],label='different') #plt.plot(single_voxel_monitor['G_total'][0][0:100000],label='single') plt.legend(loc='best') fname='%s.g_total' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig)
def adaptation_simulation(design, baseline, pop_class, N, network_params, sim_params, stim1_mean, stim2_mean, stim1_var, stim2_var, data_dir, edesc): # Compute stimulus start and end times stim1_start_time=1*second stim1_end_time=stim1_start_time+sim_params.stim_dur stim2_start_time=stim1_end_time+sim_params.isi stim2_end_time=stim2_start_time+sim_params.stim_dur pop_monitor,voxel_monitor,y_max=run_pop_code(pop_class, N, network_params, [Stimulus(stim1_mean, stim1_var, stim1_start_time, stim1_end_time), Stimulus(stim2_mean, stim2_var, stim2_start_time, stim2_end_time)], sim_params.trial_duration) if baseline=='repeated': baseline_pop_monitor,baseline_voxel_monitor,baseline_y_max=run_pop_code(pop_class, N, network_params, [Stimulus(stim1_mean,stim1_var,stim1_start_time,stim1_end_time), Stimulus(stim1_mean,stim1_var,stim2_start_time,stim2_end_time)], sim_params.trial_duration) adaptation=(y_max-baseline_y_max)/baseline_y_max elif baseline=='single': baseline_pop_monitor,baseline_voxel_monitor,baseline_y_max=run_pop_code(pop_class, N, network_params, [Stimulus(stim2_mean, stim2_var, stim1_start_time, stim1_end_time)], rapid_design_params.trial_duration) adaptation=(y_max-baseline_y_max)/baseline_y_max fig=plt.figure() plt.plot(voxel_monitor['y'][0], 'b', label='test') plt.plot(baseline_voxel_monitor['y'][0], 'r', label='baseline') plt.legend(loc='best') fname='%s.baseline-%s.%s.%s.bold' % (design,baseline,edesc,pop_class.__name__) save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) fig=plt.figure() plt.subplot(211) plt.title('test') plt.imshow(pop_monitor['e'][:],aspect='auto') plt.clim(0,1) plt.colorbar() plt.subplot(212) plt.title('baseline') plt.imshow(baseline_pop_monitor['e'][:],aspect='auto') plt.clim(0,1) plt.colorbar() fname='%s.baseline-%s.%s.%s.e' % (design,baseline,edesc,pop_class.__name__) save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) # fig=plt.figure() # plt.plot(pop_monitor['total_e'][0],'b',label='test') # plt.plot(baseline_pop_monitor['total_e'][0],'r',label='baseline') # plt.legend(loc='best') # fname='%s.baseline-%s.%s.%s.total_e' % (design,baseline,edesc,pop_class.__name__) # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) # # fig=plt.figure() # plt.plot(pop_monitor['total_r'][0],'b',label='test') # plt.plot(baseline_pop_monitor['total_r'][0],'r',label='baseline') # plt.legend(loc='best') # fname='%s.baseline-%s.%s.%s.total_r' % (design,baseline,edesc,pop_class.__name__) # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) fig=plt.figure() plt.plot(voxel_monitor['G_total'][0][0:100000],'b',label='test') plt.plot(baseline_voxel_monitor['G_total'][0][0:100000],'r',label='baseline') plt.legend(loc='best') fname='%s.baseline-%s.%s.%s.g_total' % (design,baseline,edesc,pop_class.__name__) save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig) return adaptation
def run_repeated_test(): N=150 # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design network_params=default_params sim_params=rapid_design_params # Compute stimulus start and end times stim1_start_time=1*second stim1_end_time=stim1_start_time+sim_params.stim_dur stim2_start_time=stim1_end_time+sim_params.isi stim2_end_time=stim2_start_time+sim_params.stim_dur x_delta_iter=5 # If baseline is single stimulus - need to test x_delta=0 x_delta_range=np.array(range(0,int(N/3),x_delta_iter)) # High and low variance examples low_var=5 x=int(N/3) prob_combined_y_max=np.zeros(len(x_delta_range)) prob_repeated_y_max=np.zeros(len(x_delta_range)) samp_combined_y_max=np.zeros(len(x_delta_range)) samp_repeated_y_max=np.zeros(len(x_delta_range)) for i,x_delta in enumerate(x_delta_range): print('x_delta=%d' % x_delta) pop_monitor,voxel_monitor,prob_repeated_y_max[i]=run_pop_code(ProbabilisticPopulationCode, N, network_params, [Stimulus(x,low_var,stim1_start_time,stim1_end_time), Stimulus(x+x_delta,low_var,stim2_start_time,stim2_end_time)], sim_params.trial_duration) pop_monitor,voxel_monitor,prob_first_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, [Stimulus(x, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) pop_monitor,voxel_monitor,prob_second_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, [Stimulus(x+x_delta, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) prob_combined_y_max[i]=prob_first_y_max+prob_second_y_max pop_monitor,voxel_monitor,samp_repeated_y_max[i]=run_pop_code(SamplingPopulationCode, N, network_params, [Stimulus(x,low_var,stim1_start_time,stim1_end_time), Stimulus(x+x_delta,low_var,stim2_start_time,stim2_end_time)], sim_params.trial_duration) pop_monitor,voxel_monitor,samp_first_y_max=run_pop_code(SamplingPopulationCode, N, network_params, [Stimulus(x, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) pop_monitor,voxel_monitor,samp_second_y_max=run_pop_code(SamplingPopulationCode, N, network_params, [Stimulus(x+x_delta, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) samp_combined_y_max[i]=samp_first_y_max+samp_second_y_max data_dir='../../data/adaptation/repeated_test/' fig=plt.figure() plt.plot(x_delta_range,prob_combined_y_max-prob_repeated_y_max,'r',label='prob') plt.plot(x_delta_range,samp_combined_y_max-samp_repeated_y_max,'b',label='samp') plt.legend(loc='best') fname='repeated_test' save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) plt.close(fig)
def demo(N, network_params, trial_duration, x1, x2, low_var, high_var, isi, stim_dur): stim1_start_time = 1 * second stim1_end_time = stim1_start_time + stim_dur stim2_start_time = stim1_end_time + isi stim2_end_time = stim2_start_time + stim_dur low_var_prob_pop_monitor, low_var_prob_voxel_monitor = run_pop_code( ProbabilisticPopulationCode, N, network_params, [x1, x2], [low_var, low_var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) high_var_prob_pop_monitor, high_var_prob_voxel_monitor = run_pop_code( ProbabilisticPopulationCode, N, network_params, [x1, x2], [high_var, high_var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) low_var_samp_pop_monitor, low_var_samp_voxel_monitor = run_pop_code( SamplingPopulationCode, N, network_params, [x1, x2], [low_var, low_var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) high_var_samp_pop_monitor, high_var_samp_voxel_monitor = run_pop_code( SamplingPopulationCode, N, network_params, [x1, x2], [high_var, high_var], [stim1_start_time, stim2_start_time], [stim1_end_time, stim2_end_time], trial_duration) data_dir = '../../data/adaptation/demo' fig = plt.figure() plt.subplot(411) plt.title('Probabilistic population, low variance - rate') plt.imshow(low_var_prob_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, .2) plt.subplot(412) plt.title('Probabilistic population, high variance - rate') plt.imshow(high_var_prob_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, .2) plt.subplot(413) plt.title('Sampling population, low variance - rate') plt.imshow(low_var_samp_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, .2) plt.subplot(414) plt.title('Sampling population, high variance - rate') plt.imshow(high_var_samp_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, .2) fname = 'firing_rate.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) fig = plt.figure() plt.subplot(411) plt.title('Probabilistic population, low variance - efficacy') plt.imshow(low_var_prob_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) plt.subplot(412) plt.title('Probabilistic population, high variance - efficacy') plt.imshow(high_var_prob_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) plt.subplot(413) plt.title('Sampling population, low variance - efficacy') plt.imshow(low_var_samp_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) plt.subplot(414) plt.title('Sampling population, high variance - efficacy') plt.imshow(high_var_samp_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) fname = 'efficacy.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) fig = plt.figure() plt.title('BOLD') plt.plot(low_var_prob_voxel_monitor['y'][0], label='prob,low var') plt.plot(high_var_prob_voxel_monitor['y'][0], label='prob,high var') plt.plot(low_var_samp_voxel_monitor['y'][0], label='samp,low var') plt.plot(high_var_samp_voxel_monitor['y'][0], label='samp,high var') plt.legend(loc='best') fname = 'bold.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) stim1_mid_time = stim1_start_time + (stim1_end_time - stim1_start_time) / 2 idx1 = int(stim1_mid_time / defaultclock.dt) stim2_mid_time = stim2_start_time + (stim2_end_time - stim2_start_time) / 2 idx2 = int(stim2_mid_time / defaultclock.dt) fig = plt.figure() plt.title('Probabilistic Population snapshot') plt.plot(low_var_prob_pop_monitor['r'][:, idx1], 'r', label='low var, stim 1') plt.plot(low_var_prob_pop_monitor['r'][:, idx2], 'r--', label='low var stim 2') plt.plot(high_var_prob_pop_monitor['r'][:, idx1], 'b', label='high var, stim 1') plt.plot(high_var_prob_pop_monitor['r'][:, idx2], 'b--', label='high var stim 2') plt.legend(loc='best') fname = 'prob_pop.firing_rate.snapshot.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig) fig = plt.figure() plt.title('Sampling Population snapshot') plt.plot(low_var_samp_pop_monitor['r'][:, idx1], 'r', label='low var, stim 1') plt.plot(low_var_samp_pop_monitor['r'][:, idx2], 'r--', label='low var, stim 2') plt.plot(high_var_samp_pop_monitor['r'][:, idx1], 'b', label='high var, stim 1') plt.plot(high_var_samp_pop_monitor['r'][:, idx2], 'b--', label='high var, stim 2') plt.legend(loc='best') fname = 'samp_pop.firing_rate.snapshot.%s' save_to_png(fig, os.path.join(data_dir, fname % 'png')) save_to_eps(fig, os.path.join(data_dir, fname % 'eps')) plt.close(fig)
def test_simulation(design): N = 150 network_params = default_params sim_params = rapid_design_params network_params.tau_ar = 100 * ms if design == 'long': network_params.tau_a = 5 * second sim_params = long_design_params var = 10 x1 = 50 x2 = 100 stim1_start_time = 1 * second stim1_end_time = stim1_start_time + sim_params.stim_dur stim2_start_time = stim1_end_time + sim_params.isi stim2_end_time = stim2_start_time + sim_params.stim_dur same_pop_monitor, same_voxel_monitor, same_y_max = run_pop_code( ProbabilisticPopulationCode, N, network_params, [ Stimulus(x1, var, stim1_start_time, stim1_end_time), Stimulus(x1, var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) diff_pop_monitor, diff_voxel_monitor, diff_y_max = run_pop_code( ProbabilisticPopulationCode, N, network_params, [ Stimulus(x1, var, stim1_start_time, stim1_end_time), Stimulus(x2, var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) # single_pop_monitor,single_voxel_monitor,single_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params, # [Stimulus(x1,var,stim1_start_time,stim1_end_time)], # sim_params.trial_duration) data_dir = '../../data/adaptation/adaptation_test' fig = plt.figure() #plt.subplot(311) plt.subplot(211) plt.title('Same') plt.imshow(same_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() #plt.subplot(312) plt.subplot(212) plt.title('Different') plt.imshow(diff_pop_monitor['r'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() # plt.subplot(313) # plt.title('Single') # plt.imshow(single_pop_monitor['r'][:],aspect='auto') # plt.xlabel('time') # plt.ylabel('neuron') # plt.colorbar() fname = '%s.firing_rate' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) fig = plt.figure() #plt.subplot(311) plt.subplot(211) plt.title('Same') plt.imshow(same_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) #plt.subplot(312) plt.subplot(212) plt.title('Different') plt.imshow(diff_pop_monitor['e'][:], aspect='auto') plt.xlabel('time') plt.ylabel('neuron') plt.colorbar() plt.clim(0, 1) # plt.subplot(313) # plt.title('Single') # plt.imshow(single_pop_monitor['e'][:],aspect='auto') # plt.xlabel('time') # plt.ylabel('neuron') # plt.colorbar() # plt.clim(0,1) fname = '%s.efficacy' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) fig = plt.figure() plt.title('BOLD') plt.plot(same_voxel_monitor['y'][0], label='same') plt.plot(diff_voxel_monitor['y'][0], label='different') #plt.plot(single_voxel_monitor['y'][0],label='single') plt.legend(loc='best') fname = '%s.bold' % design save_to_png(fig, os.path.join(data_dir, '%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) # fig=plt.figure() # plt.plot(same_pop_monitor['total_e'][0],label='same') # plt.plot(diff_pop_monitor['total_e'][0],label='different') # #plt.plot(single_pop_monitor['total_e'][0],label='single') # plt.legend(loc='best') # fname='%s.total_e' % design # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) # # fig=plt.figure() # plt.plot(same_pop_monitor['total_r'][0],label='same') # plt.plot(diff_pop_monitor['total_r'][0],label='different') # #plt.plot(single_pop_monitor['total_r'][0],label='single') # plt.legend(loc='best') # fname='%s.total_r' % design # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) fig = plt.figure() plt.plot(same_voxel_monitor['G_total'][0][0:20000], label='same') plt.plot(diff_voxel_monitor['G_total'][0][0:20000], label='different') #plt.plot(single_voxel_monitor['G_total'][0][0:100000],label='single') plt.legend(loc='best') fname = '%s.g_total' % design #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig)
def adaptation_simulation(design, baseline, pop_class, N, network_params, sim_params, stim1_mean, stim2_mean, stim1_var, stim2_var, data_dir, edesc): # Compute stimulus start and end times stim1_start_time = 1 * second stim1_end_time = stim1_start_time + sim_params.stim_dur stim2_start_time = stim1_end_time + sim_params.isi stim2_end_time = stim2_start_time + sim_params.stim_dur pop_monitor, voxel_monitor, y_max = run_pop_code( pop_class, N, network_params, [ Stimulus(stim1_mean, stim1_var, stim1_start_time, stim1_end_time), Stimulus(stim2_mean, stim2_var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) if baseline == 'repeated': baseline_pop_monitor, baseline_voxel_monitor, baseline_y_max = run_pop_code( pop_class, N, network_params, [ Stimulus(stim1_mean, stim1_var, stim1_start_time, stim1_end_time), Stimulus(stim1_mean, stim1_var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) adaptation = (y_max - baseline_y_max) / baseline_y_max elif baseline == 'single': baseline_pop_monitor, baseline_voxel_monitor, baseline_y_max = run_pop_code( pop_class, N, network_params, [ Stimulus(stim2_mean, stim2_var, stim1_start_time, stim1_end_time) ], rapid_design_params.trial_duration) adaptation = (y_max - baseline_y_max) / baseline_y_max fig = plt.figure() plt.plot(voxel_monitor['y'][0], 'b', label='test') plt.plot(baseline_voxel_monitor['y'][0], 'r', label='baseline') plt.legend(loc='best') fname = '%s.baseline-%s.%s.%s.bold' % (design, baseline, edesc, pop_class.__name__) save_to_png(fig, os.path.join(data_dir, '%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) fig = plt.figure() plt.subplot(211) plt.title('test') plt.imshow(pop_monitor['e'][:], aspect='auto') plt.clim(0, 1) plt.colorbar() plt.subplot(212) plt.title('baseline') plt.imshow(baseline_pop_monitor['e'][:], aspect='auto') plt.clim(0, 1) plt.colorbar() fname = '%s.baseline-%s.%s.%s.e' % (design, baseline, edesc, pop_class.__name__) save_to_png(fig, os.path.join(data_dir, '%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) # fig=plt.figure() # plt.plot(pop_monitor['total_e'][0],'b',label='test') # plt.plot(baseline_pop_monitor['total_e'][0],'r',label='baseline') # plt.legend(loc='best') # fname='%s.baseline-%s.%s.%s.total_e' % (design,baseline,edesc,pop_class.__name__) # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) # # fig=plt.figure() # plt.plot(pop_monitor['total_r'][0],'b',label='test') # plt.plot(baseline_pop_monitor['total_r'][0],'r',label='baseline') # plt.legend(loc='best') # fname='%s.baseline-%s.%s.%s.total_r' % (design,baseline,edesc,pop_class.__name__) # save_to_png(fig, os.path.join(data_dir,'%s.png' % fname)) # save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname)) # plt.close(fig) fig = plt.figure() plt.plot(voxel_monitor['G_total'][0][0:100000], 'b', label='test') plt.plot(baseline_voxel_monitor['G_total'][0][0:100000], 'r', label='baseline') plt.legend(loc='best') fname = '%s.baseline-%s.%s.%s.g_total' % (design, baseline, edesc, pop_class.__name__) save_to_png(fig, os.path.join(data_dir, '%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig) return adaptation
def run_repeated_test(): N = 150 # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design network_params = default_params sim_params = rapid_design_params # Compute stimulus start and end times stim1_start_time = 1 * second stim1_end_time = stim1_start_time + sim_params.stim_dur stim2_start_time = stim1_end_time + sim_params.isi stim2_end_time = stim2_start_time + sim_params.stim_dur x_delta_iter = 5 # If baseline is single stimulus - need to test x_delta=0 x_delta_range = np.array(range(0, int(N / 3), x_delta_iter)) # High and low variance examples low_var = 5 x = int(N / 3) prob_combined_y_max = np.zeros(len(x_delta_range)) prob_repeated_y_max = np.zeros(len(x_delta_range)) samp_combined_y_max = np.zeros(len(x_delta_range)) samp_repeated_y_max = np.zeros(len(x_delta_range)) for i, x_delta in enumerate(x_delta_range): print('x_delta=%d' % x_delta) pop_monitor, voxel_monitor, prob_repeated_y_max[i] = run_pop_code( ProbabilisticPopulationCode, N, network_params, [ Stimulus(x, low_var, stim1_start_time, stim1_end_time), Stimulus(x + x_delta, low_var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) pop_monitor, voxel_monitor, prob_first_y_max = run_pop_code( ProbabilisticPopulationCode, N, network_params, [Stimulus(x, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) pop_monitor, voxel_monitor, prob_second_y_max = run_pop_code( ProbabilisticPopulationCode, N, network_params, [Stimulus(x + x_delta, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) prob_combined_y_max[i] = prob_first_y_max + prob_second_y_max pop_monitor, voxel_monitor, samp_repeated_y_max[i] = run_pop_code( SamplingPopulationCode, N, network_params, [ Stimulus(x, low_var, stim1_start_time, stim1_end_time), Stimulus(x + x_delta, low_var, stim2_start_time, stim2_end_time) ], sim_params.trial_duration) pop_monitor, voxel_monitor, samp_first_y_max = run_pop_code( SamplingPopulationCode, N, network_params, [Stimulus(x, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) pop_monitor, voxel_monitor, samp_second_y_max = run_pop_code( SamplingPopulationCode, N, network_params, [Stimulus(x + x_delta, low_var, stim1_start_time, stim1_end_time)], sim_params.trial_duration) samp_combined_y_max[i] = samp_first_y_max + samp_second_y_max data_dir = '../../data/adaptation/repeated_test/' fig = plt.figure() plt.plot(x_delta_range, prob_combined_y_max - prob_repeated_y_max, 'r', label='prob') plt.plot(x_delta_range, samp_combined_y_max - samp_repeated_y_max, 'b', label='samp') plt.legend(loc='best') fname = 'repeated_test' save_to_png(fig, os.path.join(data_dir, '%s.png' % fname)) save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname)) plt.close(fig)