Changeset 340 for trunk/examples/retina/benchmark_retina.py
- Timestamp:
- 11/14/08 19:17:05 (4 years ago)
- Files:
-
- 1 modified
-
trunk/examples/retina/benchmark_retina.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/retina/benchmark_retina.py
r333 r340 25 25 import os, sys, numpy, pylab, shelve, progressbar 26 26 27 N, N_snr, N_seeds = 1000, 5, 10 28 from NeuroTools.parameters import * 29 p = ParameterSpace({ 30 'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 31 'kernelseed' : ParameterRange(list([12345 + k for k in range(N_seeds)]))}) 27 32 28 33 name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part 29 ############## MAKING THE SIMULATIONS ############### 30 results = shelve.open('results/mat-' + name) 34 31 35 try: 32 DATA = results['DATA'] 33 except: 36 ############## MAKING THE SIMULATIONS ############### 37 results = shelve.open('results/mat-' + name) 38 try: 39 DATA = results['DATA'] 40 params = results['params'] 41 except: 42 from retina import * 43 retina = Retina(N) 44 # calculates the dimension of the parameter space 45 results_dim, results_label = p.parameter_space_dimension_labels() 34 46 35 from NeuroTools.parameters import * 47 DATA = [] 48 pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 49 progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 50 for i_exp, experiment in enumerate(p.iter_inner()): 51 params = retina.params 52 params.update(experiment) # updates what changed in the dictionary 53 # simulate the experiment and get its data 54 data = retina.run(params)#,verbose=False) 55 # store it 56 DATA.append(data)# 57 pbar.update(i_exp) 36 58 37 N, N_snr, N_seeds = 1000, 5, 10 38 from retina import * 39 retina = Retina(N) 59 results['DATA'] = DATA 60 results['params'] = retina.params 40 61 41 t_smooth = 100. # ms. integration time to show fiber activity 42 43 p = ParameterSpace({ 44 'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 45 'kernelseed' : ParameterRange(list([retina.params['kernelseed'] + k for k in range(N_seeds)]))}) 46 47 # calculates the dimension of the parameter space 48 results_dim, results_label = p.parameter_space_dimension_labels() 49 50 DATA = [] 51 52 pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 53 progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 54 for i_exp, experiment in enumerate(p.iter_inner()): 55 params = retina.params 56 params.update(experiment) # updates what changed in the dictionary 57 # simulate the experiment and get its data 58 data = retina.run(params)#,verbose=False) 59 # store it 60 DATA.append(data)# 61 pbar.update(i_exp) 62 63 results['DATA'] = DATA 64 65 pbar.finish() 66 67 ############## PRE-PROCESSING ########################### 68 try: 62 pbar.finish() 63 results.close() 64 results = shelve.open('results/mat-pre-' + name) 65 ############## PRE-PROCESSING ########################### 69 66 #boing # uncomment to force recomputing the pre-processing stage 70 67 lower_edges = results['lower_edges'] … … 73 70 temporal_OFF = results['temporal_OFF'] 74 71 map_spatial_ON = results['map_spatial_ON'] 72 lower_edges = results['lower_edges'] 73 results.close() 75 74 76 75 except: 77 76 def temporal_mean(spike_list): 77 return numpy.sum(spike_list.firing_rate(t_smooth),axis=0) 78 79 t_smooth = 100. # ms. integration time to show fiber activity 78 80 lower_edges = DATA[0]['out_ON_DATA'].time_axis(t_smooth) 79 N_smooth = len(lower_edges) 80 params = retina.params 81 N_smooth = len(lower_edges)-1 81 82 82 83 #N_snr = len(p.snr) … … 86 87 # 87 88 N_ret, simtime = params['N_ret'], params['simtime'] 88 #89 89 x = params['position'][0] 90 90 y = params['position'][1] … … 92 92 r = numpy.sqrt(r2) 93 93 id_center = [int(k) for k in numpy.where( r2 < N_ret**2)[0]] 94 95 94 # mean activity accross kernelseeds as a function of SNR 96 95 for i_exp, experiment in enumerate(p.iter_inner()): … … 98 97 index = p.parameter_space_index(experiment) 99 98 # getting SpikeLists corresponding to the interesting parts (within the center) 100 temporal_ON[:,index[1]] += sum(DATA[i_exp]['out_ON_DATA'][id_center].firing_rate(t_smooth))/N_seeds101 temporal_OFF[:,index[1]] += sum(DATA[i_exp]['out_OFF_DATA'][id_center].firing_rate(t_smooth))/N_seeds102 map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.) /N_seeds103 map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.) /N_seeds99 temporal_ON[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 100 temporal_OFF[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 101 map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 102 map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 104 103 104 results = shelve.open('results/mat-pre-' + name) 105 105 results['temporal_ON'] = temporal_ON 106 106 results['map_spatial_OFF'] = map_spatial_OFF 107 107 results['temporal_OFF'] = temporal_OFF 108 108 results['map_spatial_ON'] = map_spatial_ON 109 results['lower_edges'] = lower_edges 110 results.close() 109 111 110 112 results.close() … … 133 135 #pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 134 136 pylab.subplot(131) 135 pylab.scatter(x,y,c=params['amplitude'], faceted=False)137 pylab.scatter(x,y,c=params['amplitude'], edgecolors='none') 136 138 137 139 pylab.subplot(232) 138 pylab.plot(lower_edges ,temporal_ON)140 pylab.plot(lower_edges[:-1],temporal_ON) 139 141 pylab.title('time course (ROI) ',fontsize = 'small') 140 142 #pylab.title('time course ON',fontsize = 'small') 141 pylab.xticks( numpy.linspace(0, simtime, 5) )143 pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 142 144 pylab.ylabel('ON activity (spike / s / neuron)') 143 145 #pylab.axis('tight') 144 146 pylab.subplot(235) 145 pylab.plot(lower_edges ,temporal_OFF)147 pylab.plot(lower_edges[:-1],temporal_OFF) 146 148 #pylab.title('time course OFF',fontsize = 'small') 147 pylab.xticks( numpy.linspace(0, simtime, 5) )149 pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 148 150 pylab.ylabel('OFF activity (spike / s / neuron)') 149 151 #pylab.axis('tight') 150 152 pylab.xlabel('time (ms)') 151 153 pylab.subplot(233) 152 pylab.scatter(x, y, c= map_spatial_ON[:,-1], faceted=False)154 pylab.scatter(x, y, c= map_spatial_ON[:,-1], edgecolors='none') 153 155 #pylab.title('spatial distribution ON',fontsize ='small') 154 156 #pylab.title('spatial distribution',fontsize ='small') 155 157 pylab.subplot(236) 156 pylab.scatter(x, y, c= map_spatial_OFF[:,-1], faceted=False)158 pylab.scatter(x, y, c= map_spatial_OFF[:,-1], edgecolors='none') 157 159 #pylab.title('spatial distribution OFF',fontsize ='small') 158 160 #pylab.xlabel('distance from center') … … 161 163 162 164 163 pylab.savefig('results/fig-' + name + '.pdf') 164 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 165 if 1: 166 pylab.ion() 167 pylab.show() 168 else: 169 pylab.savefig('results/fig-' + name + '.pdf') 170 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 171 172
